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