';
html += '';
html += '';
html += '';
html += '';
html += '' + $el.find('option:selected').html() + '' + $rule.find('option:selected').html() + '"' + $val.val() +'"';
html += '';
html += '
';
$('#wpallexport-filters, #wp_all_export_apply_filters').show();
$('#no_options_notice').hide();
$('.wp_all_export_filtering_rules').append(html);
$('.wp_all_export_filtering_rules').find('.condition:hidden').each(function(){
$(this).show();
$(this).find('.rule_condition:first').attr('checked', 'checked');
});
$('.wp_all_export_filtering_rules').find('.condition').removeClass('last_condition');
$('.wp_all_export_filtering_rules').find('.condition:last').addClass('last_condition');
$('.wp_all_export_product_matching_mode').show();
$el.prop('selectedIndex',0).trigger('chosen:updated');
$rule.prop('selectedIndex',0).trigger('chosen:updated');
$val.val('');
$('#wp_all_export_value').show();
$('#date_field_notice').hide();
liveFiltering();
});
// Re-count posts when clicking "OR" | "AND" clauses
$('input[name^=rule]').live('click', function(){
liveFiltering();
});
$('input.wpml_lang').live('click', function(){
var inputName = $(this).attr('name');
var value = $('input[name='+inputName +']:checked').val();
var $thisInput = $('.wpml_lang[value='+value +']');
$thisInput.prop('checked', 'checked');
$('#wpml_lang').val(value);
liveFiltering();
});
// Re-count posts when changing product matching mode in filtering section
$('select[name^=product_matching_mode]').live('change', function(){
liveFiltering();
});
// Re-count posts when deleting a filtering rule
$('.wp_all_export_filtering_rules').find('.remove-ico').live('click', function(){
$(this).parents('li:first').remove();
if ( ! $('.wp_all_export_filtering_rules').find('li').length)
{
$('#wp_all_export_apply_filters').hide();
$('#no_options_notice').show();
$('.wp_all_export_product_matching_mode').hide();
}
else
{
$('.wp_all_export_filtering_rules').find('li:last').find('.condition').addClass('last_condition');
}
liveFiltering();
});
// hide "value" input when "Is Empty" or "Is Not Empty" rule is selected
$('#wp_all_export_rule').change(function(){
if ($(this).val() == 'is_empty' || $(this).val() == 'is_not_empty')
$('#wp_all_export_value').hide();
else
$('#wp_all_export_value').show();
});
// auot-generate zapier API key
$('input[name=pmxe_generate_zapier_api_key]').click(function(e){
e.preventDefault();
event.preventDefault();
event.stopImmediatePropagation();
$(this).addClass('wpae-shake');
setTimeout(function(){
$('.generate-zapier-api-key').removeClass('wpae-shake');
return false;
},200);
$('.zapier-upgrade').slideDown();
});
$('.CodeMirror').click(function(e){
e.preventDefault();
$('.php-functions-upgrade').slideDown();
});
$('.wp_all_export_save_functions').click(function(e){
$('.wp_all_export_save_functions_container').addClass('wpae-shake');
setTimeout(function(){
$('.wp_all_export_save_functions_container').removeClass('wpae-shake');
$('.php-functions-upgrade').slideDown();
return false;
},200);
});
var $tmp_xml_template = '';
var $xml_template_first_load = true;
$('.xml_template_type').change(function(e){
switch ($(this).find('option:selected').val()){
case 'simple':
$('.simple_xml_template_options').slideDown();
$('.wpallexport-simple-xml-template').slideDown();
$('.wpallexport-custom-xml-template').slideUp();
$('.wpallexport-function-editor').slideUp();
$('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').show();
$('.wpallexport-submit-template').removeAttr('disabled');
$('.custom_xml_upgrade_notice').hide();
$('.wpallexport-submit-buttons').show();
if(angular.element(document.getElementById('googleMerchants')).injector()){
resetDraggable();
angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
}
vm.isGoogleMerchantsExport = false;
if(!angular.isUndefined(e.originalEvent)) {
if ( ! $('.wpallexport-file-options').hasClass('closed')) $('.wpallexport-file-options').find('.wpallexport-collapsed-header').click();
}
break;
case 'custom':
if(angular.element(document.getElementById('googleMerchants')).injector()){
resetDraggable();
angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
}
vm.isGoogleMerchantsExport = false;
$('.custom_xml_upgrade_notice').hide();
$('.wpallexport-submit-buttons').hide();
$('.simple_xml_template_options').slideUp();
$('.wpallexport-simple-xml-template').slideUp();
$('.wpallexport-function-editor').slideDown();
// If the event was not triggered by the user
if(!angular.isUndefined(e.originalEvent)) {
if ( ! $('.wpallexport-file-options').hasClass('closed')) $('.wpallexport-file-options').find('.wpallexport-collapsed-header').click();
}
$('.wpallexport-custom-xml-template').slideDown(400, function(){
xml_editor.setCursor(1);
});
$('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').hide();
if ( $(this).find('option:selected').val() == 'XmlGoogleMerchants' ){
if ( ! $xml_template_first_load ) {
$tmp_xml_template = xml_editor.getValue();
// Get all necessary data according to the spec
var request = {
action: 'get_xml_spec',
security: wp_all_export_security,
spec_class: $(this).find('option:selected').val()
};
xml_editor.setValue("Loading...");
$.ajax({
type: 'POST',
url: get_valid_ajaxurl(),
data: request,
success: function (response) {
if (response.result) {
xml_editor.setValue(response.fields);
}
},
error: function (jqXHR, textStatus) {
},
dataType: "json"
});
}
}
else{
if ( $tmp_xml_template != '' ){
xml_editor.setValue($tmp_xml_template);
$tmp_xml_template = '';
}
}
$('.wpallexport-submit-template').attr('disabled', 'disabled');
$('.wpallexport-custom-xml-template').show();
break;
case 'XmlGoogleMerchants':
$('.wpallexport-submit-buttons').hide();
$('.simple_xml_template_options').slideUp();
$('.wpallexport-simple-xml-template').slideUp();
$('.wpallexport-custom-xml-template').slideUp();
if(!vm.isCSVExport()) {
$('.wpallexport-google-merchants-template').slideUp();
}
$('.wpallexport-google-merchants-template').slideUp();
if ( ! $('.wpallexport-file-options').hasClass('closed')) {
$('.wpallexport-file-options').find('.wpallexport-collapsed-header').click();
}
$('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').show();
if(angular.element(document.getElementById('googleMerchants')).injector()){
resetDraggable();
angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsSelected', vm.isProductVariationsExport());
}
vm.isGoogleMerchantsExport = true;
$('.wpallexport-submit-template').attr('disabled', 'disabled');
$('.wpallexport-google-merchants-template').show();
break;
default:
resetDraggable();
angular.element(document.getElementById('googleMerchants')).injector().get('$rootScope').$broadcast('googleMerchantsDeselected');
vm.isGoogleMerchantsExport = false;
$('.simple_xml_template_options').slideUp();
$('.wpallexport-simple-xml-template').slideDown();
$('.wpallexport-custom-xml-template').slideUp();
$('.wpallexport-function-editor').slideDown();
$('.pmxe_product_data').find(".wpallexport-xml-element:contains('Attributes')").parents('li:first').show();
$('.wpallexport-submit-template').removeAttr('disabled');
$('.custom_xml_upgrade_notice').hide();
break;
}
$xml_template_first_load = false;
}).change();
$('.wpallexport-overlay').click(function(){
$('.wp-pointer').hide();
$('#columns').find('div.active').removeClass('active');
$('fieldset.wp-all-export-edit-column').hide();
$('fieldset.wp-all-export-custom-xml-help').hide();
$('fieldset.wp-all-export-scheduling-help').hide();
$(this).hide();
});
if ($('.wpallexport-template').length)
{
setTimeout(function(){
$('.wpallexport-template').slideDown();
}, 1000);
}
// [ \Additional functionality ]
// Logic for radio boxes (CDATA settings)
$('input[name=simple_custom_xml_cdata_logic]').change(function(){
var value = $('input[name=simple_custom_xml_cdata_logic]:checked').val();
$('#custom_custom_xml_cdata_logic_'+value).prop('checked', true);
$('#custom_xml_cdata_logic').val(value);
});
$('input[name=custom_custom_xml_cdata_logic]').change(function(event) {
event.stopImmediatePropagation();
var value = $('input[name=custom_custom_xml_cdata_logic]:checked').val();
$('#simple_custom_xml_cdata_logic_'+value).prop('checked', true);
$('input[name=simple_custom_xml_cdata_logic]').trigger('change');
});
// Logic for show CDATA tags in preview
$('.show_cdata_in_preview').change(function(){
if($(this).is(':checked')) {
$('#show_cdata_in_preview').val(1);
$('.show_cdata_in_preview').prop('checked', true);
} else {
$('#show_cdata_in_preview').val(0);
$('.show_cdata_in_preview').prop('checked', false);
}
});
// Logic to show CSV advanced options
$('#export_to_sheet').change(function(e){
if ( $('input[name=export_to]').val() === 'xml' ) return;
var isWooCommerceOrder = vm.isWoocommerceOrderExport();
var isVariationsExport = vm.isProductVariationsExport();
var value = $(this).val();
if(value === 'xls' || value === 'xlsx') {
if(isWooCommerceOrder || isVariationsExport) {
$('.csv_delimiter').hide();
} else {
$('.export_to_csv').slideUp();
}
$('.export_to_xls_upgrade_notice').show();
$('.wpallexport-submit-buttons').hide();
$('.wpallexport-submit-template').attr('disabled', 'disabled');
} else {
if(isWooCommerceOrder || isVariationsExport) {
$('.csv_delimiter').show();
} else {
$('.export_to_csv').slideDown();
}
$('.export_to_xls_upgrade_notice').hide();
$('.wpallexport-submit-buttons').show();
$('.wpallexport-submit-template').removeAttr('disabled');
}
});
$('#templateForm').submit(function(event){
var exportType = $('select.xml_template_type').val();
if(vm.isGoogleMerchantsExport || exportType == 'custom') {
event.stopImmediatePropagation();
return false;
}
});
$('select[name=column_value_type]').change(function(){
var disabledFields = ['fees', 'notes', 'refunds', 'taxes', 'item_data', 'items'];
var selectedField = $(this).find('option:selected').attr('options');
var isShowWarning = false;
for (var i = 0; i < disabledFields.length; i++) {
if (disabledFields[i] == selectedField){
isShowWarning = true;
break;
}
};
if (isShowWarning){
$('.disabled_fields_upgrade_notice').show();
$('.save_action').addClass('wp_all_export_disabled_button').attr('disabled', 'disabled');
}
else {
$('.disabled_fields_upgrade_notice').hide();
$('.save_action').removeClass('wp_all_export_disabled_button').removeAttr('disabled');
}
});
var $el = $('#available_data');
if($el) {
if($el.offset()) {
var originalOffset = $el.offset().top - 50;
var elementWidth = $el.width();
$el.css('width', elementWidth);
$(window).scroll(function (e) {
var isPositionFixed = ($el.css('position') == 'fixed');
if ($(this).scrollTop() > originalOffset && !isPositionFixed) {
$('#available_data').css({'position': 'fixed', 'top': '50px'});
}
if ($(this).scrollTop() < originalOffset && isPositionFixed) {
$('#available_data').css({'position': 'static', 'top': '50px'});
}
});
}
}
window.openSchedulingDialog = function(itemId, element, preloaderSrc) {
$('.wpallexport-overlay').show();
$('.wpallexport-loader').show();
var $self = element;
$.ajax({
type: "POST",
url: ajaxurl,
context: element,
data: {
'action': 'scheduling_dialog_content',
'id': itemId,
'security' : wp_all_export_security
},
success: function (data) {
$('.wpallexport-loader').hide();
$(this).pointer({
content: '
' + data + '
',
position: {
edge: 'right',
align: 'center'
},
pointerWidth: 815,
show: function (event, t) {
$('.timepicker').timepicker();
var $leftOffset = ($(window).width() - 715) / 2;
var $pointer = $('.wp-pointer').last();
$pointer.css({'position': 'absolute', 'top': '50px', 'left': $leftOffset + 'px'});
$pointer.find('a.close').remove();
$pointer.find('.wp-pointer-buttons').append('');
$pointer.find('.wp-pointer-buttons').append('');
$(".close-pointer, .wpallexport-overlay").unbind('click').click(function () {
$self.pointer('close');
$self.pointer('destroy');
});
if(!window.pmxeHasSchedulingSubscription) {
$('.save-changes ').addClass('disabled');
}
$(".save-changes").unbind('click').click(function () {
if($(this).hasClass('disabled')) {
return false;
}
var formValid = pmxeValidateSchedulingForm();
if (formValid.isValid) {
var schedulingEnable = $('input[name="scheduling_enable"]:checked').val();
var formData = $('#scheduling-form').serializeArray();
formData.push({name: 'security', value: wp_all_export_security});
formData.push({name: 'action', value: 'save_scheduling'});
formData.push({name: 'element_id', value: itemId});
formData.push({name: 'scheduling_enable', value: schedulingEnable});
$('.close-pointer').hide();
$('.save-changes').hide();
$('.wp-pointer-buttons').append(' ');
$.ajax({
type: "POST",
url: ajaxurl,
data: formData,
dataType: "json",
success: function (data) {
$('#pmxe_button_preloader').remove();
$('.close-pointer').show();
$(".wpallexport-overlay").trigger('click');
},
error: function () {
alert('There was a problem saving the schedule');
$('#pmxe_button_preloader').remove();
$('.close-pointer').show();
$(".wpallexport-overlay").trigger('click');
}
});
} else {
alert(formValid.message);
}
return false;
});
},
close: function () {
jQuery('.wpallexport-overlay').hide();
}
}).pointer('open');
},
error: function () {
alert('There was a problem saving the schedule');
$('#pmxe_button_preloader').remove();
$('.close-pointer').show();
$(".wpallexport-overlay").trigger('click');
$('.wpallexport-loader').hide();
}
});
};
window.pmxeValidateSchedulingForm = function () {
var schedulingEnabled = $('input[name="scheduling_enable"]:checked').val() == 1;
if (!schedulingEnabled) {
return {
isValid: true
};
}
var runOn = $('input[name="scheduling_run_on"]:checked').val();
// Validate weekdays
if (runOn == 'weekly') {
var weeklyDays = $('#weekly_days').val();
if (weeklyDays == '') {
$('#weekly li').addClass('error');
return {
isValid: false,
message: 'Please select at least a day on which the export should run'
}
}
} else if (runOn == 'monthly') {
var monthlyDays = $('#monthly_days').val();
if (monthlyDays == '') {
$('#monthly li').addClass('error');
return {
isValid: false,
message: 'Please select at least a day on which the export should run'
}
}
}
// Validate times
var timeValid = true;
var timeMessage = 'Please select at least a time for the export to run';
var timeInputs = $('.timepicker');
var timesHasValues = false;
timeInputs.each(function (key, $elem) {
if($(this).val() !== ''){
timesHasValues = true;
}
if (!$(this).val().match(/^(0?[1-9]|1[012])(:[0-5]\d)[APap][mM]$/) && $(this).val() != '') {
$(this).addClass('error');
timeValid = false;
} else {
$(this).removeClass('error');
}
});
if(!timesHasValues) {
timeValid = false;
$('.timepicker').addClass('error');
}
if (!timeValid) {
return {
isValid: false,
message: timeMessage
};
}
return {
isValid: true
};
};
});})(jQuery, window.EventService);