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