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