PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / static / js / scheduling.js
wp-all-export / static / js Last commit date
jquery 4 weeks ago admin.js 4 weeks ago pmxe.js 3 years ago scheduling.js 4 weeks ago upgrade-notice.js 4 years ago validate-braces.js 8 years ago
scheduling.js
965 lines
1 /**
2 * plugin javascript
3 */
4 (function($){$(function () {
5
6 if ( ! $('body.wpallexport-plugin').length) return; // do not execute any code if we are not on plugin page
7
8 var hasActiveLicense = false;
9
10 // Main accordion logic
11 $(document).on('change', 'input[name="scheduling_enable"]', function () {
12 var schedulingEnable = $('input[name="scheduling_enable"]:checked').val();
13 if (schedulingEnable == 1) {
14 $('#automatic-scheduling').slideDown();
15 $('.manual-scheduling').slideUp();
16 setTimeout(function () {
17 $('.timezone-select').slideDown(275);
18 }, 200);
19 }
20 else if (schedulingEnable == 2) {
21 $('.timezone-select').slideUp(275);
22 $('#automatic-scheduling').slideUp();
23 $('.manual-scheduling').slideDown();
24 } else {
25 $('.timezone-select').hide();
26 $('#automatic-scheduling').slideUp();
27 $('.manual-scheduling').slideUp();
28 }
29 if(!window.pmxeHasSchedulingSubscription && parseInt(schedulingEnable) == 1) {
30 $('.save-changes').addClass('disabled');
31 } else {
32 $('.save-changes').removeClass('disabled');
33 }
34 });
35
36 window.handleHelpSchedulingClick = function() {
37 $('input[name="scheduling_enable"][value="1"]').prop('checked', true).trigger('change');
38 }
39
40 function fetchExportSchedulingConnectionIcon() {
41 $.ajax({
42 type: "POST",
43 url: ajaxurl,
44 data: {
45 action: 'wpae_get_scheduling_connection_icon',
46 security: wp_all_export_security
47 },
48 dataType: "json",
49 success: function (response) {
50 let schedulingIcon = $('#scheduling-connection-icon');
51 if (response.data.html) {
52 schedulingIcon.html(response.data.html);
53 } else {
54 $('.unable-to-connect').html('Refresh page to see the current Scheduling connection status.');
55 }
56 },
57 error: function (xhr, status, error) {
58 $('.unable-to-connect').html('Refresh page to see the current Scheduling connection status.');
59 }
60 });
61 }
62
63 function openSchedulingAccordeonIfClosed() {
64 if ($('.wpallexport-file-options').hasClass('closed')) {
65 // Open accordion
66 $('#scheduling-title').trigger('click');
67 }
68 }
69
70 $(document).on('click', '.scheduling-subscribe-link', function () {
71 openSchedulingSubscribeDialog(this)
72 });
73
74 window.openSchedulingSubscribeDialog = function(element) {
75 // Display overlay and loader initially
76 $('.wpallexport-overlay').show();
77 $('.wpallexport-loader').show();
78
79 var $self = $(element);
80
81 $.ajax({
82 type: "POST",
83 url: ajaxurl,
84 context: element,
85 data: {
86 action: 'scheduling_subscribe_dialog_content',
87 security: wp_all_export_security
88 },
89 success: function (data) {
90 $('.wpallexport-loader').hide();
91 $(this).pointer({
92 content: '<div id="scheduling-popup">' + data + '</div>',
93 position: {
94 edge: 'right',
95 align: 'center'
96 },
97 pointerWidth: 815,
98 show: function () {
99 var $leftOffset = ($(window).width() - 715) / 2;
100 var $topOffset = $(document).scrollTop() + 100;
101
102 var $pointer = $('.wp-pointer').last();
103 $pointer.css({'position': 'absolute', 'top': $topOffset + 'px', 'left': $leftOffset + 'px'});
104
105 $pointer.find('a.close').remove();
106 $pointer.find('.wp-pointer-buttons').append('<button class="close-pointer button wpallimport-large-button scheduling-cancel-button" style="float: right; background: #F1F1F1; text-shadow: 0 0 black; color: #777; margin-right: 10px;">Close</button>');
107
108 $("#subscribe").unbind('click').on('click', function (event) {
109 schedulingSubscribeHandler(event)
110 $(".close-pointer").trigger('click');
111 });
112
113 // Close scheduling dialog
114 $(".close-pointer, .wpallexport-overlay").unbind('click').on('click', function () {
115 $self.pointer('close');
116 if ($self.pointer) {
117 $self.pointer('close');
118 $self.pointer('destroy');
119 }
120 })
121
122 $('#scheduling-subscribe-group').css('border', 'none').css('margin', 'auto');
123 },
124 close: function () {
125 // Hide overlay on closing pointer dialog
126 $('.wpallexport-overlay').hide();
127 }
128 }).pointer('open');
129 },
130 error: function () {
131 alert('There was an issue retrieving the scheduling subscribe content.');
132 $('.wpallexport-loader').hide();
133 $('.wpallexport-overlay').hide();
134 }
135 });
136 };
137
138 window.openSchedulingDialog = function(itemId, element, preloaderSrc) {
139 $('.wpallexport-overlay').show();
140 $('.wpallexport-loader').show();
141
142 var $self = element;
143 $.ajax({
144 type: "POST",
145 url: ajaxurl,
146 context: element,
147 data: {
148 'action': 'scheduling_dialog_content',
149 'id': itemId,
150 'security' : wp_all_export_security
151 },
152 success: function (data) {
153 $('.wpallexport-loader').hide();
154 $(this).pointer({
155 content: '<div id="scheduling-popup">' + data + '</div>',
156 position: {
157 edge: 'right',
158 align: 'center'
159 },
160 pointerWidth: 815,
161 show: function (event, t) {
162
163 $('.timepicker').timepicker();
164
165 var $leftOffset = ($(window).width() - 715) / 2;
166 var $topOffset = $(document).scrollTop() + 100;
167
168 var $pointer = $('.wp-pointer').last();
169 $pointer.css({'position': 'absolute', 'top': $topOffset + 'px', 'left': $leftOffset + 'px'});
170
171 $pointer.find('a.close').remove();
172 $pointer.find('.wp-pointer-buttons').append('<button class="save-changes button wpallexport-large-button" style="float: right; background-image: none;">Save</button>');
173 $pointer.find('.wp-pointer-buttons').append('<button class="close-pointer button wpallexport-large-button" style="float: right; background: #F1F1F1 none;text-shadow: 0 0 black; color: #777; margin-right: 10px;">Cancel</button>');
174
175 $(".close-pointer, .wpallexport-overlay").unbind('click').on('click', function () {
176 $self.pointer('close');
177 $self.pointer('destroy');
178 });
179
180 if(!window.pmxeHasSchedulingSubscription) {
181 $('.save-changes ').addClass('disabled');
182 }
183
184 // help icons
185 $('.wpallexport-help').tipsy({
186 gravity: function() {
187 var ver = 'n';
188 if ($(document).scrollTop() < $(this).offset().top - $('.tipsy').height() - 2) {
189 ver = 's';
190 }
191 var hor = '';
192 if ($(this).offset().left + $('.tipsy').width() < $(window).width() + $(document).scrollLeft()) {
193 hor = 'w';
194 } else if ($(this).offset().left - $('.tipsy').width() > $(document).scrollLeft()) {
195 hor = 'e';
196 }
197 return ver + hor;
198 },
199 html: true,
200 opacity: 1
201 }).on('click', function () {
202 return false;
203 }).each(function () { // fix tipsy title for IE
204 $(this).attr('original-title', $(this).attr('title'));
205 $(this).removeAttr('title');
206 });
207
208
209 $(".save-changes").off('click').on('click', function () {
210 if($(this).hasClass('disabled')) {
211 return false;
212 }
213
214 var formValid = pmxeValidateSchedulingForm();
215
216 if (formValid.isValid) {
217
218 var schedulingEnable = $('input[name="scheduling_enable"]:checked').val();
219
220 var formData = $('#scheduling-form').serializeArray();
221 formData.push({name: 'security', value: wp_all_export_security});
222 formData.push({name: 'action', value: 'save_scheduling'});
223 formData.push({name: 'element_id', value: itemId});
224 formData.push({name: 'scheduling_enable', value: schedulingEnable});
225
226 $('.close-pointer').hide();
227 $('.save-changes').hide();
228
229 $('.wp-pointer-buttons').append('<img id="pmxe_button_preloader" style="float:right" src="' + preloaderSrc + '" /> ');
230 $.ajax({
231 type: "POST",
232 url: ajaxurl,
233 data: formData,
234 dataType: "json",
235 success: function (data) {
236 $('#pmxe_button_preloader').remove();
237 $('.close-pointer').show();
238 $(".wpallexport-overlay").trigger('click');
239 },
240 error: function () {
241 alert('There was a problem saving the schedule');
242 $('#pmxe_button_preloader').remove();
243 $('.close-pointer').show();
244 $(".wpallexport-overlay").trigger('click');
245 }
246 });
247
248 } else {
249 alert(formValid.message);
250 }
251 return false;
252 });
253 },
254 close: function () {
255 jQuery('.wpallexport-overlay').hide();
256 }
257 }).pointer('open');
258 },
259 error: function () {
260 alert('There was a problem saving the schedule');
261 $('#pmxe_button_preloader').remove();
262 $('.close-pointer').show();
263 $(".wpallexport-overlay").trigger('click');
264 $('.wpallexport-loader').hide();
265 }
266 });
267 };
268
269
270 window.pmxeValidateSchedulingForm = function () {
271
272 var schedulingEnabled = $('input[name="scheduling_enable"]:checked').val() == 1;
273
274 if (!schedulingEnabled) {
275 return {
276 isValid: true
277 };
278 }
279
280 var runOn = $('input[name="scheduling_run_on"]:checked').val();
281
282 // Validate weekdays
283 if (runOn == 'weekly') {
284 var weeklyDays = $('#weekly_days').val();
285
286 if (weeklyDays == '') {
287 $('#weekly li').addClass('error');
288 return {
289 isValid: false,
290 message: 'Please select at least a day on which the import should run'
291 }
292 }
293 } else if (runOn == 'monthly') {
294 var monthlyDays = $('#monthly_days').val();
295
296 if (monthlyDays == '') {
297 $('#monthly li').addClass('error');
298 return {
299 isValid: false,
300 message: 'Please select at least a day on which the import should run'
301 }
302 }
303 }
304
305 // Validate times
306 var timeValid = true;
307 var timeMessage = 'Please select at least a time for the import to run';
308 var timeInputs = $('.timepicker');
309 var timesHasValues = false;
310
311 timeInputs.each(function (key, $elem) {
312
313 if($(this).val() !== ''){
314 timesHasValues = true;
315 }
316
317 if (!$(this).val().match(/^(0?[1-9]|1[012])(:[0-5]\d)[APap][mM]$/) && $(this).val() != '') {
318 $(this).addClass('error');
319 timeValid = false;
320 } else {
321 $(this).removeClass('error');
322 }
323 });
324
325 if(!timesHasValues) {
326 timeValid = false;
327 $('.timepicker').addClass('error');
328 }
329
330 if (!timeValid) {
331 return {
332 isValid: false,
333 message: timeMessage
334 };
335 }
336
337 return {
338 isValid: true
339 };
340 };
341
342 $(document).on('click', '#weekly li', function () {
343
344 $('#weekly li').removeClass('error');
345
346 if ($(this).hasClass('selected')) {
347 $(this).removeClass('selected');
348 } else {
349 $(this).addClass('selected');
350 }
351
352 $('#weekly_days').val('');
353
354 $('#weekly li.selected').each(function () {
355 var val = $(this).data('day');
356 $('#weekly_days').val($('#weekly_days').val() + val + ',');
357 });
358
359 $('#weekly_days').val($('#weekly_days').val().slice(0, -1));
360
361 });
362
363 $(document).on('click', '#monthly li', function () {
364
365 $('#monthly li').removeClass('error');
366 $(this).parent().parent().find('.days-of-week li').removeClass('selected');
367 $(this).addClass('selected');
368
369 $('#monthly_days').val($(this).data('day'));
370 });
371
372 $(document).on('change', 'input[name="scheduling_run_on"]', function () {
373 var val = $('input[name="scheduling_run_on"]:checked').val();
374 if (val == "weekly") {
375
376 $('#weekly').slideDown({
377 queue: false
378 });
379 $('#monthly').slideUp({
380 queue: false
381 });
382
383 } else if (val == "monthly") {
384
385 $('#weekly').slideUp({
386 queue: false
387 });
388 $('#monthly').slideDown({
389 queue: false
390 });
391 }
392 });
393
394 $('.timepicker').timepicker();
395
396 var selectedTimes = [];
397
398 var onTimeSelected = function () {
399
400 selectedTimes.push([$(this).val(), $(this).val() + 1]);
401
402 var isLastChild = $(this).is(':last-child');
403 if (isLastChild) {
404 $(this).parent().append('<input class="timepicker" name="scheduling_times[]" style="display: none;" type="text" />');
405 $('.timepicker:last-child').timepicker({
406 'disableTimeRanges': selectedTimes
407 });
408 $('.timepicker:last-child').fadeIn('fast');
409 $('.timepicker').on('changeTime', onTimeSelected);
410 }
411 };
412
413 $(document).on('changeTime', '.timepicker', onTimeSelected);
414
415 $('#timezone').chosen({width: '320px'});
416
417 $(document).on('click', '.wpae-save-button', function (e) {
418 if($('.wpae-save-button').hasClass('disabled')) {
419 return false;
420 }
421 var initialValue = $(this).find('.save-text').html();
422 var schedulingEnable = $('input[name="scheduling_enable"]:checked').val() == 1;
423 var validationResponse = pmxeValidateSchedulingForm();
424 if (!validationResponse.isValid) {
425
426 openSchedulingAccordeonIfClosed();
427 e.preventDefault();
428 return false;
429 }
430 var formData = $('#scheduling-form :input').serializeArray();
431
432 formData.push({name: 'security', value: wp_all_export_security});
433 formData.push({name: 'action', value: 'save_scheduling'});
434 formData.push({name: 'element_id', value: $('#scheduling_export_id').val()});
435 formData.push({name: 'scheduling_enable', value: $('input[name="scheduling_enable"]:checked').val()});
436
437 $button = $(this);
438 saveTextElement = $button.find('.save-text');
439 if (saveTextElement.length && saveTextElement.text().trim() === 'Save Scheduling Options') {
440 $button.find('.easing-spinner').toggle();
441 $button.find('.save-text').html('Saving Scheduling Options');
442 }else{
443 $button.find('.save-text').html('Saving Export Configuration');
444 }
445
446 $.ajax({
447 type: 'POST',
448 url: ajaxurl,
449 data: formData,
450 success: function (response) {
451
452 if (saveTextElement.length && saveTextElement.text().trim() === 'Saving Scheduling Options') {
453 $button.find('.easing-spinner').toggle();
454 $button.find('.save-text').html('Save Scheduling Options');
455 $button.find('svg').show();
456 $button.find('svg').fadeOut(5000);
457 }
458 var submitEvent = $.Event('wpae-scheduling-options-form:submit');
459 $(document).trigger(submitEvent);
460
461 },
462 error: function () {
463 if (saveTextElement.length && saveTextElement.text().trim() === 'Saving Scheduling Options') {
464 $button.find('.easing-spinner').toggle();
465 $button.find('.save-text').html('Save Scheduling Options');
466 alert('There was a problem saving the schedule');
467 }
468 }
469 });
470 });
471
472 $(document).on('click', '#activate-license', function (e) {
473 e.preventDefault();
474
475 let license = $('#add-subscription-field').val();
476
477 if (license) {
478 $('.activate-button-group .loader').show();
479 $('#activate-license').prop('disabled', true);
480
481 $.ajax({
482 url:ajaxurl+'?action=wpae_api&q=schedulingLicense/saveSchedulingLicense&security=' + wp_all_export_security,
483 type: "POST",
484 data: {
485 license: license
486 },
487 dataType: "json",
488 success: function (response) {
489
490 $('#activate-license .activate-license').css('background-color', '#425f9a');
491
492 if (response.success) {
493 hasActiveLicense = true;
494 $('#scheduling-subscribe-group').hide();
495 $('.activate-button-group .loader').hide();
496 $('#activate-license').prop('disabled', false);
497 $('#scheduling-schedule-input').show();
498 $('#subscribe-button svg.success').show();
499 $('#subscribe-button svg.success').fadeOut(3000, function () {
500 $('.subscribe').hide({queue: false});
501 $('#subscribe-filler').show({queue: false});
502 });
503
504 $('.save-changes').removeClass('disabled');
505 $('.wpae-save-button').removeClass('disabled')
506 window.pmxeHasSchedulingSubscription = true;
507
508 $('.wpae-no-license').hide();
509 $('.wpae-license').show();
510 $('#scheduling-connection-icon').html('');
511
512 fetchExportSchedulingConnectionIcon();
513
514 } else {
515 $subscriptionField = $('#add-subscription-field');
516 $subscriptionField.val('');
517 $subscriptionField.css('border-color', 'red');
518 $('.activate-button-group .loader').hide();
519 $('#activate-license').prop('disabled', false);
520 let licenseResponse = response.license || 'invalid';
521 $('.license-overlay').remove();
522
523 // Check for "active sites limit reached" error
524 if (licenseResponse === 'active sites limit reached') {
525 openActiveSitesLimitModal(response); // Open additional modal
526 } else {
527 // Create dynamic overlay for license error message.
528 let $overlay = $('<div class="license-overlay"></div>');
529 $overlay.html('<span style="">License error:</span><span style="margin-left:5px;font-weight:500;">' + licenseResponse + '</span>');
530
531
532 $subscriptionField.parent().css('position', 'relative');
533 $subscriptionField.after($overlay);
534
535 $overlay.css({
536 position: 'absolute',
537 top: $subscriptionField.position().top + 'px',
538 left: $subscriptionField.position().left + 'px',
539 width: $subscriptionField.outerWidth() - 20,
540 height: $subscriptionField.outerHeight(),
541 background: 'rgba(255, 255, 255, 0.9)',
542 color: $subscriptionField.css('color'),
543 fontSize: 14 + 'px',
544 fontFamily: $subscriptionField.css('font-family'),
545 fontStyle: $subscriptionField.css('font-style'),
546 lineHeight: $subscriptionField.css('line-height'),
547 display: 'flex',
548 alignItems: 'center',
549 justifyContent: 'start',
550 padding: '0 10px',
551 border: '1px solid red',
552 borderRadius: '4px',
553 pointerEvents: 'none',
554 zIndex: 9999999,
555 });
556
557 // Remove the overlay after 2.5 seconds.
558 setTimeout(() => {
559 $overlay.fadeOut(300, function () {
560 $(this).remove();
561 });
562 }, 2500);
563 }
564 }
565 }
566 });
567
568 return false;
569 }else{
570 $('#add-subscription-field').css('border-color', 'red');
571 }
572 });
573
574 /**
575 * Check settings page for Scheduling license limit reached
576 */
577
578 // Ensure this is the correct page for the plugin
579 if ($('body').hasClass('wpallexport-plugin') && window.location.search.includes('page=pmxe-admin-settings')) {
580
581 // Check if the license error div exists
582 let $licenseStatus = $('.license-status.inline.error');
583 let siteLimit = $('input[name="scheduling_license_limit"]').val(); // Fetch value of the hidden input
584
585 // Ensure both the error div exists and contains "active sites limit reached"
586 if ($licenseStatus.length && $licenseStatus.text().trim() === 'active sites limit reached' && siteLimit) {
587
588 // Trigger the modal with the limit value
589 openActiveSitesLimitModal({
590 license_limit: parseInt(siteLimit, 10),
591 });
592 }
593 }
594
595 /**
596 * Function to display modal when active sites limit reached
597 */
598 function openActiveSitesLimitModal(response) {
599 let license_limit = response.license_limit;
600 let expiration = response.expires;
601 let renewalDate = new Date(expiration * 1000).toLocaleDateString();
602
603 $('.active-sites-limit-modal-overlay').show();
604 $('.active-sites-limit-modal').show();
605
606 $('[id^="limit-"]').each(function () {
607 const limitValue = parseInt($(this).attr('id').replace('limit-', ''), 10);
608
609 if (license_limit >= limitValue) {
610 $(this).hide();
611 } else {
612 $(this).show();
613 }
614 });
615
616 $('#cta-text').text(function(index, text) {
617 return text.replace('{{renewal_date}}', renewalDate);
618 });
619
620 // Center modal dynamically in case of resizing
621 centerModal('.active-sites-limit-modal');
622
623 // Add click event handlers
624 $('.active-sites-limit-modal-overlay').on('click', function () {
625 $('.active-sites-limit-modal-overlay').hide();
626 });
627
628 // Close the modal if clicking on the overlay
629 $('.active-sites-limit-modal-overlay').on('click', function () {
630 $('.active-sites-limit-modal-overlay').hide();
631 });
632
633 // Prevent closing the modal when clicking inside the modal itself
634 $('.active-sites-limit-modal').on('click', function (e) {
635 if (!$(e.target).is('#subscribe-upgrade')) {
636 e.stopPropagation();
637 }
638 });
639
640 $('.manage-license-button').on('click', function () {
641 window.open('https://www.wpallimport.com/licenses', '_blank'); // Redirect to license management
642 });
643 }
644
645 /**
646 * Function to dynamically center a modal on screen
647 */
648 function centerModal(selector) {
649 const $modal = $(selector);
650 const windowWidth = $(window).width();
651 const windowHeight = $(window).height();
652
653 $modal.css({
654 position: 'fixed',
655 top: (windowHeight - $modal.outerHeight()) / 2 + 'px',
656 left: (windowWidth - $modal.outerWidth()) / 2 + 'px'
657 });
658 }
659
660 $(document).on('click', '#subscribe-upgrade', function(event){
661 schedulingSubscribeHandler(event, 'input[name="upgrade_pricing_plan"]:checked', 'upgrade');
662 });
663
664 $(document).on('click', '#scheduling-already-licensed', function (event) {
665
666 $('#subscribe-button-group').hide();
667 $('#checkout-trust-group').hide();
668 $('#register-site-group').removeClass('hidden');
669 $('#add-subscription-field').show();
670 $('.text-container p').fadeOut();
671 event.stopPropagation();
672
673 });
674
675 $(document).on('click', '#scheduling-subscribe-group', function (event) {
676 if (!$(event.target).is('button, input, a') && !$('#register-site-group').hasClass('hidden')) {
677 $('#subscribe-button-group').show();
678 $('#checkout-trust-group').show();
679 $('#register-site-group').addClass('hidden');
680 $('#add-subscription-field').hide().css('border-color', '');
681 $('.text-container p').fadeIn();
682 }
683 });
684
685 window.schedulingSubscribeHandler = function (event, target = 'input[name="pricing_plan"]:checked', type = 'subscribe') {
686 let selectedPlan = $(target).val();
687 let url = '';
688
689 switch (selectedPlan) {
690 case 'single_site':
691 if(type === 'subscribe') {
692 url = 'https://www.wpallimport.com/scheduling/1-site';
693 }
694 break;
695 case 'three_sites':
696 if(type === 'subscribe') {
697 url = 'https://www.wpallimport.com/scheduling/3-sites';
698 }else{
699 url = 'https://www.wpallimport.com/scheduling/upgrade-3-sites';
700 }
701 break;
702 case 'ten_sites':
703 if(type === 'subscribe') {
704 url = 'https://www.wpallimport.com/scheduling/10-sites';
705 }else{
706 url = 'https://www.wpallimport.com/scheduling/upgrade-10-sites';
707 }
708 break;
709 case 'unlimited_sites':
710 url = 'https://www.wpallimport.com/scheduling/unlimited-sites-9s9d82';
711 break;
712 default:
713 break;
714 }
715
716 if (url) {
717 $('#scheduling-already-licensed').trigger('click');
718 window.open(url, '_blank');
719 event.stopPropagation();
720 }
721 };
722
723 $(document).on('click', '#subscribe', function(event){
724 schedulingSubscribeHandler(event)
725 });
726
727 $(document).on('change', '.wpallexport-plugin .tiered-pricing-options .pricing-plans input[type="radio"]', function() {
728 $('input[name="' + $(this).attr('name') + '"]').closest('label').removeClass('checked');
729 if ($(this).is(':checked')) {
730 $(this).closest('label').addClass('checked');
731 }
732 });
733
734
735 function get_delete_missing_notice_type() {
736 let $is_delete_missing = $('input#is_delete_missing');
737 if (!$is_delete_missing.is(':checked') || $is_delete_missing.data('backups-prompt') === 'disabled') {
738 return 0;
739 }
740 if ($('input[name="delete_missing_logic"]:checked').val() == 'import' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_send_removed_to_trash"]').is(':checked')) {
741 return 1;
742 }
743 if ($('input[name="delete_missing_logic"]:checked').val() == 'import' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_change_post_status_of_removed"]').is(':checked')) {
744 return 2;
745 }
746 if ($('input[name="delete_missing_logic"]:checked').val() == 'import' && $('input[name="delete_missing_action"]:checked').val() == 'remove') {
747 return 3;
748 }
749 if ($('input[name="delete_missing_logic"]:checked').val() == 'all' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_send_removed_to_trash"]').is(':checked')) {
750 return 4;
751 }
752 if ($('input[name="delete_missing_logic"]:checked').val() == 'all' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_change_post_status_of_removed"]').is(':checked')) {
753 return 5;
754 }
755 if ($('input[name="delete_missing_logic"]:checked').val() == 'all' && $('input[name="delete_missing_action"]:checked').val() == 'remove') {
756 return 6;
757 }
758 return 0;
759 }
760
761 function is_valid_delete_missing_options() {
762 let is_valid = true;
763 if ( $('input[name="is_delete_missing"]').is(':checked') && $('input[name="delete_missing_action"]:checked').val() == 'keep' ) {
764 if ( ! $('input[name="is_send_removed_to_trash"]').is(':checked')
765 && ! $('input[name="is_change_post_status_of_removed"]').is(':checked')
766 && ! $('input[name="is_update_missing_cf"]').is(':checked')
767 && ! $('input[name="missing_records_stock_status"]').is(':checked')
768 ) {
769 is_valid = false;
770 }
771 }
772 return is_valid;
773 }
774
775 let submit_export_settings = function($button) {
776
777 var saveOnly = $button.hasClass('save_only');
778
779 var hasActiveLicense = $('#scheduling_has_license').val();
780
781 if(hasActiveLicense === '1') {
782 hasActiveLicense = true;
783 } else {
784 hasActiveLicense = false;
785 }
786
787 var initialValue = $button.find('.save-text').html();
788 var schedulingEnable = $('input[name="scheduling_enable"]:checked').val() == 1;
789 if(!hasActiveLicense) {
790 if (!$button.data('iunderstand') && schedulingEnable) {
791 $('#no-subscription').slideDown();
792 $button.find('.save-text').html('I Understand');
793 $button.find('.save-text').addClass('wpae-iunderstand');
794 $button.find('.save-text').css('left', '100px');
795 $button.data('iunderstand', 1);
796
797 openSchedulingAccordeonIfClosed();
798 e.preventDefault();
799 return;
800 } else {
801 if(saveOnly) {
802 $('#save_only_field').prop('disabled', false);
803 }
804 $('#wpae-submit-confirm-form').submit();
805 return;
806 }
807 }
808
809 // Don't process scheduling
810 if (!hasActiveLicense) {
811 if(saveOnly) {
812 $('#save_only_field').prop('disabled', false);
813 }
814 $('#wpae-submit-confirm-form').submit();
815
816 return;
817 }
818
819 var validationResponse = pmxeValidateSchedulingForm();
820 if (!validationResponse.isValid) {
821
822 openSchedulingAccordeonIfClosed();
823 $('html, body').animate({
824 scrollTop: $("#scheduling-title").offset().top-100
825 }, 500);
826 e.preventDefault();
827 return false;
828 }
829
830 var formData = $('#scheduling-form :input').serializeArray();
831
832 formData.push({name: 'security', value: wp_all_export_security});
833 formData.push({name: 'action', value: 'save_scheduling'});
834 formData.push({name: 'element_id', value: $('#scheduling_export_id').val()});
835 formData.push({name: 'scheduling_enable', value: $('input[name="scheduling_enable"]:checked').val()});
836
837 $button.find('.easing-spinner').toggle();
838
839 $.ajax({
840 type: 'POST',
841 url: ajaxurl,
842 data: formData,
843 success: function (response) {
844 $button.find('.easing-spinner').toggle();
845 $button.find('.save-text').html(initialValue);
846 $button.find('.save-text').removeClass('wpae-iunderstand');
847 $button.find('svg').show();
848
849 setTimeout(function(){
850 if(saveOnly) {
851 $('#save_only_field').prop('disabled', false);
852 }
853 $('#wpae-submit-confirm-form').submit();
854 }, 1000);
855
856 },
857 error: function () {
858 $button.find('.easing-spinner').toggle();
859 $button.find('.save-text').html(initialValue);
860 $button.find('.save-text').removeClass('wpae-iunderstand');
861 alert('There was a problem saving the schedule');
862 }
863 });
864 }
865
866 $('.wpae-save-scheduling-button, .wpae-save-scheduling-button-blue').on('click', function (e) {
867 // Validate delete missing options.
868 let notice_type = get_delete_missing_notice_type();
869
870 if ( ! is_valid_delete_missing_options() ) {
871 $('.delete-missing-error').removeClass('hidden');
872 $('.switcher-target-delete_missing_action_keep').addClass('delete-missing-error-wrapper');
873 return;
874 }
875
876 let $this = $(this);
877 // Show notice if any.
878 if (notice_type) {
879 $('.confirmation-modal-' + notice_type).find('.status_of_removed').html($('select[name="status_of_removed"]').val());
880 $('.confirmation-modal-' + notice_type).dialog({
881 resizable: false,
882 height: "auto",
883 width: 550,
884 modal: true,
885 draggable: false,
886 closeText: '',
887 classes: {
888 "ui-dialog": "wpae-warning-check"
889 },
890 buttons: {
891 "Confirm": {
892 click: function() {
893
894 let confirm_field = $('#confirm-settings-' + notice_type);
895
896 let confirm_text = confirm_field.val();
897
898 if (confirm_text !== 'I HAVE BACKUPS') {
899
900 if (confirm_text.length === 0) {
901 alert('Please type the confirmation message.');
902 } else {
903 alert('Please double-check that the confirmation message has been typed as required.');
904 }
905
906 confirm_field.addClass('confirm-error');
907
908 return false;
909 }
910
911 $( this ).dialog( "close" );
912
913 submit_export_settings($this);
914 },
915 text: 'Confirm',
916 class: 'wpae-warning-confirm-button'
917 },
918 "Cancel": {
919 click: function() {
920 $( this ).dialog( "close" );
921 },
922 text: 'Cancel',
923 class: 'wpae-warning-cancel-button'
924 }
925 }
926 });
927 } else {
928 submit_export_settings($this);
929 }
930 });
931
932 window.toggleSection = function (faqId) {
933 $('.wpallexport-plugin .tiered-pricing-options .faq-answer').each(function () {
934 if ($(this).attr('id') !== faqId) {
935 $(this).slideUp();
936 }
937 });
938
939 $('.wpallexport-plugin .tiered-pricing-options .faq-section').each(function () {
940 if ($(this).next('.faq-answer').attr('id') !== faqId) {
941 $(this).removeClass('open')
942 .addClass('closed')
943 .attr('aria-expanded', 'false');
944 }
945 });
946
947 const $faq = $('#' + faqId);
948 const $section = $faq.prev('.faq-section');
949
950 if ($faq.is(':hidden')) {
951 $faq.slideDown();
952 $section.removeClass('closed')
953 .addClass('open')
954 .attr('aria-expanded', 'true');
955 } else {
956 $faq.slideUp();
957 $section.removeClass('open')
958 .addClass('closed')
959 .attr('aria-expanded', 'false');
960 }
961 }
962
963 });})(jQuery);
964
965