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