jquery
7 years ago
admin.js
7 years ago
pmxe.js
7 years ago
scheduling.js
7 years ago
validate-braces.js
7 years ago
scheduling.js
157 lines
| 1 | (function ($) { |
| 2 | $(function () { |
| 3 | $(document).ready(function () { |
| 4 | |
| 5 | window.pmxeISchedulingFormValid = function () { |
| 6 | |
| 7 | var schedulingEnabled = $('#scheduling_enable').is(':checked'); |
| 8 | |
| 9 | if (!schedulingEnabled) { |
| 10 | return { |
| 11 | isValid: true |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | var runOn = $('input[name="scheduling_run_on"]:checked').val(); |
| 16 | |
| 17 | // Validate weekdays |
| 18 | if (runOn == 'weekly') { |
| 19 | var weeklyDays = $('#weekly_days').val(); |
| 20 | |
| 21 | if (weeklyDays == '') { |
| 22 | return { |
| 23 | isValid: false, |
| 24 | message: 'Please select at least a day on which the export should run' |
| 25 | } |
| 26 | } |
| 27 | } else if (runOn == 'monthly') { |
| 28 | var monthlyDays = $('#monthly_days').val(); |
| 29 | |
| 30 | if (monthlyDays == '') { |
| 31 | return { |
| 32 | isValid: false, |
| 33 | message: 'Please select at least a day on which the export should run' |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // Validate times |
| 39 | var timeValid = false; |
| 40 | var timeInputs = $('.timepicker'); |
| 41 | |
| 42 | timeInputs.each(function () { |
| 43 | if ($(this).val() != '') { |
| 44 | timeValid = true; |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | if (!timeValid) { |
| 49 | return { |
| 50 | isValid: false, |
| 51 | message: 'Please select at least a time' |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | return { |
| 56 | isValid: true |
| 57 | }; |
| 58 | }; |
| 59 | |
| 60 | $('#weekly li').click(function () { |
| 61 | if ($(this).hasClass('selected')) { |
| 62 | $(this).removeClass('selected'); |
| 63 | } else { |
| 64 | $(this).addClass('selected'); |
| 65 | } |
| 66 | |
| 67 | $('#weekly_days').val(''); |
| 68 | |
| 69 | $('#weekly li.selected').each(function () { |
| 70 | var val = $(this).data('day'); |
| 71 | $('#weekly_days').val($('#weekly_days').val() + val + ','); |
| 72 | }); |
| 73 | |
| 74 | $('#weekly_days').val($('#weekly_days').val().slice(0, -1)); |
| 75 | |
| 76 | }); |
| 77 | |
| 78 | $('#monthly li').click(function () { |
| 79 | $(this).parent().parent().find('.days-of-week li').removeClass('selected'); |
| 80 | $(this).addClass('selected'); |
| 81 | }); |
| 82 | |
| 83 | $('input[name="scheduling_run_on"]').change(function () { |
| 84 | var val = $('input[name="scheduling_run_on"]:checked').val(); |
| 85 | if (val == "weekly") { |
| 86 | |
| 87 | $('#weekly').slideDown(); |
| 88 | $('#monthly').slideUp(); |
| 89 | |
| 90 | } else if (val == "monthly") { |
| 91 | |
| 92 | $('#weekly').slideUp(); |
| 93 | $('#monthly').slideDown(); |
| 94 | |
| 95 | } |
| 96 | }); |
| 97 | |
| 98 | $('.timepicker').timepicker(); |
| 99 | |
| 100 | var selectedTimes = []; |
| 101 | |
| 102 | var onTimeSelected = function () { |
| 103 | |
| 104 | selectedTimes.push([$(this).val(), $(this).val() + 1]); |
| 105 | |
| 106 | var isLastChild = $(this).is(':last-child'); |
| 107 | if (isLastChild) { |
| 108 | $(this).parent().append('<input class="timepicker" name="scheduling_times[]" style="display: none;" type="text" />'); |
| 109 | $('.timepicker:last-child').timepicker({ |
| 110 | 'disableTimeRanges': selectedTimes |
| 111 | }); |
| 112 | $('.timepicker:last-child').fadeIn('fast'); |
| 113 | $('.timepicker').on('changeTime', onTimeSelected); |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | $('.timepicker').on('changeTime', onTimeSelected); |
| 118 | |
| 119 | $('#timezone').chosen({width: '329px'}); |
| 120 | |
| 121 | $(document).on('wpae-scheduling-form:submitted', function(e){ |
| 122 | // Do this to cancel the form submit |
| 123 | // e.preventDefault(); |
| 124 | |
| 125 | $(this).find('.easing-spinner').toggle(); |
| 126 | $(this).find('.save-text').html('Saving...'); |
| 127 | |
| 128 | var $button = $(this); |
| 129 | |
| 130 | var schedulingEnable = $('#scheduling_enable').is(':checked'); |
| 131 | |
| 132 | var formData = $('#scheduling-form :input').serializeArray(); |
| 133 | |
| 134 | formData.push({name: 'security', value: wp_all_export_security}); |
| 135 | formData.push({name: 'action', value: 'save_scheduling'}); |
| 136 | formData.push({name: 'scheduling_enable', value: schedulingEnable}); |
| 137 | |
| 138 | $.ajax({ |
| 139 | type: 'POST', |
| 140 | url: ajaxurl, |
| 141 | data: formData, |
| 142 | success: function (response) { |
| 143 | $button.find('.easing-spinner').toggle(); |
| 144 | $button.find('.save-text').html('Save'); |
| 145 | $button.find('svg').show(); |
| 146 | $button.find('svg').fadeOut(5000); |
| 147 | }, |
| 148 | error: function () { |
| 149 | $button.find('.easing-spinner').toggle(); |
| 150 | $button.find('.save-text').html('Save'); |
| 151 | } |
| 152 | }); |
| 153 | }); |
| 154 | |
| 155 | }); |
| 156 | }); |
| 157 | })(jQuery); |