PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.3
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.3
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 / admin.js
wp-all-export / static / js Last commit date
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
admin.js
2746 lines
1 /**
2 * plugin admin area javascript
3 */
4 (function($, EventService ){$(function () {
5
6 var vm = {
7 'preiviewText' :'',
8 'isGoogleMerchantsExport' : false,
9 'isWoocommerceOrderExport' : function(){
10 return $('#woo_commerce_order').length;
11 },
12 'isCSVExport': function(){
13 return $('input[name=export_to]').val() === 'csv';
14 },
15 'isProductVariationsExport' : function() {
16 return this.hasVariations;
17 },
18 'hasVariations' : false,
19 'availableDataSelector': $('.right.template-sidebar .wpae_available_data'),
20 'availableDataSelectorInModal' : $('fieldset.optionsset .wpae_available_data'),
21 'modeEnabled' : true
22 };
23
24 function processElementName($element, $elementName){
25 if ( $element.find('input[name^=cc_type]').val().indexOf('image_') !== -1 )
26 {
27 $elementName = 'Image ' + $elementName;
28 }
29 if ( $element.find('input[name^=cc_type]').val().indexOf('attachment_') !== -1 )
30 {
31 $elementName = 'Attachment ' + $elementName;
32 }
33 return $elementName;
34 }
35
36 function selectSpreadsheet()
37 {
38 vm.isGoogleMerchantsExport = false;
39 if(vm.availableDataSelector.css('position') == 'fixed') {
40 $('.template-sidebar').find('.wpae_available_data').css({'position': 'static', 'top': '50px'});
41 }
42 resetDraggable();
43 angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
44 $('.wpallexport-custom-xml-template').slideUp();
45 $('.wpallexport-simple-xml-template').slideDown();
46 $('.wpallexport-csv-options').show();
47 $('.wpallexport-xml-options').hide();
48
49 $('.wpallexport-csv-advanced-options').css('display', 'block');
50 $('.wpallexport-xml-advanced-options').css('display', 'none');
51
52 $('input[name=export_to]').val('csv');
53
54 if ($('#export_to_sheet').val() !== 'csv') {
55 if (isWooCommerceOrder || vm.isProductVariationsExport()) {
56 $('.csv_delimiter').hide();
57 $('.export_to_csv').show();
58 } else {
59 $('.export_to_csv').hide();
60 }
61 } else {
62 /** isProductVariationsExport */
63 if (isWooCommerceOrder) {
64 $('.export_to_csv').show();
65 } else {
66 $('.export_to_csv').show();
67 $('.csv_delimiter').show();
68 }
69 }
70 }
71
72 function selectFeed()
73 {
74 $('.wpallexport-csv-options').hide();
75 $('.wpallexport-xml-options').show();
76 $('input[name=export_to]').val('xml');
77 $('.xml_template_type').change();
78
79 $('.wpallexport-csv-advanced-options').css('display', 'none');
80 $('.wpallexport-xml-advanced-options').css('display', 'block');
81 }
82
83 var currentLine = -1;
84
85 var dragHelper = function(e, ui) {
86
87
88 var isEditingField = $('#combine_multiple_fields_data').find(e.currentTarget).length;
89
90 if(!vm.isGoogleMerchantsExport && !isEditingField) {
91 return $(this).clone().css("pointer-events","none").css('z-index', '99999999999999999').appendTo("body").show();
92 }
93 if(!$(this).find('.custom_column').length && !isEditingField) {
94 return $(this).clone().css("pointer-events","none").css('z-index', '999999999999999999').appendTo("body").show();
95 }
96
97 var elementName = $(this).find('.custom_column').find('input[name^=cc_name]').val();
98 elementName = helpers.sanitizeElementName(elementName);
99 elementName = processElementName($(this), elementName);
100
101 return $('<div>{' + elementName + '}</div>').css("pointer-events","none").css('z-index', 9999999999999999).appendTo("body").show();
102
103 };
104
105 var onDrag = function(e, ui)
106 {
107 var exportType = $('select.xml_template_type').val();
108
109 if ( exportType == 'custom' && isDraggingOverTextEditor(e))
110 {
111 xml_editor.focus();
112
113 if ( ui.helper.find('.custom_column').length )
114 {
115 var $elementName = ui.helper.find('.custom_column').find('input[name^=cc_name]').val();
116
117 var $elementValue = $elementName;
118 $elementName = helpers.sanitizeElementName($elementName);
119
120 if ( ! ui.helper.find('.custom_column').hasClass('wp-all-export-custom-xml-drag-over') ) ui.helper.find('.custom_column').addClass('wp-all-export-custom-xml-drag-over');
121 ui.helper.find('.custom_column').find('.wpallexport-xml-element').html("&lt;" + $elementName.replace(/ /g,'') + "&gt;<span>{" + $elementValue + "}</span>&lt;/" + $elementName.replace(/ /g,'') + "&gt;");
122 }
123 if ( ui.helper.find('.default_column').length )
124 {
125 var $elementName = ui.helper.find('.default_column').find('.wpallexport-element-label').html();
126 if ( ! ui.helper.find('.default_column').hasClass('wp-all-export-custom-xml-drag-over') ) ui.helper.find('.default_column').addClass('wp-all-export-custom-xml-drag-over');
127 }
128
129 var line = xml_editor.lineAtHeight(ui.position.top, 'page');
130 var ch = xml_editor.coordsChar(ui.position, 'page');
131
132 if( line == currentLine ) {
133 return;
134 }
135
136 if (currentLine != -1) {
137 removeLine(currentLine);
138 }
139
140 currentLine = line;
141
142 addLine("\n", line);
143
144 xml_editor_doc.setCursor({line:line, ch:ch.ch});
145 }
146
147 };
148
149 function isDraggingOverTextEditor(event) {
150 var e = event.originalEvent.originalEvent.target;
151 return $.contains(xml_editor.display.scroller, e)
152 }
153
154 function addLine(str, line, ch) {
155 if(typeof ch === 'undefined') {
156 ch = 0;
157 }
158 xml_editor.replaceRange(str, {line: line, ch:0}, {line:line, ch:0});
159 }
160
161 function removeLine(line) {
162 xml_editor.removeLine(line);
163 }
164
165 var initDraggable = function() {
166 function initGeneralDraggable($element) {
167 $element.find("li:not(.available_sub_section)").draggable({
168 appendTo: "body",
169 containment: "document",
170 helper: dragHelper,
171 drag: onDrag,
172 start: function () {
173 $('.google-merchants-droppable').css('cursor', 'copy');
174 $('#columns').css('cursor', 'copy');
175 $('.CodeMirror-lines').css('cursor', 'copy');
176 $('#combine_multiple_fields_value').css('cursor', 'copy');
177 },
178 stop: function () {
179 $('#columns').css('cursor', 'initial');
180 $('.CodeMirror-lines').css('cursor', 'text');
181 $('.google-merchants-droppable').css('cursor', 'initial');
182 $('#combine_multiple_fields_value').css('cursor', 'initial');
183 }
184 });
185 }
186
187 initGeneralDraggable(vm.availableDataSelector);
188 initGeneralDraggable(vm.availableDataSelectorInModal);
189 };
190
191 var resetDraggable = function() {
192
193 var $draggableSelector = vm.availableDataSelector.find("li:not(.available_sub_section)");
194
195 if($draggableSelector.data('ui-draggable')){
196 $draggableSelector.draggable('destroy');
197 }
198
199 initDraggable();
200 };
201
202 initDraggable();
203
204 $('.export_variations').change(function(){
205 setTimeout(liveFiltering, 200);
206 $('.wp-all-export-product-bundle-warning').hide();
207 if ($(this).val() == 3){
208 $('.warning-only-export-parent-products').show();
209 }
210 if ($(this).val() == 2){
211 $('.warning-only-export-product-variations').show();
212 }
213 });
214
215 var helpers = {
216 'sanitizeElementName' : function($elementName) {
217 if($elementName.indexOf('(per tax)') !== false ){
218 $elementName = $elementName.replace('(per tax)','PerTax');
219 $elementName = $elementName.replace('(per coupon)','PerCoupon');
220 $elementName = $elementName.replace('(per surcharge)','PerSurcharge');
221 }
222
223 return $elementName;
224 }
225 };
226
227 if ( ! $('body.wpallexport-plugin').length) return; // do not execute any code if we are not on plugin page
228
229 // fix layout position
230 setTimeout(function () {
231 $('table.wpallexport-layout').length && $('table.wpallexport-layout td.left h2:first-child').css('margin-top', $('.wrap').offset().top - $('table.wpallexport-layout').offset().top);
232 }, 10);
233
234 // help icons
235 $('.wpallexport-help, .help_scheduling').tipsy({
236 gravity: function() {
237 var ver = 'n';
238 if ($(document).scrollTop() < $(this).offset().top - $('.tipsy').height() - 2) {
239 ver = 's';
240 }
241 var hor = '';
242 if ($(this).offset().left + $('.tipsy').width() < $(window).width() + $(document).scrollLeft()) {
243 hor = 'w';
244 } else if ($(this).offset().left - $('.tipsy').width() > $(document).scrollLeft()) {
245 hor = 'e';
246 }
247 return ver + hor;
248 },
249 live: true,
250 html: true,
251 opacity: 1
252 }).live('click', function () {
253 return false;
254 }).each(function () { // fix tipsy title for IE
255 $(this).attr('original-title', $(this).attr('title'));
256 $(this).removeAttr('title');
257 });
258
259 if ($('#wp_all_export_code').length){
260 var editor = CodeMirror.fromTextArea(document.getElementById("wp_all_export_code"), {
261 lineNumbers: true,
262 matchBrackets: true,
263 mode: "application/x-httpd-php",
264 indentUnit: 4,
265 indentWithTabs: true,
266 lineWrapping: true
267 });
268 editor.setCursor(1);
269
270 $('.CodeMirror').resizable({
271 resize: function() {
272 editor.setSize("100%", $(this).height());
273 }
274 });
275 }
276
277 if ($('#wp_all_export_custom_xml_template').length)
278 {
279 var xml_editor = CodeMirror.fromTextArea(document.getElementById("wp_all_export_custom_xml_template"), {
280 lineNumbers: true,
281 matchBrackets: true,
282 mode: "xml",
283 indentUnit: 4,
284 indentWithTabs: true,
285 lineWrapping: true,
286 autoRefresh: true
287 // dragDrop: true,
288 // handleMouseEvents: true
289 });
290
291 xml_editor.setCursor(1);
292 $('.CodeMirror').resizable({
293 resize: function() {
294 xml_editor.setSize("100%", $(this).height());
295 }
296 });
297
298 var xml_editor_doc = xml_editor.getDoc();
299
300 }
301
302 if ($('#wp_all_export_main_code').length){
303 var main_editor = CodeMirror.fromTextArea(document.getElementById("wp_all_export_main_code"), {
304 lineNumbers: true,
305 matchBrackets: true,
306 mode: "application/x-httpd-php",
307 indentUnit: 4,
308 indentWithTabs: true,
309 lineWrapping: true
310 });
311 main_editor.setCursor(1);
312 $('.CodeMirror').resizable({
313 resize: function() {
314 main_editor.setSize("100%", $(this).height());
315 }
316 });
317 }
318
319 // swither show/hide logic
320 $('input.switcher').live('change', function (e) {
321
322 if ($(this).is(':radio:checked')) {
323 $(this).parents('form').find('input.switcher:radio[name="' + $(this).attr('name') + '"]').not(this).change();
324 }
325 var $switcherID = $(this).attr('id');
326
327 var $targets = $('.switcher-target-' + $switcherID);
328
329 var is_show = $(this).is(':checked'); if ($(this).is('.switcher-reversed')) is_show = ! is_show;
330 if (is_show) {
331 $targets.fadeIn('fast', function(){
332 });
333 } else {
334 $targets.hide().find('.clear-on-switch').add($targets.filter('.clear-on-switch')).val('');
335 }
336 }).change();
337
338 // swither show/hide logic
339 $('input.switcher-horizontal').live('change', function (e) {
340
341 if ($(this).is(':checked')) {
342 $(this).parents('form').find('input.switcher-horizontal[name="' + $(this).attr('name') + '"]').not(this).change();
343 }
344 var $targets = $('.switcher-target-' + $(this).attr('id'));
345
346 var is_show = $(this).is(':checked'); if ($(this).is('.switcher-reversed')) is_show = ! is_show;
347
348 if (is_show) {
349 $targets.animate({width:'205px'}, 350);
350 } else {
351 $targets.animate({width:'0px'}, 1000).find('.clear-on-switch').add($targets.filter('.clear-on-switch')).val('');
352 }
353 }).change();
354
355 // autoselect input content on click
356 $('input.selectable').live('click', function () {
357 $(this).select();
358 });
359
360 $('.pmxe_choosen').each(function(){
361 $(this).find(".choosen_input").select2({tags: $(this).find('.choosen_values').html().split(',')});
362 });
363
364 // choose file form: option selection dynamic
365 // options form: highlight options of selected post type
366 $('form.choose-post-type input[name="type"]').click(function() {
367 var $container = $(this).parents('.file-type-container');
368 $('.file-type-container').not($container).removeClass('selected').find('.file-type-options').hide();
369 $container.addClass('selected').find('.file-type-options').show();
370 }).filter(':checked').click();
371
372 $('.wpallexport-collapsed').each(function(){
373
374 if ( ! $(this).hasClass('closed')) $(this).find('.wpallexport-collapsed-content:first').slideDown();
375
376 });
377
378 $('.wpallexport-collapsed').find('.wpallexport-collapsed-header:not(.disable-jquery)').live('click', function(){
379
380 var $parent = $(this).parents('.wpallexport-collapsed:first');
381
382 if ($parent.hasClass('closed')){
383 $parent.find('hr').show();
384 $parent.removeClass('closed');
385 $parent.find('.wpallexport-collapsed-content:first').slideDown(400, function(){
386 if ($('#wp_all_export_main_code').length) {
387 main_editor.setCursor(1);
388 }
389 if ($('#wp_all_export_custom_xml_template').length){
390 xml_editor.setCursor(1);
391 }
392 });
393 }
394 else{
395 $parent.addClass('closed');
396 $parent.find('.wpallexport-collapsed-content:first').slideUp();
397 $parent.find('hr').hide();
398 }
399 });
400
401 // [ Helper functions ]
402
403 var get_valid_ajaxurl = function()
404 {
405 var $URL = ajaxurl;
406 if (typeof export_id != "undefined")
407 {
408 if ($URL.indexOf("?") == -1)
409 {
410 $URL += '?id=' + export_id;
411 }
412 else
413 {
414 $URL += '&id=' + export_id;
415 }
416 }
417 return $URL;
418 }
419
420 // generate warning on a fly when required fields deleting from the export template
421 var trigger_warnings = function()
422 {
423
424 var missing_fields = ['id'];
425
426 if ( $('#is_product_export').length ) missing_fields = missing_fields.concat(['_sku', 'product_type', 'parent']);
427 if ( $('#is_wp_query').length ) missing_fields.push('post_type');
428
429 $('#columns').find('li:not(.placeholder)').each(function(i, e){
430 $(this).find('div.custom_column:first').attr('rel', i + 1);
431 if ($(this).find('input[name^=cc_type]').val() == 'id'){
432 var index = missing_fields.indexOf('id');
433 if (index > -1) {
434 missing_fields.splice(index, 1);
435 }
436 }
437 if ($(this).find('input[name^=cc_label]').val() == '_sku'){
438 var index = missing_fields.indexOf('_sku');
439 if (index > -1) {
440 missing_fields.splice(index, 1);
441 }
442
443 }
444 if ($(this).find('input[name^=cc_label]').val() == 'product_type'){
445 var index = missing_fields.indexOf('product_type');
446 if (index > -1) {
447 missing_fields.splice(index, 1);
448 }
449 }
450 if ($(this).find('input[name^=cc_label]').val() == 'parent'){
451 var index = missing_fields.indexOf('parent');
452 if (index > -1) {
453 missing_fields.splice(index, 1);
454 }
455 }
456 if ($(this).find('input[name^=cc_label]').val() == 'post_type'){
457 var index = missing_fields.indexOf('post_type');
458 if (index > -1) {
459 missing_fields.splice(index, 1);
460 }
461 }
462 });
463
464 if ( missing_fields.length )
465 {
466 var fields = '';
467 switch (missing_fields.length)
468 {
469 case 1:
470 fields = missing_fields.shift();
471 break;
472 case 2:
473 fields = missing_fields.join(" and ");
474 break;
475 default:
476 var latest_field = missing_fields.pop();
477 fields = missing_fields.join(", ") + ", and " + latest_field;
478 break;
479 }
480
481 var warning_template = $('#warning_template').length ? $('#warning_template').val().replace("%s", fields) : '';
482
483 var is_dismiss_warnings = parseInt($('#dismiss_warnings').val());
484
485 if ( ! is_dismiss_warnings ) {
486 $('.wp-all-export-warning').find('p').html(warning_template);
487 $('.wp-all-export-warning').show();
488 }
489 }
490 else
491 {
492 $('.wp-all-export-warning').hide();
493 }
494 }
495
496 // Get a valid filtering rules for selected field type
497 var init_filtering_fields = function(){
498
499 var wp_all_export_rules_config = {
500 '#wp_all_export_xml_element' : {width:"98%"},
501 '#wp_all_export_rule' : {width:"98%"},
502 }
503
504 for (var selector in wp_all_export_rules_config) {
505
506 $(selector).chosen(wp_all_export_rules_config[selector]);
507
508 if (selector == '#wp_all_export_xml_element'){
509
510 $(selector).on('change', function(evt, params) {
511
512 $('#wp_all_export_available_rules').html('<div class="wp_all_export_preloader" style="display:block;"></div>');
513
514 var date_fields = ['post_date', 'post_modified', 'comment_date', 'user_registered', 'cf__completed_date', 'product_date'];
515
516 if ( date_fields.indexOf(params.selected) > -1 )
517 {
518 $('#date_field_notice').show();
519 }
520 else
521 {
522 $('#date_field_notice').hide();
523 }
524
525 var request = {
526 action: 'wpae_available_rules',
527 data: {'selected' : params.selected},
528 security: wp_all_export_security
529 };
530 $.ajax({
531 type: 'POST',
532 url: ajaxurl,
533 data: request,
534 success: function(response) {
535 $('#wp_all_export_available_rules').html(response.html);
536 $('#wp_all_export_rule').chosen({width:"98%"});
537 $('#wp_all_export_rule').on('change', function(evt, params) {
538 if (params.selected == 'is_empty' || params.selected == 'is_not_empty')
539 $('#wp_all_export_value').hide();
540 else
541 $('#wp_all_export_value').show();
542 });
543 },
544 dataType: "json"
545 });
546 });
547 }
548 }
549
550 $('.wp_all_export_filtering_rules').pmxe_nestedSortable({
551 handle: 'div',
552 items: 'li.dragging',
553 toleranceElement: '> div',
554 update: function () {
555 $('.wp_all_export_filtering_rules').find('.condition').removeClass('last_condition').show();
556 $('.wp_all_export_filtering_rules').find('.condition:last').addClass('last_condition');
557 liveFiltering();
558 }
559 });
560
561 }
562
563 var is_first_load = true;
564
565 var filtering = function(postType){
566
567 var is_preload = $('.wpallexport-preload-post-data').val();
568 var filter_rules_hierarhy = parseInt(is_preload) ? $('input[name=filter_rules_hierarhy]').val() : '';
569
570 $('.wpallexport-preload-post-data').val(0);
571
572 var request = {
573 action: 'wpae_filtering',
574 data: {'cpt' : postType, 'export_type' : 'specific', 'filter_rules_hierarhy' : filter_rules_hierarhy, 'product_matching_mode' : 'strict', 'taxonomy_to_export' : $('input[name=taxonomy_to_export]').val()},
575 security: wp_all_export_security
576 };
577
578 if (is_first_load == false || postType != '') $('.wp_all_export_preloader').show();
579
580 $.ajax({
581 type: 'POST',
582 url: ajaxurl,
583 data: request,
584 success: function(response) {
585
586 $('.wp_all_export_preloader').hide();
587
588 var export_type = $('input[name=export_type]').val();
589
590 if (export_type == 'advanced')
591 {
592 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
593 $('.wpallexport-choose-file').find('.wp_all_export_continue_step_two').html(response.btns);
594 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').show();
595 }
596 else
597 {
598 if (postType != '')
599 {
600
601 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').html(response.html);
602 $('.wpallexport-choose-file').find('.wp_all_export_continue_step_two').html(response.btns);
603
604 init_filtering_fields();
605 liveFiltering(is_first_load);
606 }
607 else
608 {
609 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
610 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
611 }
612 }
613
614 is_first_load = false;
615
616 },
617 error: function( jqXHR, textStatus ) {
618
619 $('.wp_all_export_preloader').hide();
620
621 },
622 dataType: "json"
623 });
624
625 };
626
627 var liveFiltering = function(first_load, after_filtering){
628
629 // serialize filters
630 $('.hierarhy-output').each(function(){
631 var sortable = $('.wp_all_export_filtering_rules.ui-sortable');
632 if (sortable.length){
633 $(this).val(window.JSON.stringify(sortable.pmxe_nestedSortable('toArray', {startDepthCount: 0})));
634 }
635 });
636
637 var postType = $('input[name=cpt]').length ? $('input[name=cpt]').val() : $('input[name=selected_post_type]').val();
638
639 var $export_only_new_stuff = $('input[name=export_only_new_stuff]').val();
640 if ($('#export_only_new_stuff').length){
641 $export_only_new_stuff = $('#export_only_new_stuff').is(':checked') ? 1 : 0;
642 }
643
644 var $export_only_modified_stuff = $('input[name=export_only_modified_stuff]').val();
645 if ($('#export_only_modified_stuff').length){
646 $export_only_modified_stuff = $('#export_only_modified_stuff').is(':checked') ? 1 : 0;
647 }
648
649 // prepare data for ajax request to get post count after filtering
650 var request = {
651 action: 'wpae_filtering_count',
652 data: {
653 'cpt' : postType,
654 'filter_rules_hierarhy' : $('input[name=filter_rules_hierarhy]').val(),
655 'product_matching_mode' : $('select[name=product_matching_mode]').length ? $('select[name=product_matching_mode]').val() : '',
656 'is_confirm_screen' : $('.wpallexport-step-4').length,
657 'is_template_screen' : $('.wpallexport-step-3').length,
658 'export_only_new_stuff' : $export_only_new_stuff,
659 'export_only_modified_stuff' : $export_only_modified_stuff,
660 'export_type' : $('input[name=export_type]').val(),
661 'taxonomy_to_export' : $('input[name=taxonomy_to_export]').val(),
662 'wpml_lang' : $('input[name=wpml_lang]').val(),
663 'export_variations' : $('#export_variations').val()
664 },
665 security: wp_all_export_security
666 };
667
668 $('.wp_all_export_preloader').show();
669 $('.wp_all_export_filter_preloader').show();
670
671 $.ajax({
672 type: 'POST',
673 url: get_valid_ajaxurl(),
674 data: request,
675 success: function(response) {
676
677 $('.wpae-record-count').val(response.found_records);
678
679 vm.hasVariations = response.hasVariations;
680 if(vm.hasVariations) {
681
682 if($('#export_to_sheet').val() == 'xls' || $('#export_to_sheet').val() == 'xlsx') {
683 $('.csv_delimiter').hide();
684 $('.export_to_csv').slideDown();
685 }
686
687 $('.product_variations').show();
688
689 }
690
691 $('.wp_all_export_filter_preloader').hide();
692
693 $('#filtering_result').html(response.html);
694
695 $('.wpallexport-choose-file').find('.wpallexport-filtering-wrapper').slideDown(400, function(){
696 if (typeof first_load != 'undefined')
697 {
698 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideDown();
699 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').addClass('closed');
700 if (response.found_records) $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').show();
701 }
702 });
703
704 $('.wp_all_export_preloader').hide();
705
706 if (typeof after_filtering != 'undefined')
707 {
708 after_filtering(response);
709 }
710
711 if ( $('.wpallexport-step-4').length && typeof wp_all_export_L10n != 'undefined'){
712
713 if (response.found_records)
714 {
715 $('.wp_all_export_confirm_and_run').show();
716 $('.confirm_and_run_bottom').val(wp_all_export_L10n.confirm_and_run);
717 $('#filtering_result').removeClass('nothing_to_export');
718 }
719 else
720 {
721 $('.wp_all_export_confirm_and_run').hide();
722 $('.confirm_and_run_bottom').val(wp_all_export_L10n.save_configuration);
723 $('#filtering_result').addClass('nothing_to_export');
724 }
725 }
726
727 if ( $('.wpallexport-step-3').length ){
728
729 $('.founded_records').html(response.html);
730
731 if (response.found_records)
732 {
733 $('.founded_records').removeClass('nothing_to_export');
734 }
735 else
736 {
737 $('.founded_records').addClass('nothing_to_export');
738 }
739 }
740
741 if ( $('.wpallexport-step-1').length)
742 {
743 if (response.found_records)
744 {
745 $('.founded_records').removeClass('nothing_to_export');
746 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').show();
747 }
748 else
749 {
750 $('.founded_records').addClass('nothing_to_export');
751 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
752 }
753 }
754 },
755 error: function( jqXHR, textStatus ) {
756
757 $('.wp_all_export_filter_preloader').hide();
758 $('.wp_all_export_preloader').hide();
759
760 },
761 dataType: "json"
762 }).fail(function(xhr, textStatus, error) {
763 $('div.error.inline').remove();
764 $('.wpallexport-header').next('.clear').after("<div class='error inline'><p>" + textStatus + " " + error + "</p></div>");
765 });
766
767 }
768 // [ \Helper functions ]
769
770
771 // [ Step 1 ( chose & filter export data ) ]
772 $('.wpallexport-step-1').each(function(){
773
774 var $wrap = $('.wrap');
775
776 var formHeight = $wrap.height();
777
778 $('.wpallexport-import-from').click(function(){
779
780 var showImportType = false;
781
782 var postType = $('input[name=cpt]').val();
783
784 switch ($(this).attr('rel')){
785 case 'specific_type':
786
787 $('.wpallexport-user-export-notice').hide();
788 $('.wpallexport-shop_customer-export-notice').hide();
789 $('.wpallexport-comments-export-notice').hide();
790
791 if (postType != '')
792 {
793 if (postType == 'users'){
794 $('.wpallexport-user-export-notice').show();
795 showImportType = false;
796 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideDown();
797 }
798 else if (postType == 'comments')
799 {
800 $('.wpallexport-comments-export-notice').show();
801 showImportType = false;
802 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideDown();
803 }
804 else if (postType == 'shop_customer')
805 {
806 $('.wpallexport-customer-export-notice').show();
807 showImportType = false;
808 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideDown();
809 }
810 else if (postType == 'taxonomies'){
811 showImportType = false;
812 $('.taxonomy_to_export_wrapper').slideDown();
813 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideDown();
814 }
815 else
816 {
817 showImportType = true;
818 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideDown();
819 }
820
821 $('.wpallexport-filtering-wrapper').show();
822 }
823 break;
824 case 'advanced_type':
825
826 $('.wpallexport-user-export-notice').hide();
827 $('.wpallexport-comments-export-notice').hide();
828 $('.wpallexport-shop_customer-export-notice').hide();
829
830 if ($('input[name=wp_query_selector]').val() == 'wp_user_query')
831 {
832 $('.wpallexport-user-export-notice').show();
833 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
834 showImportType = false;
835 }
836 else if ($('input[name=wp_query_selector]').val() == 'wp_comment_query')
837 {
838 $('.wpallexport-comments-export-notice').show();
839 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
840 showImportType = false;
841 }
842 else
843 {
844 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
845 showImportType = true;
846 }
847 $('.wpallexport-filtering-wrapper').hide();
848 filtering();
849 break;
850 }
851
852 $('.wpallexport-import-from').removeClass('selected').addClass('bind');
853 $(this).addClass('selected').removeClass('bind');
854 $('.wpallexport-choose-file').find('.wpallexport-upload-type-container').hide();
855 $('.wpallexport-choose-file').find('.wpallexport-upload-type-container[rel=' + $(this).attr('rel') + ']').show();
856 $('.wpallexport-choose-file').find('input[name=export_type]').val( $(this).attr('rel').replace('_type', '') );
857
858 if ( ! showImportType)
859 {
860 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
861 }
862 else{
863 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').show();
864 }
865
866 });
867
868 $('.wpallexport-import-from.selected').click();
869
870 $('#file_selector').ddslick({
871 width: 600,
872 onSelected: function(selectedData){
873
874 $('.wpallexport-user-export-notice').hide();
875 $('.wpallexport-comments-export-notice').hide();
876 $('.wpallexport-shop_customer-export-notice').hide();
877 $('.wpallexport-taxonomies-export-notice').hide();
878
879 if (selectedData.selectedData.value != ""){
880
881 $('#file_selector').find('.dd-selected').css({'color':'#555'});
882
883 var i = 0;
884 var postType = selectedData.selectedData.value;
885 $('#file_selector').find('.dd-option-value').each(function(){
886 if (postType == $(this).val()) return false;
887 i++;
888 });
889
890 $('.wpallexport-choose-file').find('input[name=cpt]').val(postType);
891
892 if (postType == 'taxonomies'){
893 $('.taxonomy_to_export_wrapper').slideDown();
894 if ($('input[name=taxonomy_to_export]').val() != ''){
895 filtering(postType);
896 }
897 else{
898 $('.wpallexport-choose-file').find('.wpallexport-filtering-wrapper').slideUp();
899 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
900 }
901 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
902 }
903 else{
904 $('.taxonomy_to_export_wrapper').slideUp();
905
906 if (postType == 'users')
907 {
908 $('.wpallexport-user-export-notice').show();
909 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
910 }
911 else if (postType == 'comments')
912 {
913 $('.wpallexport-comments-export-notice').show();
914 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
915 }
916 else if (postType == 'shop_customer')
917 {
918 $('.wpallexport-shop_customer-export-notice').show();
919 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
920 }
921 else
922 {
923 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').show();
924 }
925
926 filtering(postType);
927 }
928 }
929 else
930 {
931 $('.taxonomy_to_export_wrapper').slideUp();
932 $('.wpallexport-choose-file').find('input[name=cpt]').val('');
933 $('#file_selector').find('.dd-selected').css({'color':'#cfceca'});
934 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
935 $('.wpallexport-choose-file').find('.wpallexport-filtering-wrapper').slideUp();
936
937 switch ($('.wpallexport-import-from.selected').attr('rel')){
938 case 'specific_type':
939 filtering($('input[name=cpt]').val());
940 break;
941 case 'advanced_type':
942
943 break;
944 }
945 }
946 }
947 });
948
949 $('a.auto-generate-template').live('click', function(){
950
951 var export_type = $('input[name="cpt"]').val();
952
953 if(export_type == 'shop_order') {
954 $('#migrate-orders-notice').slideDown();
955 return;
956 }
957
958 $('input[name^=auto_generate]').val('1');
959
960 $('.hierarhy-output').each(function(){
961 var sortable = $('.wp_all_export_filtering_rules.ui-sortable');
962 if (sortable.length){
963 $(this).val(window.JSON.stringify(sortable.pmxe_nestedSortable('toArray', {startDepthCount: 0})));
964 }
965 });
966
967 $(this).parents('form:first').submit();
968 });
969
970 $('form.wpallexport-choose-file').find('input[type=submit]').click(function(e){
971 e.preventDefault();
972
973 $('.hierarhy-output').each(function(){
974 var sortable = $('.wp_all_export_filtering_rules.ui-sortable');
975 if (sortable.length){
976 $(this).val(window.JSON.stringify(sortable.pmxe_nestedSortable('toArray', {startDepthCount: 0})));
977 }
978 });
979
980 $(this).parents('form:first').submit();
981 });
982
983 $('#wp_query_selector').ddslick({
984 width: 600,
985 onSelected: function(selectedData){
986
987 $('.wpallexport-user-export-notice').hide();
988 $('.wpallexport-comments-export-notice').hide();
989 $('.wpallexport-shop_customer-export-notice').hide();
990 $('.wpallexport-taxonomies-export-notice').hide();
991
992 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
993
994 if (selectedData.selectedData.value != ""){
995
996 $('#wp_query_selector').find('.dd-selected').css({'color':'#555'});
997 var queryType = selectedData.selectedData.value;
998 if (queryType == 'wp_query'){
999 $('textarea[name=wp_query]').attr("placeholder", "'post_type' => 'post', 'post_status' => array( 'pending', 'draft', 'future' )");
1000 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').show();
1001 }
1002 if(queryType == 'wp_user_query')
1003 {
1004 $('.wpallexport-user-export-notice').show();
1005 $('textarea[name=wp_query]').attr("placeholder", "'role' => 'Administrator'");
1006 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
1007 }
1008 else if(queryType == 'wp_comment_query')
1009 {
1010 $('.wpallexport-comments-export-notice').show();
1011 $('textarea[name=wp_query]').attr("placeholder", "'meta_key' => 'featured', 'meta_value' => '1'");
1012 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
1013 }
1014 $('input[name=wp_query_selector]').val(queryType);
1015 }
1016 else{
1017
1018 $('#wp_query_selector').find('.dd-selected').css({'color':'#cfceca'});
1019 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
1020
1021 }
1022 }
1023 });
1024 // Taxonomies Export
1025 $('#taxonomy_to_export').ddslick({
1026 width: 600,
1027 onSelected: function(selectedData){
1028
1029 if (selectedData.selectedData.value != ""){
1030
1031 $('#taxonomy_to_export').find('.dd-selected').css({'color':'#555'});
1032 $('input[name=taxonomy_to_export]').val(selectedData.selectedData.value);
1033 filtering($('input[name=cpt]').val());
1034 $('.wpallexport-taxonomies-export-notice').show();
1035 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
1036 }
1037 else{
1038 $('#taxonomy_to_export').find('.dd-selected').css({'color':'#cfceca'});
1039 $('.wpallexport-choose-file').find('.wpallexport-filtering-wrapper').slideUp();
1040 $('.wpallexport-choose-file').find('.wpallexport-upload-resource-step-two').slideUp();
1041 $('.wpallexport-choose-file').find('.wpallexport-submit-buttons').hide();
1042 }
1043 }
1044 });
1045 });
1046 // [ \Step 1 ( chose & filter export data ) ]
1047
1048
1049 // [ Step 2 ( export template ) ]
1050 $('.wpallexport-export-template').each(function(){
1051
1052 trigger_warnings();
1053
1054 var $sortable = $( "#columns" );
1055
1056 var outsideContainer = 0;
1057
1058 // this one control if the draggable is outside the droppable area
1059 $('#columns_to_export').droppable({
1060 accept : '.ui-sortable-helper'
1061 });
1062
1063 $( "#columns_to_export" ).on( "dropout", function( event, ui ) {
1064 outsideContainer = 1;
1065 ui.draggable.find('.custom_column').css('background', 'white');
1066 } );
1067
1068 $( "#columns_to_export" ).on( "dropover", function( event, ui ) {
1069 outsideContainer = 0;
1070 ui.draggable.find('.custom_column').css('background', 'white');
1071 } );
1072
1073 // this one control if the draggable is dropped
1074 $('body, form.wpallexport-template').droppable({
1075 accept : '.ui-sortable-helper',
1076 drop : function(event, ui){
1077 if(outsideContainer == 1){
1078 ui.draggable.remove();
1079 trigger_warnings();
1080
1081 if ( $('#columns').find('li:not(.placeholder)').length === 1)
1082 {
1083 $('#columns').find( ".placeholder" ).show();
1084 }
1085 }else{
1086 ui.draggable.find('.custom_column').css('background', 'none');
1087 }
1088 }
1089 });
1090
1091 $( "#columns_to_export ol" ).droppable({
1092 activeClass: "pmxe-state-default",
1093 hoverClass: "pmxe-state-hover",
1094 accept: ":not(.ui-sortable-helper)",
1095 drop: function( event, ui ) {
1096
1097 if(event.originalEvent.target.nodeName == 'TEXTAREA') {
1098 return;
1099 }
1100 $( this ).find( ".placeholder" ).hide();
1101
1102 if (ui.draggable.find('input[name^=rules]').length){
1103 $('li.' + ui.draggable.find('input[name^=rules]').val()).each(function(){
1104 var $value = $(this).find('input[name^=cc_value]').val();
1105 var $is_media_field = false;
1106 if ( $(this).find('input[name^=cc_type]').val().indexOf('image_') !== -1 || $(this).find('input[name^=cc_type]').val().indexOf('attachment_') !== -1 )
1107 {
1108 $value = $(this).find('input[name^=cc_type]').val();
1109 $is_media_field = true;
1110 }
1111 var $add_field = true;
1112 $('#columns').find('li').each(function(){
1113 if ( $is_media_field )
1114 {
1115 if ($(this).find('input[name^=cc_type]').val() == $value){
1116 $add_field = false;
1117 }
1118 }
1119 else
1120 {
1121 if ($(this).find('input[name^=cc_value]').val() == $value){
1122 $add_field = false;
1123 }
1124 }
1125 });
1126 if ($add_field)
1127 {
1128 $( "<li></li>" ).html( $(this).html() ).appendTo( $( "#columns_to_export ol" ) );
1129 var $just_added = $('#columns').find('li:last').find('div:first');
1130 $just_added.attr('rel', $('#columns').find('li:not(.placeholder)').length);
1131 if ( $just_added.find('input[name^=cc_type]').val().indexOf('image_') !== -1 )
1132 {
1133 $just_added.find('.wpallexport-xml-element').html('Image ' + $just_added.find('input[name^=cc_name]').val());
1134 $just_added.find('input[name^=cc_name]').val('Image ' + $just_added.find('input[name^=cc_name]').val());
1135 }
1136 if ( $just_added.find('input[name^=cc_type]').val().indexOf('attachment_') !== -1 )
1137 {
1138 $just_added.find('.wpallexport-xml-element').html('Attachment ' + $just_added.find('input[name^=cc_name]').val());
1139 $just_added.find('input[name^=cc_name]').val('Attachment ' + $just_added.find('input[name^=cc_name]').val());
1140 }
1141 }
1142 });
1143 }
1144 else{
1145 $( "<li></li>" ).html( ui.draggable.html() ).appendTo( this );
1146 var $just_added = $('#columns').find('li:last').find('div:first');
1147 $just_added.attr('rel', $('#columns').find('li:not(.placeholder)').length);
1148 if ( $just_added.find('input[name^=cc_type]').val().indexOf('image_') !== -1 )
1149 {
1150 $just_added.find('.wpallexport-xml-element').html('Image ' + $just_added.find('input[name^=cc_name]').val());
1151 $just_added.find('input[name^=cc_name]').val('Image ' + $just_added.find('input[name^=cc_name]').val());
1152 }
1153 if ( $just_added.find('input[name^=cc_type]').val().indexOf('attachment_') !== -1 )
1154 {
1155 $just_added.find('.wpallexport-xml-element').html('Attachment ' + $just_added.find('input[name^=cc_name]').val());
1156 $just_added.find('input[name^=cc_name]').val('Attachment ' + $just_added.find('input[name^=cc_name]').val());
1157 }
1158 }
1159
1160 trigger_warnings();
1161
1162 }
1163 }).sortable({
1164 items: "li:not(.placeholder)",
1165 sort: function() {
1166 // gets added unintentionally by droppable interacting with sortable
1167 // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
1168 $( this ).removeClass( "ui-state-default" );
1169 }
1170 });
1171
1172 $( ".CodeMirror-code" ).droppable({
1173 activeClass: "pmxe-template-state-default",
1174 hoverClass: "pmxe-template-state-hover",
1175 accept: ":not(.ui-sortable-helper)",
1176 drag: function( event, ui ){
1177 },
1178 drop: function( event, ui ) {
1179
1180 function getCodeToPlace($elementName) {
1181 var $elementValue = $elementName;
1182 $elementName = helpers.sanitizeElementName($elementName);
1183 return "<" + $elementName.replace(/ /g,'') + ">{" + $elementValue+ "}</" + $elementName.replace(/ /g,'') + ">\n"
1184 }
1185
1186
1187 function replaceLineWithElements(content){
1188 removeLine(currentLine);
1189
1190 addLine( content, currentLine, currentLine);
1191 currentLine = -1;
1192
1193 var totalLines = xml_editor.lineCount();
1194 xml_editor.autoIndentRange({line:0, ch:0}, {line:totalLines,ch:100});
1195 }
1196
1197 if (ui.draggable.find('input[name^=rules]').length){
1198 var content = "";
1199 $('li.' + ui.draggable.find('input[name^=rules]').val()).each(function(){
1200 var $elementName = $(this).find('input[name^=cc_name]').val();
1201 $elementName = processElementName($(this),$elementName);
1202 content = content + getCodeToPlace($elementName);
1203 });
1204
1205 replaceLineWithElements(content);
1206 }
1207 else{
1208 var $elementName = ui.draggable.find('.custom_column').find('input[name^=cc_name]').val();
1209 var $element = ui.draggable.find('.custom_column');
1210 $elementName = processElementName($element, $elementName);
1211
1212 replaceLineWithElements(getCodeToPlace($elementName));
1213 }
1214 }
1215 });
1216
1217 var $this = $(this);
1218 var $addAnother = $this.find('input.add_column');
1219 var $addAnotherForm = $('fieldset.wp-all-export-edit-column');
1220 var $template = $(this).find('.custom_column.template');
1221
1222 if (typeof wpPointerL10n != "undefined") wpPointerL10n.dismiss = 'Close';
1223
1224 // Add Another btn click
1225 $addAnother.click(function(){
1226
1227 $addAnotherForm.find('form')[0].reset();
1228 $addAnotherForm.find('.column_name').val('ID');
1229
1230 $addAnotherForm.find('input[name="combine_multiple_fields"][value="0"]').prop('checked',true).trigger('click');
1231
1232 // Reset custom field
1233 $('#combine_multiple_fields_value_container').hide();
1234 $('#combine_multiple_fields_data').hide();
1235 $('.export-single').show();
1236 $('.single-field-options').show();
1237 $('.php_snipped').show();
1238 $('.add-new-field-notice').hide();
1239
1240 $addAnotherForm.removeAttr('rel');
1241 $addAnotherForm.removeClass('dc').addClass('cc');
1242 $addAnotherForm.find('.cc_field').hide();
1243
1244 $addAnotherForm.find('.wpallexport-edit-row-title').hide();
1245 $addAnotherForm.find('.wpallexport-add-row-title').show();
1246 $addAnotherForm.find('div[class^=switcher-target]').hide();
1247 $addAnotherForm.find('#coperate_php').removeAttr('checked');
1248 $addAnotherForm.find('input.column_name').parents('div.input:first').show();
1249
1250 $('.custom_column').removeClass('active');
1251
1252 $addAnotherForm.find('select[name=column_value_type]').find('option').each(function(){
1253 if ($(this).val() == 'id')
1254 $(this).attr({'selected':'selected'}).click();
1255 else
1256 $(this).removeAttr('selected');
1257 });
1258
1259 $('.wp-all-export-chosen-select').trigger('chosen:updated');
1260 $('.wp_all_export_saving_status').html('');
1261
1262 $('.wpallexport-overlay').show();
1263
1264 $addAnotherForm.find('input.switcher').change();
1265 $addAnotherForm.show();
1266
1267 });
1268
1269 // Delete custom column action
1270 $addAnotherForm.find('.delete_action').click(function(){
1271
1272 $('.custom_column').removeClass('active');
1273
1274 $('.custom_column[rel='+ $addAnotherForm.attr('rel') +']').parents('li:first').fadeOut().remove();
1275
1276 if ( ! $('#columns').find('li:visible').length ){
1277 $('#columns').find( ".placeholder" ).show();
1278 }
1279
1280 trigger_warnings();
1281
1282 $addAnotherForm.fadeOut();
1283 $('.wpallexport-overlay').hide();
1284 });
1285
1286 // Add/Edit custom column action
1287 $addAnotherForm.find('.save_action').click(function(event){
1288
1289 if($(this).hasClass('disabled')) {
1290 event.preventDefault();
1291 event.stopImmediatePropagation();
1292 return false;
1293 }
1294 var $save = true;
1295
1296 // element name in exported file
1297 var $elementName = $addAnotherForm.find('input.column_name');
1298
1299 // element name validation
1300 if ($elementName.val() == '')
1301 {
1302 $save = false;
1303 $elementName.addClass('error');
1304 return false;
1305 }
1306
1307 // get PHP function name
1308 var $phpFunction = $addAnotherForm.find('.php_code:visible');
1309
1310 // validation passed, prepare field data
1311 var $elementIndex = $addAnotherForm.attr('rel');
1312 // element type
1313 var $elementType = $addAnotherForm.find('select[name=column_value_type]');
1314 // element label, options and other stuff
1315 var $elementDetails = $elementType.find('option:selected');
1316 // element labeel
1317 var $elementLabel = $elementDetails.attr('label');
1318
1319 var $clone = ( $elementIndex ) ? $('#columns').find('.custom_column[rel='+ $elementIndex +']') : $template.clone(true);
1320
1321 // if new field adding
1322 if ( ! parseInt( $elementIndex ) )
1323 {
1324 // new column added, increase element Index
1325 $clone.attr('rel', $('#columns').find('.custom_column').length + 1);
1326 }
1327
1328 // add element label
1329 $clone.find('label.wpallexport-xml-element').html( $elementName.val() );
1330 // wrap field value into PHP function
1331 $clone.find('input[name^=cc_php]').val( $addAnotherForm.find('#coperate_php').is(':checked') ? '1' : '0' );
1332 // save PHP function name
1333 $clone.find('input[name^=cc_code]').val( $phpFunction.val() );
1334 // save SQL code
1335 $clone.find('input[name^=cc_sql]').val( $addAnotherForm.find('textarea.column_value').val() );
1336 // save element name
1337 $clone.find('input[name^=cc_name]').val( $elementName.val() );
1338 // save element type
1339 $clone.find('input[name^=cc_type]').val( $elementType.val() );
1340 // save element value
1341 $clone.find('input[name^=cc_value]').val( $elementDetails.attr('label') );
1342 // save element label
1343 $clone.find('input[name^=cc_label]').val( $elementDetails.attr('label') );
1344 // save element options
1345 $clone.find('input[name^=cc_options]').val( $elementDetails.attr('options') );
1346
1347 $('.add-new-field-notice').hide();
1348
1349 // if new field adding append element to the export template
1350 if ( ! parseInt( $elementIndex ) )
1351 {
1352 $( "#columns" ).find( ".placeholder" ).hide();
1353 $sortable.append('<li></li>');
1354 $sortable.find('li:last').append($clone.removeClass('template').fadeIn());
1355 }
1356
1357 var $fieldType = $elementType.val();
1358
1359 if ($elementLabel == '_sale_price_dates_from' || $elementLabel == '_sale_price_dates_to') $fieldType = 'date';
1360
1361 // set up additional element settings by element type
1362 switch ( $fieldType )
1363 {
1364 case 'content':
1365 var obj = {};
1366 obj['export_images_from_gallery'] = $addAnotherForm.find('#export_images_from_gallery').is(':checked');
1367 $clone.find('input[name^=cc_settings]').val(window.JSON.stringify(obj));
1368 break;
1369 // save post date field format
1370 case 'date':
1371 case 'comment_date':
1372 case 'user_registered':
1373 case 'post_modified':
1374 var $dateType = $addAnotherForm.find('select.date_field_export_data').val();
1375 if ($dateType == 'unix')
1376 $clone.find('input[name^=cc_settings]').val('unix');
1377 else
1378 $clone.find('input[name^=cc_settings]').val($('.pmxe_date_format').val());
1379 break;
1380 // set up additional settings for repeater field
1381 case 'acf':
1382 // determine is repeater field selected in dropdown
1383 if ( $clone.find('input[name^=cc_options]').val().indexOf('s:4:"type";s:8:"repeater"') !== -1 )
1384 {
1385 var obj = {};
1386 obj['repeater_field_item_per_line'] = $addAnotherForm.find('#repeater_field_item_per_line').is(':checked');
1387 obj['repeater_field_fill_empty_columns'] = $addAnotherForm.find('#repeater_field_fill_empty_columns').is(':checked');
1388 $clone.find('input[name^=cc_settings]').val(window.JSON.stringify(obj));
1389 }
1390 break;
1391 case 'woo':
1392 switch ( $clone.find('input[name^=cc_value]').val() )
1393 {
1394 case '_upsell_ids':
1395 case '_crosssell_ids':
1396 case 'item_data___upsell_ids':
1397 case 'item_data___crosssell_ids':
1398 $clone.find('input[name^=cc_settings]').val($addAnotherForm.find('select.linked_field_export_data').val());
1399 break;
1400 }
1401 break;
1402 case 'woo_order':
1403 $woo_type = $clone.find('input[name^=cc_value]');
1404 switch ($woo_type.val()) {
1405 case 'post_date':
1406 case 'post_modified':
1407 case '_completed_date':
1408 var $dateType = $addAnotherForm.find('select.date_field_export_data').val();
1409 if ($dateType == 'unix')
1410 $clone.find('input[name^=cc_settings]').val('unix');
1411 else
1412 $clone.find('input[name^=cc_settings]').val($('.pmxe_date_format').val());
1413 break;
1414 }
1415 break;
1416 default:
1417 // save option for media images field types
1418 if ( $clone.find('input[name^=cc_type]').val().indexOf('image_') !== -1 )
1419 {
1420 var obj = {};
1421 obj['is_export_featured'] = $addAnotherForm.find('#is_image_export_featured').is(':checked');
1422 obj['is_export_attached'] = $addAnotherForm.find('#is_image_export_attached_images').is(':checked');
1423 obj['image_separator'] = $addAnotherForm.find('input[name=image_field_separator]').val();
1424 $clone.find('input[name^=cc_options]').val(window.JSON.stringify(obj));
1425 }
1426
1427 break;
1428 }
1429
1430 trigger_warnings();
1431
1432 $addAnotherForm.hide();
1433
1434 $('.wpallexport-overlay').hide();
1435
1436 $('.custom_column').removeClass('active');
1437
1438 });
1439
1440 // Clicking on column for edit
1441 $('#columns').find('.custom_column').live('click', function(){
1442
1443 $('.add-new-field-notice').hide();
1444
1445 $addAnotherForm.find('form')[0].reset();
1446 $addAnotherForm.find('input[type=checkbox]').removeAttr('checked');
1447
1448 $addAnotherForm.removeClass('dc').addClass('cc');
1449 $addAnotherForm.attr('rel', $(this).attr('rel'));
1450
1451 $addAnotherForm.find('.wpallexport-add-row-title').hide();
1452 $addAnotherForm.find('.wpallexport-edit-row-title').show();
1453
1454 $addAnotherForm.find('input.column_name').parents('div.input:first').show();
1455
1456 $addAnotherForm.find('.cc_field').hide();
1457 $('.custom_column').removeClass('active');
1458 $(this).addClass('active');
1459
1460 var $elementType = $(this).find('input[name^=cc_type]');
1461 var $elementLabel = $(this).find('input[name^=cc_label]');
1462
1463
1464 $('.wp_all_export_saving_status').html('');
1465
1466 $addAnotherForm.find('select[name=column_value_type]').find('option').each(function(){
1467 if ($(this).attr('label') == $elementLabel.val() && $(this).val() == $elementType.val())
1468 $(this).attr({'selected':'selected'}).click();
1469 else
1470 $(this).removeAttr('selected');
1471 });
1472
1473 $('.wp-all-export-chosen-select').trigger('chosen:updated');
1474
1475 // set php snipped
1476 var $php_code = $(this).find('input[name^=cc_code]');
1477 var $is_php = parseInt($(this).find('input[name^=cc_php]').val());
1478
1479 if ($is_php){
1480 $addAnotherForm.find('#coperate_php').attr({'checked':'checked'});
1481 $addAnotherForm.find('#coperate_php').parents('div.input:first').find('div[class^=switcher-target]').show();
1482 }
1483 else{
1484 $addAnotherForm.find('#coperate_php').removeAttr('checked');
1485 $addAnotherForm.find('#coperate_php').parents('div.input:first').find('div[class^=switcher-target]').hide();
1486 }
1487
1488 var $isCombineMultipleFieldsIntoOne = $(this).find('input[name^=cc_combine_multiple_fields]').val();
1489
1490 if($isCombineMultipleFieldsIntoOne == "1") {
1491 $addAnotherForm.find('input[name="combine_multiple_fields"][value="1"]').attr('checked', true);
1492 $addAnotherForm.find('#combine_multiple_fields_value').val($(this).find('input[name^=cc_combine_multiple_fields_value]').val());
1493
1494 $('#combine_multiple_fields_value_container').show();
1495 $('#combine_multiple_fields_data').show();
1496 $('.export-single').hide();
1497 } else {
1498 $addAnotherForm.find('input[name="combine_multiple_fields"][value="0"]').attr('checked', true);
1499
1500 $('#combine_multiple_fields_value_container').hide();
1501 $('#combine_multiple_fields_data').hide();
1502 $('.export-single').show();
1503
1504 }
1505
1506 $addAnotherForm.find('#coperate_php').parents('div.input:first').find('.php_code').val($php_code.val());
1507
1508 var $options = $(this).find('input[name^=cc_options]').val();
1509 var $settings = $(this).find('input[name^=cc_settings]').val();
1510
1511 var $fieldType = $elementType.val();
1512
1513 if ($elementLabel.val() == '_sale_price_dates_from' || $elementLabel.val() == '_sale_price_dates_to') $fieldType = 'date';
1514
1515 switch ( $fieldType ){
1516 case 'content':
1517 $addAnotherForm.find('.content_field_type').show();
1518 if ($settings != "" && $settings != 0)
1519 {
1520 var $field_options = window.JSON.parse($settings);
1521 if ($field_options.export_images_from_gallery) $addAnotherForm.find('#export_images_from_gallery').attr('checked','checked');
1522 }
1523 else{
1524 // this option should be enabled by default
1525 $addAnotherForm.find('#export_images_from_gallery').attr('checked','checked');
1526 }
1527 break;
1528 case 'sql':
1529 $addAnotherForm.find('textarea.column_value').val($(this).find('input[name^=cc_sql]').val());
1530 $addAnotherForm.find('.sql_field_type').show();
1531 break;
1532 case 'acf':
1533 if ($options.indexOf('s:4:"type";s:8:"repeater"') !== -1)
1534 {
1535 $addAnotherForm.find('.repeater_field_type').show();
1536 if ($settings != "")
1537 {
1538 var $field_options = window.JSON.parse($settings);
1539 if ($field_options.repeater_field_item_per_line) $addAnotherForm.find('#repeater_field_item_per_line').attr('checked','checked');
1540 if ($field_options.repeater_field_fill_empty_columns) $addAnotherForm.find('#repeater_field_fill_empty_columns').attr('checked','checked');
1541 }
1542 }
1543 break;
1544 case 'woo':
1545 $woo_type = $(this).find('input[name^=cc_value]');
1546 switch ($woo_type.val())
1547 {
1548 case '_upsell_ids':
1549 case '_crosssell_ids':
1550 case 'item_data___upsell_ids':
1551 case 'item_data___crosssell_ids':
1552
1553 $addAnotherForm.find('select.linked_field_export_data').find('option').each(function(){
1554 if ($(this).val() == $settings)
1555 $(this).attr({'selected':'selected'}).click();
1556 else
1557 $(this).removeAttr('selected');
1558 });
1559 $addAnotherForm.find('.linked_field_type').show();
1560 break;
1561 }
1562 break;
1563 case 'woo_order':
1564 $woo_type = $(this).find('input[name^=cc_value]');
1565 switch ($woo_type.val())
1566 {
1567 case 'post_date':
1568 case 'post_modified':
1569 case '_completed_date':
1570
1571 $addAnotherForm.find('select.date_field_export_data').find('option').each(function(){
1572 if ($(this).val() == $settings || $settings != 'unix' && $(this).val() == 'php')
1573 $(this).attr({'selected':'selected'}).click();
1574 else
1575 $(this).removeAttr('selected');
1576 });
1577
1578 if ($settings != 'php' && $settings != 'unix'){
1579 if ($settings != '0') $('.pmxe_date_format').val($settings); else $('.pmxe_date_format').val('');
1580 $('.pmxe_date_format_wrapper').show();
1581 }
1582 else{
1583 $('.pmxe_date_format').val('');
1584 }
1585 $addAnotherForm.find('.date_field_type').show();
1586 break;
1587 }
1588 break;
1589 case 'date':
1590 case 'comment_date':
1591 case 'user_registered':
1592 case 'post_modified':
1593 $addAnotherForm.find('select.date_field_export_data').find('option').each(function(){
1594 if ($(this).val() == $settings || $settings != 'unix' && $(this).val() == 'php')
1595 $(this).attr({'selected':'selected'}).click();
1596 else
1597 $(this).removeAttr('selected');
1598 });
1599
1600 if ($settings != 'php' && $settings != 'unix'){
1601 if ($settings != '0') $('.pmxe_date_format').val($settings); else $('.pmxe_date_format').val('');
1602 $('.pmxe_date_format_wrapper').show();
1603 }
1604 else{
1605 $('.pmxe_date_format').val('');
1606 }
1607 $addAnotherForm.find('.date_field_type').show();
1608 break;
1609 default:
1610
1611 if ( $elementType.val().indexOf('image_') !== -1 )
1612 {
1613 $addAnotherForm.find('.image_field_type').show();
1614
1615 if ($options != "")
1616 {
1617 var $field_options = window.JSON.parse($options);
1618
1619 if ($field_options.is_export_featured) $addAnotherForm.find('#is_image_export_featured').attr('checked','checked');
1620 if ($field_options.is_export_attached) $addAnotherForm.find('#is_image_export_attached_images').attr('checked','checked');
1621
1622 $addAnotherForm.find('input[name=image_field_separator]').val($field_options.image_separator);
1623 }
1624 }
1625
1626 break;
1627 }
1628
1629 $addAnotherForm.find('input.switcher').change();
1630
1631 var $column_name = $(this).find('input[name^=cc_name]').val();
1632
1633 $addAnotherForm.find('input.column_name').val($column_name);
1634 $addAnotherForm.show();
1635 $('.wpallexport-overlay').show();
1636
1637 var availableDataHeight = $('.wp-all-export-edit-column.cc').height()- 200;
1638
1639 });
1640
1641 // Preview export file
1642 var doPreview = function( ths, tagno ){
1643
1644 $('.wpallexport-overlay').show();
1645
1646 ths.pointer({
1647 content: '<div class="wpallexport-preview-preload wpallexport-pointer-preview"></div>',
1648 position: {
1649 edge: 'right',
1650 align: 'center'
1651 },
1652 pointerWidth: 850,
1653 close: function() {
1654 $.post( ajaxurl, {
1655 pointer: 'pksn1',
1656 action: 'dismiss-wp-pointer'
1657 });
1658 $('.wpallexport-overlay').hide();
1659 }
1660 }).pointer('open');
1661
1662 var $pointer = $('.wpallexport-pointer-preview').parents('.wp-pointer').first();
1663
1664 var $leftOffset = ($(window).width() - 850)/2;
1665
1666 $pointer.css({'position':'fixed', 'top' : '15%', 'left' : $leftOffset + 'px'});
1667
1668 var request = {
1669 action: 'wpae_preview',
1670 data: $('form.wpallexport-step-3').serialize(),
1671 custom_xml: xml_editor.getValue(),
1672 tagno: tagno,
1673 security: wp_all_export_security
1674 };
1675 var url = get_valid_ajaxurl();
1676 var show_cdata = $('#show_cdata_in_preview').val();
1677
1678 if (url.indexOf("?") == -1) {
1679 url += '?show_cdata=' + show_cdata;
1680 } else {
1681 url += '&show_cdata=' + show_cdata;
1682 }
1683
1684 $.ajax({
1685 type: 'POST',
1686 url: url,
1687 data: request,
1688 success: function(response) {
1689
1690 ths.pointer({'content' : response.html});
1691
1692 $pointer.css({'position':'fixed', 'top' : '15%', 'left' : $leftOffset + 'px'});
1693
1694 var $preview = $('.wpallexport-preview');
1695
1696 $preview.parent('.wp-pointer-content').removeClass('wp-pointer-content').addClass('wpallexport-pointer-content');
1697
1698 $preview.find('.navigation a').unbind('click').die('click').live('click', function () {
1699
1700 tagno += '#prev' == $(this).attr('href') ? -1 : 1;
1701
1702 doPreview(ths, tagno);
1703
1704 });
1705
1706 },
1707 error: function( jqXHR, textStatus ) {
1708 // Handle an eval error
1709 if(jqXHR.responseText.indexOf('[[ERROR]]') !== -1) {
1710 vm.preiviewText = $('.wpallexport-preview-title').text();
1711
1712 var json = jqXHR.responseText.split('[[ERROR]]')[1];
1713 json = $.parseJSON(json);
1714 ths.pointer({'content' : '<div id="post-preview" class="wpallexport-preview">' +
1715 '<p class="wpallexport-preview-title">' + json.title + '</p>\
1716 <div class="wpallexport-preview-content">'+json.error+'</div></div></div>'});
1717
1718 $pointer.css({'position':'fixed', 'top' : '15%', 'left' : $leftOffset + 'px'});
1719
1720 } else {
1721 ths.pointer({'content' : '<div id="post-preview" class="wpallexport-preview">' +
1722 '<p class="wpallexport-preview-title">An error occured</p>\
1723 <div class="wpallexport-preview-content">An unknown error occured</div></div></div>'});
1724 $pointer.css({'position':'fixed', 'top' : '15%', 'left' : $leftOffset + 'px'});
1725 }
1726
1727 },
1728 dataType: "json"
1729 });
1730
1731 };
1732
1733 $(this).find('.preview_a_row').click( function(){
1734 doPreview($(this), 1);
1735 });
1736
1737 // preview custom XML template
1738 $(this).find('.preview_a_custom_xml_row').click(function(){
1739 doPreview($(this), 1);
1740 });
1741
1742 // help custom XML template
1743 $(this).find('.help_custom_xml').click(function(){
1744 $('.wp-all-export-custom-xml-help').css('left', ($( document ).width()/2) - 255 ).show();
1745 $('#wp-all-export-custom-xml-help-inner').css('max-height', $( window ).height()-150).show();
1746 $('.wpallexport-overlay').show();
1747 });
1748
1749 $('.wp_all_export_custom_xml_help').find('h3').click(function(){
1750 var $action = $(this).find('span').html();
1751 $('.wp_all_export_custom_xml_help').find('h3').each(function(){
1752 $(this).find('span').html("+");
1753 });
1754 if ( $action == "+" ) {
1755 $('.wp_all_export_help_tab').slideUp({queue:false});
1756 $('.wp_all_export_help_tab[rel=' + $(this).attr('id') + ']').slideDown({queue: false});
1757 $(this).find('span').html("-");
1758 }
1759 else{
1760 $('.wp_all_export_help_tab[rel=' + $(this).attr('id') + ']').slideUp({queue: false});
1761 $(this).find('span').html("+");
1762 }
1763 });
1764
1765 $('.wpae-available-fields-group').click(function(){
1766 var $mode = $(this).find('.wpae-expander').text();
1767 $(this).next('div').slideToggle();
1768 if ($mode == '+') $(this).find('.wpae-expander').text('-'); else $(this).find('.wpae-expander').text('+');
1769 });
1770
1771 $('.pmxe_remove_column').live('click', function(){
1772 $(this).parents('li:first').remove();
1773 });
1774
1775 $('.close_action').click(function(){
1776 $(this).parents('fieldset:first').hide();
1777 $('.wpallexport-overlay').hide();
1778 $('#columns').find('div.active').removeClass('active');
1779 });
1780
1781 $('.date_field_export_data').change(function(){
1782 if ($(this).val() == "unix")
1783 $('.pmxe_date_format_wrapper').hide();
1784 else
1785 $('.pmxe_date_format_wrapper').show();
1786 });
1787
1788 $('.xml-expander').live('click', function () {
1789 var method;
1790 if ('-' == $(this).text()) {
1791 $(this).text('+');
1792 method = 'addClass';
1793 } else {
1794 $(this).text('-');
1795 method = 'removeClass';
1796 }
1797 // for nested representation based on div
1798 $(this).parent().find('> .xml-content')[method]('collapsed');
1799 // for nested representation based on tr
1800 var $tr = $(this).parent().parent().filter('tr.xml-element').next()[method]('collapsed');
1801 });
1802
1803 $('.wp-all-export-edit-column').css('left', ($( document ).width()/2) - 432);
1804
1805 var wp_all_export_config = {
1806 '.wp-all-export-chosen-select' : {width:"50%"}
1807 };
1808
1809 for (var selector in wp_all_export_config) {
1810 $(selector).chosen(wp_all_export_config[selector]);
1811 $(selector).on('change', function(evt, params) {
1812 $('.cc_field').hide();
1813 var selected_value = $(selector).find('option:selected').attr('label');
1814 var ftype = $(selector).val();
1815
1816 switch (ftype){
1817 case 'post_modified':
1818 case 'date':
1819 $('.date_field_type').show();
1820 break;
1821 case 'sql':
1822 $('.sql_field_type').show();
1823 break;
1824 case 'content':
1825 $('.content_field_type').show();
1826 break;
1827 case 'woo':
1828 switch (selected_value){
1829 case 'item_data___upsell_ids':
1830 case 'item_data___crosssell_ids':
1831 case '_upsell_ids':
1832 case '_crosssell_ids':
1833 $addAnotherForm.find('.linked_field_type').show();
1834 break;
1835 }
1836 break;
1837 default:
1838 if ( $(selector).val().indexOf('image_') !== -1)
1839 {
1840 $('.image_field_type').show();
1841 }
1842 break;
1843 }
1844 });
1845 }
1846
1847 $('.wp-all-export-advanced-field-options').click(function(){
1848 if ($(this).find('span').html() == '+'){
1849 $(this).find('span').html('-');
1850 $('.wp-all-export-advanced-field-options-content').fadeIn('fast', function(){
1851 if ($('#coperate_php').is(':checked')) editor.setCursor(1);
1852 });
1853 }
1854 else{
1855 $(this).find('span').html('+');
1856 $('.wp-all-export-advanced-field-options-content').hide();
1857 }
1858 });
1859
1860 // Auto generate available data
1861 $('.wp_all_export_auto_generate_data').click(function(){
1862
1863 $('ol#columns').find('li:not(.placeholder)').fadeOut().remove();
1864 $('ol#columns').find('li.placeholder').fadeOut();
1865
1866
1867 if (vm.availableDataSelector.find('li.wp_all_export_auto_generate').length)
1868 {
1869 vm.availableDataSelector.find('li.wp_all_export_auto_generate, li.pmxe_cats').each(function(i, e){
1870 var $clone = $(this).clone();
1871 $clone.attr('rel', i);
1872 $( "<li></li>" ).html( $clone.html() ).appendTo( $( "#columns_to_export ol" ) );
1873 });
1874 }
1875 else
1876 {
1877 vm.availableDataSelector.find('div.custom_column').each(function(i, e){
1878 var $parent = $(this).parent('li');
1879 var $clone = $parent.clone();
1880 $clone.attr('rel', i);
1881
1882 if ( $clone.find('input[name^=cc_type]').val().indexOf('image_') !== -1 )
1883 {
1884 $clone.find('.wpallexport-xml-element').html('Image ' + $clone.find('input[name^=cc_name]').val());
1885 $clone.find('input[name^=cc_name]').val('Image ' + $clone.find('input[name^=cc_name]').val());
1886 }
1887
1888 if ( $clone.find('input[name^=cc_type]').val().indexOf('attachment_') !== -1 )
1889 {
1890 $clone.find('.wpallexport-xml-element').html('Attachment ' + $clone.find('input[name^=cc_name]').val());
1891 $clone.find('input[name^=cc_name]').val('Attachment ' + $clone.find('input[name^=cc_name]').val());
1892 }
1893
1894 $( "<li></li>" ).html( $clone.html() ).appendTo( $( "#columns_to_export ol" ) );
1895 });
1896 }
1897
1898 trigger_warnings();
1899
1900 });
1901
1902 $('.wp_all_export_clear_all_data').live('click', function(){
1903 $('ol#columns').find('li:not(.placeholder)').remove();
1904 $('ol#columns').find('li.placeholder').fadeIn();
1905 });
1906
1907 if ($('input[name^=selected_post_type]').length){
1908
1909 var postType = $('input[name^=selected_post_type]').val();
1910
1911 init_filtering_fields();
1912
1913 liveFiltering();
1914
1915 $('form.wpallexport-template').find('input[type=submit]').click(function(e){
1916 e.preventDefault();
1917
1918 $('#validationError').fadeOut();
1919 $('#validationError p').find('*').remove();
1920
1921 var submitButton = $(this);
1922
1923 if(!vm.isGoogleMerchantsExport) {
1924 // Validate the form by sending it to preview before submitting it
1925 var request = {
1926 action: 'wpae_preview',
1927 data: $('form.wpallexport-step-3').serialize(),
1928 custom_xml: xml_editor.getValue(),
1929 security: wp_all_export_security
1930 };
1931
1932
1933 $.ajax({
1934 type: 'POST',
1935 url: get_valid_ajaxurl(),
1936 data: request,
1937 success: function(response) {
1938
1939 // Look for errors
1940 var tempDom = $('<div>').append($.parseHTML(response.html));
1941 var errorMessage = $('.error', tempDom);
1942
1943 // If we have error messages
1944 if(errorMessage.length) {
1945 // Display the error messages
1946 errorMessage.each(function(){
1947 $('#validationError').find('p').append($(this));
1948 });
1949
1950 $('#validationError').fadeIn();
1951 $('html, body').animate({scrollTop: $("#validationError").offset().top - 50});
1952 } else {
1953 // Else submit the form
1954 $('.hierarhy-output').each(function(){
1955 var sortable = $('.wp_all_export_filtering_rules.ui-sortable');
1956 if (sortable.length){
1957 $(this).val(window.JSON.stringify(sortable.pmxe_nestedSortable('toArray', {startDepthCount: 0})));
1958 }
1959 });
1960 submitButton.parents('form:first').submit();
1961 }
1962 },
1963 error: function( jqXHR, textStatus ) {
1964 $('#validationError p').html('');
1965
1966 // Handle an eval error
1967 if(jqXHR.responseText.indexOf('[[ERROR]]') != -1) {
1968 var json = jqXHR.responseText.split('[[ERROR]]')[1];
1969 json = $.parseJSON(json);
1970
1971 $('#validationError').find('p').append(json.error);
1972 $('#validationError').fadeIn();
1973 $('html, body').animate({scrollTop: $("#validationError").offset().top - 50});
1974
1975 } else {
1976 // We don't know the error
1977 $('#validationError').find('p').html('An unknown error occured');
1978 $('#validationError').fadeIn();
1979 $('html, body').animate({scrollTop: $("#validationError").offset().top - 50});
1980 }
1981 },
1982 dataType: "json"
1983 });
1984 } else {
1985 submitButton.parents('form:first').submit();
1986 }
1987 });
1988 }
1989
1990 if ( $('input[name=export_to]').val() == 'csv' && $('#export_to_sheet').val() == 'xls' && $('#export_to_sheet').val() == 'xlsx'){
1991 $('.export_to_xls_upgrade_notice').show();
1992 $('.wpallexport-submit-template').attr('disabled', 'disabled');
1993 $('.wpallexport-submit-buttons').hide();
1994 }
1995 else{
1996 $('.export_to_xls_upgrade_notice').hide();
1997 $('.wpallexport-submit-template').removeAttr('disabled');
1998 $('.wpallexport-submit-buttons').show();
1999 }
2000
2001 $('.wpallexport-import-to-format').click(function(){
2002
2003 var isWooCommerceOrder = vm.isWoocommerceOrderExport();
2004
2005 $('.wpallexport-import-to-format').removeClass('selected');
2006 $(this).addClass('selected');
2007
2008 if ($(this).hasClass('wpallexport-csv-type'))
2009 {
2010 vm.isGoogleMerchantsExport = false;
2011 //resetDraggable();
2012 angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
2013 $('.wpallexport-custom-xml-template').slideUp();
2014 $('.wpallexport-simple-xml-template').slideDown();
2015 $('.wpallexport-csv-options').show();
2016 $('.wpallexport-xml-options').hide();
2017
2018 $('.wpallexport-csv-advanced-options').css('display', 'block');
2019 $('.wpallexport-xml-advanced-options').css('display', 'none');
2020
2021 $('input[name=export_to]').val('csv');
2022
2023 if ($('#export_to_sheet').val() !== 'csv') {
2024 if (isWooCommerceOrder || vm.isProductVariationsExport()) {
2025 $('.csv_delimiter').hide();
2026 $('.export_to_csv').show();
2027 } else {
2028 $('.export_to_csv').hide();
2029 }
2030 $('.wpallexport-submit-template').attr('disabled', 'disabled');
2031 $('.wpallexport-submit-buttons').hide();
2032 } else {
2033 /** isProductVariationsExport */
2034 if (isWooCommerceOrder) {
2035 $('.export_to_csv').show();
2036 } else {
2037 $('.export_to_csv').show();
2038 $('.csv_delimiter').show();
2039 }
2040 $('.wpallexport-submit-template').removeAttr('disabled');
2041 $('.wpallexport-submit-buttons').show();
2042 }
2043
2044 $('.custom_xml_upgrade_notice').hide();
2045 }
2046 else
2047 {
2048 $('.wpallexport-csv-options').hide();
2049 $('.wpallexport-xml-options').show();
2050 $('input[name=export_to]').val('xml');
2051 $('.xml_template_type').change();
2052
2053 $('.wpallexport-csv-advanced-options').css('display', 'none');
2054 $('.wpallexport-xml-advanced-options').css('display', 'block');
2055 var $xml_export_format = $('.xml_template_type').val();
2056 if ( $xml_export_format == 'custom' || $xml_export_format == 'XmlGoogleMerchants'){
2057 $('.wpallexport-submit-template').attr('disabled', 'disabled');
2058
2059 if ( $xml_export_format == 'custom') {
2060 $('.custom_xml_upgrade_notice.wpallexport-custom-xml-template').show();
2061 } else if ($xml_export_format == 'XmlGoogleMerchants') {
2062 $('.custom_xml_upgrade_notice.wpallexport-google-merchants-template').show();
2063 }
2064
2065 $('.wpallexport-submit-buttons').hide();
2066 }
2067 else{
2068 $('.wpallexport-submit-buttons').show();
2069 }
2070 }
2071 });
2072
2073 // template form: auto submit when `load template` list value is picked
2074 $(this).find('select[name="load_template"]').live('change', function () {
2075
2076 var template = $(this).find('option:selected').val();
2077 var exportMode = $('.xml_template_type').find('option:selected').val();
2078
2079 $(this).parents('form').trigger('submit', ['templateSelected']);
2080 return;
2081 if( exportMode == 'XmlGoogleMerchants') {
2082 angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('selectedTemplate', template);
2083 } else {
2084 $(this).parents('form').submit();
2085 }
2086 });
2087
2088 var height = $(window).height();
2089 vm.availableDataSelector.find('.wpallexport-xml').css({'max-height': height - 125});
2090
2091 // dismiss export template warnings
2092 $('.wp-all-export-warning').find('.notice-dismiss').click(function(){
2093
2094 var $parent = $(this).parent('.wp-all-export-warning');
2095
2096 $('#dismiss_warnings').val('1');
2097
2098 if ( typeof export_id == 'undefined') {
2099 $parent.slideUp();
2100 return true;
2101 }
2102
2103 var request = {
2104 action: 'dismiss_export_warnings',
2105 data: {
2106 export_id: export_id,
2107 warning: $parent.find('p:first').html()
2108 },
2109 security: wp_all_export_security
2110 };
2111
2112 $parent.slideUp();
2113
2114 $.ajax({
2115 type: 'POST',
2116 url: get_valid_ajaxurl(),
2117 data: request,
2118 success: function(response) {},
2119 dataType: "json"
2120 });
2121 });
2122
2123 });
2124 // [ \Step 2 ( export template ) ]
2125
2126
2127 // [ Step 3 ( export options ) ]
2128 if ( $('.wpallexport-export-options').length ){
2129
2130 if ($('input[name^=selected_post_type]').length){
2131
2132 var postType = $('input[name^=selected_post_type]').val();
2133
2134 init_filtering_fields();
2135 liveFiltering();
2136
2137 $(document).on('wpae-scheduling-options-form:submit', function(e){
2138
2139 $('.hierarhy-output').each(function(){
2140 var sortable = $('.wp_all_export_filtering_rules.ui-sortable');
2141 if (sortable.length){
2142 $(this).val(window.JSON.stringify(sortable.pmxe_nestedSortable('toArray', {startDepthCount: 0})));
2143 }
2144 });
2145
2146 $('#wpae-options-form').submit();
2147 });
2148 }
2149
2150 }
2151 $('#export_only_new_stuff').click(function(){
2152 $(this).attr('disabled','disabled');
2153 $('label[for=export_only_new_stuff]').addClass('loading');
2154 liveFiltering(null, function(){
2155 $('label[for=export_only_new_stuff]').removeClass('loading');
2156 $('#export_only_new_stuff').removeAttr('disabled');
2157 });
2158 });
2159 $('#export_only_modified_stuff').click(function(){
2160 $(this).attr('disabled','disabled');
2161 $('label[for=export_only_modified_stuff]').addClass('loading');
2162 liveFiltering(null, function(){
2163 $('label[for=export_only_modified_stuff]').removeClass('loading');
2164 $('#export_only_modified_stuff').removeAttr('disabled');
2165 });
2166 });
2167 // [ \Step 3 ( export options ) ]
2168
2169 $('#download-bundle').click(function(e){
2170
2171 var exportCpt = $('#export-cpt').val();
2172
2173 if(exportCpt == 'shop_order') {
2174
2175 $('#migrate-orders-notice').slideDown();
2176 e.preventDefault();
2177 e.stopImmediatePropagation();
2178 return false;
2179 }
2180 });
2181
2182 // [ Step 4 ( export completed ) ]
2183 $('.download_data').click(function(){
2184 window.location.href = $(this).attr('rel');
2185 });
2186 // [ \Step 4 ( export completed ) ]
2187
2188
2189 // [ Additional functionality ]
2190
2191 // Add new filtering rule
2192 $('#wp_all_export_add_rule').live('click', function(){
2193
2194 var $el = $('#wp_all_export_xml_element');
2195 var $rule = $('#wp_all_export_rule');
2196 var $val = $('#wp_all_export_value');
2197
2198 if ($el.val() == "" || $rule.val() == "") return;
2199
2200 var relunumber = $('.wp_all_export_filtering_rules').find('li').length + 1;
2201
2202 var html = '<li id="item_'+ relunumber +'" class="dragging"><div class="drag-element">';
2203 html += '<input type="hidden" value="'+ $el.val() +'" class="wp_all_export_xml_element" name="wp_all_export_xml_element['+relunumber+']"/>';
2204 html += '<input type="hidden" value="'+ $el.find('option:selected').html() +'" class="wp_all_export_xml_element_title" name="wp_all_export_xml_element_title['+relunumber+']"/>';
2205 html += '<input type="hidden" value="'+ $rule.val() +'" class="wp_all_export_rule" name="wp_all_export_rule['+relunumber+']"/>';
2206 html += '<input type="hidden" value="'+ $val.val() +'" class="wp_all_export_value" name="wp_all_export_value['+relunumber+']"/>';
2207 html += '<span class="rule_element">' + $el.find('option:selected').html() + '</span> <span class="rule_as_is">' + $rule.find('option:selected').html() + '</span> <span class="rule_condition_value">"' + $val.val() +'"</span>';
2208 html += '<span class="condition"> <label for="rule_and_'+relunumber+'">AND</label><input id="rule_and_'+relunumber+'" type="radio" value="and" name="rule['+relunumber+']" checked="checked" class="rule_condition"/><label for="rule_or_'+relunumber+'">OR</label><input id="rule_or_'+relunumber+'" type="radio" value="or" name="rule['+relunumber+']" class="rule_condition"/> </span>';
2209 html += '</div><a href="javascript:void(0);" class="icon-item remove-ico"></a></li>';
2210
2211 $('#wpallexport-filters, #wp_all_export_apply_filters').show();
2212 $('#no_options_notice').hide();
2213
2214 $('.wp_all_export_filtering_rules').append(html);
2215
2216 $('.wp_all_export_filtering_rules').find('.condition:hidden').each(function(){
2217 $(this).show();
2218 $(this).find('.rule_condition:first').attr('checked', 'checked');
2219 });
2220 $('.wp_all_export_filtering_rules').find('.condition').removeClass('last_condition');
2221 $('.wp_all_export_filtering_rules').find('.condition:last').addClass('last_condition');
2222
2223 $('.wp_all_export_product_matching_mode').show();
2224
2225 $el.prop('selectedIndex',0).trigger('chosen:updated');
2226 $rule.prop('selectedIndex',0).trigger('chosen:updated');
2227
2228 $val.val('');
2229 $('#wp_all_export_value').show();
2230
2231 $('#date_field_notice').hide();
2232
2233 liveFiltering();
2234
2235 });
2236
2237 // Re-count posts when clicking "OR" | "AND" clauses
2238 $('input[name^=rule]').live('click', function(){
2239 liveFiltering();
2240 });
2241 $('input.wpml_lang').live('click', function(){
2242 var inputName = $(this).attr('name');
2243 var value = $('input[name='+inputName +']:checked').val();
2244 var $thisInput = $('.wpml_lang[value='+value +']');
2245 $thisInput.prop('checked', 'checked');
2246
2247 $('#wpml_lang').val(value);
2248 liveFiltering();
2249 });
2250 // Re-count posts when changing product matching mode in filtering section
2251 $('select[name^=product_matching_mode]').live('change', function(){
2252 liveFiltering();
2253 });
2254 // Re-count posts when deleting a filtering rule
2255 $('.wp_all_export_filtering_rules').find('.remove-ico').live('click', function(){
2256 $(this).parents('li:first').remove();
2257 if ( ! $('.wp_all_export_filtering_rules').find('li').length)
2258 {
2259 $('#wp_all_export_apply_filters').hide();
2260 $('#no_options_notice').show();
2261 $('.wp_all_export_product_matching_mode').hide();
2262 }
2263 else
2264 {
2265 $('.wp_all_export_filtering_rules').find('li:last').find('.condition').addClass('last_condition');
2266 }
2267
2268 liveFiltering();
2269 });
2270 // hide "value" input when "Is Empty" or "Is Not Empty" rule is selected
2271 $('#wp_all_export_rule').change(function(){
2272 if ($(this).val() == 'is_empty' || $(this).val() == 'is_not_empty')
2273 $('#wp_all_export_value').hide();
2274 else
2275 $('#wp_all_export_value').show();
2276 });
2277
2278 // auot-generate zapier API key
2279 $('input[name=pmxe_generate_zapier_api_key]').click(function(e){
2280
2281 e.preventDefault();
2282
2283 event.preventDefault();
2284 event.stopImmediatePropagation();
2285 $(this).addClass('wpae-shake');
2286 setTimeout(function(){
2287 $('.generate-zapier-api-key').removeClass('wpae-shake');
2288 return false;
2289 },200);
2290
2291 $('.zapier-upgrade').slideDown();
2292
2293 });
2294
2295 $('.CodeMirror').click(function(e){
2296 e.preventDefault();
2297 $('.php-functions-upgrade').slideDown();
2298 });
2299
2300 $('.wp_all_export_save_functions').click(function(e){
2301 $('.wp_all_export_save_functions_container').addClass('wpae-shake');
2302 setTimeout(function(){
2303 $('.wp_all_export_save_functions_container').removeClass('wpae-shake');
2304 $('.php-functions-upgrade').slideDown();
2305 return false;
2306 },200);
2307 });
2308
2309 var $tmp_xml_template = '';
2310 var $xml_template_first_load = true;
2311
2312 $('.xml_template_type').change(function(e){
2313
2314 switch ($(this).find('option:selected').val()){
2315 case 'simple':
2316 $('.simple_xml_template_options').slideDown();
2317 $('.wpallexport-simple-xml-template').slideDown();
2318 $('.wpallexport-custom-xml-template').slideUp();
2319 $('.wpallexport-function-editor').slideUp();
2320
2321 $('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').show();
2322 $('.wpallexport-submit-template').removeAttr('disabled');
2323 $('.custom_xml_upgrade_notice').hide();
2324 $('.wpallexport-submit-buttons').show();
2325 if(angular.element(document.getElementById('googleMerchants')).injector()){
2326 resetDraggable();
2327 angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
2328 }
2329 vm.isGoogleMerchantsExport = false;
2330
2331 if(!angular.isUndefined(e.originalEvent)) {
2332 if ( ! $('.wpallexport-file-options').hasClass('closed')) $('.wpallexport-file-options').find('.wpallexport-collapsed-header').click();
2333 }
2334
2335 break;
2336 case 'custom':
2337 if(angular.element(document.getElementById('googleMerchants')).injector()){
2338 resetDraggable();
2339 angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
2340 }
2341 vm.isGoogleMerchantsExport = false;
2342 $('.custom_xml_upgrade_notice').hide();
2343 $('.wpallexport-submit-buttons').hide();
2344 $('.simple_xml_template_options').slideUp();
2345 $('.wpallexport-simple-xml-template').slideUp();
2346 $('.wpallexport-function-editor').slideDown();
2347
2348 // If the event was not triggered by the user
2349 if(!angular.isUndefined(e.originalEvent)) {
2350 if ( ! $('.wpallexport-file-options').hasClass('closed')) $('.wpallexport-file-options').find('.wpallexport-collapsed-header').click();
2351 }
2352
2353 $('.wpallexport-custom-xml-template').slideDown(400, function(){
2354 xml_editor.setCursor(1);
2355 });
2356 $('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').hide();
2357
2358 if ( $(this).find('option:selected').val() == 'XmlGoogleMerchants' ){
2359 if ( ! $xml_template_first_load ) {
2360 $tmp_xml_template = xml_editor.getValue();
2361 // Get all necessary data according to the spec
2362 var request = {
2363 action: 'get_xml_spec',
2364 security: wp_all_export_security,
2365 spec_class: $(this).find('option:selected').val()
2366 };
2367 xml_editor.setValue("Loading...");
2368 $.ajax({
2369 type: 'POST',
2370 url: get_valid_ajaxurl(),
2371 data: request,
2372 success: function (response) {
2373 if (response.result) {
2374 xml_editor.setValue(response.fields);
2375 }
2376 },
2377 error: function (jqXHR, textStatus) {
2378
2379 },
2380 dataType: "json"
2381 });
2382 }
2383 }
2384 else{
2385 if ( $tmp_xml_template != '' ){
2386 xml_editor.setValue($tmp_xml_template);
2387 $tmp_xml_template = '';
2388 }
2389 }
2390 $('.wpallexport-submit-template').attr('disabled', 'disabled');
2391 $('.wpallexport-custom-xml-template').show();
2392 break;
2393 case 'XmlGoogleMerchants':
2394 $('.wpallexport-submit-buttons').hide();
2395 $('.simple_xml_template_options').slideUp();
2396 $('.wpallexport-simple-xml-template').slideUp();
2397 $('.wpallexport-custom-xml-template').slideUp();
2398 if(!vm.isCSVExport()) {
2399 $('.wpallexport-google-merchants-template').slideUp();
2400 }
2401 $('.wpallexport-google-merchants-template').slideUp();
2402
2403 if ( ! $('.wpallexport-file-options').hasClass('closed')) {
2404 $('.wpallexport-file-options').find('.wpallexport-collapsed-header').click();
2405 }
2406
2407 $('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').show();
2408
2409 if(angular.element(document.getElementById('googleMerchants')).injector()){
2410 resetDraggable();
2411 angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsSelected', vm.isProductVariationsExport());
2412 }
2413 vm.isGoogleMerchantsExport = true;
2414 $('.wpallexport-submit-template').attr('disabled', 'disabled');
2415 $('.wpallexport-google-merchants-template').show();
2416 break;
2417 default:
2418 resetDraggable();
2419 angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
2420 vm.isGoogleMerchantsExport = false;
2421 $('.simple_xml_template_options').slideUp();
2422 $('.wpallexport-simple-xml-template').slideDown();
2423 $('.wpallexport-custom-xml-template').slideUp();
2424 $('.wpallexport-function-editor').slideDown();
2425
2426 $('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').show();
2427 $('.wpallexport-submit-template').removeAttr('disabled');
2428 $('.custom_xml_upgrade_notice').hide();
2429 break;
2430 }
2431 $xml_template_first_load = false;
2432 }).change();
2433
2434 $('.wpallexport-overlay').click(function(){
2435 $('.wp-pointer').hide();
2436 $('#columns').find('div.active').removeClass('active');
2437 $('fieldset.wp-all-export-edit-column').hide();
2438 $('fieldset.wp-all-export-custom-xml-help').hide();
2439 $('fieldset.wp-all-export-scheduling-help').hide();
2440
2441
2442 $(this).hide();
2443 });
2444
2445 if ($('.wpallexport-template').length)
2446 {
2447 setTimeout(function(){
2448 $('.wpallexport-template').slideDown();
2449 }, 1000);
2450 }
2451 // [ \Additional functionality ]
2452
2453 // Logic for radio boxes (CDATA settings)
2454 $('input[name=simple_custom_xml_cdata_logic]').change(function(){
2455 var value = $('input[name=simple_custom_xml_cdata_logic]:checked').val();
2456 $('#custom_custom_xml_cdata_logic_'+value).prop('checked', true);
2457 $('#custom_xml_cdata_logic').val(value);
2458 });
2459
2460
2461 $('input[name=custom_custom_xml_cdata_logic]').change(function(event) {
2462 event.stopImmediatePropagation();
2463 var value = $('input[name=custom_custom_xml_cdata_logic]:checked').val();
2464 $('#simple_custom_xml_cdata_logic_'+value).prop('checked', true);
2465 $('input[name=simple_custom_xml_cdata_logic]').trigger('change');
2466
2467 });
2468
2469 // Logic for show CDATA tags in preview
2470 $('.show_cdata_in_preview').change(function(){
2471 if($(this).is(':checked')) {
2472 $('#show_cdata_in_preview').val(1);
2473 $('.show_cdata_in_preview').prop('checked', true);
2474 } else {
2475 $('#show_cdata_in_preview').val(0);
2476 $('.show_cdata_in_preview').prop('checked', false);
2477 }
2478 });
2479
2480 // Logic to show CSV advanced options
2481 $('#export_to_sheet').change(function(e){
2482
2483 if ( $('input[name=export_to]').val() === 'xml' ) return;
2484
2485 var isWooCommerceOrder = vm.isWoocommerceOrderExport();
2486 var isVariationsExport = vm.isProductVariationsExport();
2487
2488 var value = $(this).val();
2489 if(value === 'xls' || value === 'xlsx') {
2490 if(isWooCommerceOrder || isVariationsExport) {
2491 $('.csv_delimiter').hide();
2492 } else {
2493 $('.export_to_csv').slideUp();
2494 }
2495 $('.export_to_xls_upgrade_notice').show();
2496 $('.wpallexport-submit-buttons').hide();
2497 $('.wpallexport-submit-template').attr('disabled', 'disabled');
2498 } else {
2499 if(isWooCommerceOrder || isVariationsExport) {
2500 $('.csv_delimiter').show();
2501 } else {
2502 $('.export_to_csv').slideDown();
2503 }
2504 $('.export_to_xls_upgrade_notice').hide();
2505 $('.wpallexport-submit-buttons').show();
2506 $('.wpallexport-submit-template').removeAttr('disabled');
2507 }
2508 });
2509
2510 $('#templateForm').submit(function(event){
2511
2512 var exportType = $('select.xml_template_type').val();
2513
2514 if(vm.isGoogleMerchantsExport || exportType == 'custom') {
2515 event.stopImmediatePropagation();
2516 return false;
2517 }
2518 });
2519
2520 $('select[name=column_value_type]').change(function(){
2521 var disabledFields = ['fees', 'notes', 'refunds', 'taxes', 'item_data', 'items'];
2522 var selectedField = $(this).find('option:selected').attr('options');
2523 var isShowWarning = false;
2524 for (var i = 0; i < disabledFields.length; i++) {
2525 if (disabledFields[i] == selectedField){
2526 isShowWarning = true;
2527 break;
2528 }
2529 };
2530 if (isShowWarning){
2531 $('.disabled_fields_upgrade_notice').show();
2532 $('.save_action').addClass('wp_all_export_disabled_button').attr('disabled', 'disabled');
2533 }
2534 else {
2535 $('.disabled_fields_upgrade_notice').hide();
2536 $('.save_action').removeClass('wp_all_export_disabled_button').removeAttr('disabled');
2537 }
2538
2539 });
2540
2541 var $el = $('#available_data');
2542 if($el) {
2543 if($el.offset()) {
2544
2545
2546 var originalOffset = $el.offset().top - 50;
2547 var elementWidth = $el.width();
2548
2549 $el.css('width', elementWidth);
2550
2551 $(window).scroll(function (e) {
2552
2553 var isPositionFixed = ($el.css('position') == 'fixed');
2554 if ($(this).scrollTop() > originalOffset && !isPositionFixed) {
2555 $('#available_data').css({'position': 'fixed', 'top': '50px'});
2556 }
2557 if ($(this).scrollTop() < originalOffset && isPositionFixed) {
2558 $('#available_data').css({'position': 'static', 'top': '50px'});
2559 }
2560 });
2561 }
2562 }
2563
2564
2565 window.openSchedulingDialog = function(itemId, element, preloaderSrc) {
2566 $('.wpallexport-overlay').show();
2567 $('.wpallexport-loader').show();
2568
2569 var $self = element;
2570 $.ajax({
2571 type: "POST",
2572 url: ajaxurl,
2573 context: element,
2574 data: {
2575 'action': 'scheduling_dialog_content',
2576 'id': itemId,
2577 'security' : wp_all_export_security
2578 },
2579 success: function (data) {
2580
2581 $('.wpallexport-loader').hide();
2582 $(this).pointer({
2583 content: '<div id="scheduling-popup">' + data + '</div>',
2584 position: {
2585 edge: 'right',
2586 align: 'center'
2587 },
2588 pointerWidth: 815,
2589 show: function (event, t) {
2590
2591 $('.timepicker').timepicker();
2592
2593 var $leftOffset = ($(window).width() - 715) / 2;
2594
2595 var $pointer = $('.wp-pointer').last();
2596 $pointer.css({'position': 'absolute', 'top': '50px', 'left': $leftOffset + 'px'});
2597
2598 $pointer.find('a.close').remove();
2599 $pointer.find('.wp-pointer-buttons').append('<button class="save-changes button button-primary button-hero wpallexport-large-button" style="float: right; background-image: none;">Save</button>');
2600 $pointer.find('.wp-pointer-buttons').append('<button class="close-pointer button button-primary button-hero wpallexport-large-button" style="float: right; background: #F1F1F1 none;text-shadow: 0 0 black; color: #777; margin-right: 10px;">Cancel</button>');
2601
2602 $(".close-pointer, .wpallexport-overlay").unbind('click').click(function () {
2603 $self.pointer('close');
2604 $self.pointer('destroy');
2605 });
2606
2607 if(!window.pmxeHasSchedulingSubscription) {
2608 $('.save-changes ').addClass('disabled');
2609 }
2610
2611 $(".save-changes").unbind('click').click(function () {
2612 if($(this).hasClass('disabled')) {
2613 return false;
2614 }
2615
2616 var formValid = pmxeValidateSchedulingForm();
2617
2618 if (formValid.isValid) {
2619
2620 var schedulingEnable = $('input[name="scheduling_enable"]:checked').val();
2621
2622 var formData = $('#scheduling-form').serializeArray();
2623 formData.push({name: 'security', value: wp_all_export_security});
2624 formData.push({name: 'action', value: 'save_scheduling'});
2625 formData.push({name: 'element_id', value: itemId});
2626 formData.push({name: 'scheduling_enable', value: schedulingEnable});
2627
2628 $('.close-pointer').hide();
2629 $('.save-changes').hide();
2630
2631 $('.wp-pointer-buttons').append('<img id="pmxe_button_preloader" style="float:right" src="' + preloaderSrc + '" /> ');
2632 $.ajax({
2633 type: "POST",
2634 url: ajaxurl,
2635 data: formData,
2636 dataType: "json",
2637 success: function (data) {
2638 $('#pmxe_button_preloader').remove();
2639 $('.close-pointer').show();
2640 $(".wpallexport-overlay").trigger('click');
2641 },
2642 error: function () {
2643 alert('There was a problem saving the schedule');
2644 $('#pmxe_button_preloader').remove();
2645 $('.close-pointer').show();
2646 $(".wpallexport-overlay").trigger('click');
2647 }
2648 });
2649
2650 } else {
2651 alert(formValid.message);
2652 }
2653 return false;
2654 });
2655 },
2656 close: function () {
2657 jQuery('.wpallexport-overlay').hide();
2658 }
2659 }).pointer('open');
2660 },
2661 error: function () {
2662 alert('There was a problem saving the schedule');
2663 $('#pmxe_button_preloader').remove();
2664 $('.close-pointer').show();
2665 $(".wpallexport-overlay").trigger('click');
2666 $('.wpallexport-loader').hide();
2667 }
2668 });
2669 };
2670
2671 window.pmxeValidateSchedulingForm = function () {
2672
2673 var schedulingEnabled = $('input[name="scheduling_enable"]:checked').val() == 1;
2674
2675 if (!schedulingEnabled) {
2676 return {
2677 isValid: true
2678 };
2679 }
2680
2681 var runOn = $('input[name="scheduling_run_on"]:checked').val();
2682
2683 // Validate weekdays
2684 if (runOn == 'weekly') {
2685 var weeklyDays = $('#weekly_days').val();
2686
2687 if (weeklyDays == '') {
2688 $('#weekly li').addClass('error');
2689 return {
2690 isValid: false,
2691 message: 'Please select at least a day on which the export should run'
2692 }
2693 }
2694 } else if (runOn == 'monthly') {
2695 var monthlyDays = $('#monthly_days').val();
2696
2697 if (monthlyDays == '') {
2698 $('#monthly li').addClass('error');
2699 return {
2700 isValid: false,
2701 message: 'Please select at least a day on which the export should run'
2702 }
2703 }
2704 }
2705
2706 // Validate times
2707 var timeValid = true;
2708 var timeMessage = 'Please select at least a time for the export to run';
2709 var timeInputs = $('.timepicker');
2710 var timesHasValues = false;
2711
2712 timeInputs.each(function (key, $elem) {
2713
2714 if($(this).val() !== ''){
2715 timesHasValues = true;
2716 }
2717
2718 if (!$(this).val().match(/^(0?[1-9]|1[012])(:[0-5]\d)[APap][mM]$/) && $(this).val() != '') {
2719 $(this).addClass('error');
2720 timeValid = false;
2721 } else {
2722 $(this).removeClass('error');
2723 }
2724 });
2725
2726 if(!timesHasValues) {
2727 timeValid = false;
2728 $('.timepicker').addClass('error');
2729 }
2730
2731 if (!timeValid) {
2732 return {
2733 isValid: false,
2734 message: timeMessage
2735 };
2736 }
2737
2738 return {
2739 isValid: true
2740 };
2741 };
2742
2743
2744
2745 });})(jQuery, window.EventService);
2746