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