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