Fix no-use-before-define eslint rule in ES5 files
[MAILPOET-1144]
This commit is contained in:
@ -41,7 +41,6 @@
|
||||
"no-throw-literal": 0,
|
||||
"no-extra-bind": 0,
|
||||
"brace-style": 0,
|
||||
"no-use-before-define": 0,
|
||||
"camelcase": 0,
|
||||
"padded-blocks": 0,
|
||||
"strict": 0,
|
||||
|
@ -11,6 +11,27 @@ var Observable;
|
||||
var WysijaHistory;
|
||||
var WysijaForm;
|
||||
|
||||
/* LOGGING */
|
||||
function info(value) {
|
||||
if (WysijaForm.options.debug === false) return;
|
||||
|
||||
if (!(window.console && console.log)) {
|
||||
(function () {
|
||||
var noop = function () {};
|
||||
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'markTimeline', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
|
||||
var length = methods.length;
|
||||
var console = {};
|
||||
window.console = {};
|
||||
while (length--) {
|
||||
console[methods[length]] = noop;
|
||||
}
|
||||
}());
|
||||
}
|
||||
try {
|
||||
console.log('[DEBUG] ' + value);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
Event.cacheDelegated = {};
|
||||
Object.extend(document, (function () {
|
||||
var cache = Event.cacheDelegated;
|
||||
@ -96,6 +117,12 @@ Observable = (function () {
|
||||
return name.underscore().split('_').join(':');
|
||||
}
|
||||
|
||||
function getWrapper(handler, klass) {
|
||||
return function (event) {
|
||||
return handler.call(new klass(this), event, event.memo);
|
||||
};
|
||||
}
|
||||
|
||||
function getHandlers(klass) {
|
||||
var proto = klass.prototype;
|
||||
var namespace = proto.namespace;
|
||||
@ -106,12 +133,6 @@ Observable = (function () {
|
||||
});
|
||||
}
|
||||
|
||||
function getWrapper(handler, klass) {
|
||||
return function (event) {
|
||||
return handler.call(new klass(this), event, event.memo);
|
||||
};
|
||||
}
|
||||
|
||||
function onDomLoad(selector, klass) {
|
||||
window.$$(selector).each(function (element) {
|
||||
new klass(element).onDomLoaded();
|
||||
@ -1074,25 +1095,4 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
|
||||
/* When dom is loaded, initialize WysijaForm */
|
||||
document.observe('dom:loaded', WysijaForm.init);
|
||||
|
||||
/* LOGGING */
|
||||
function info(value) {
|
||||
if (WysijaForm.options.debug === false) return;
|
||||
|
||||
if (!(window.console && console.log)) {
|
||||
(function () {
|
||||
var noop = function () {};
|
||||
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'markTimeline', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
|
||||
var length = methods.length;
|
||||
var console = {};
|
||||
window.console = {};
|
||||
while (length--) {
|
||||
console[methods[length]] = noop;
|
||||
}
|
||||
}());
|
||||
}
|
||||
try {
|
||||
console.log('[DEBUG] ' + value);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
module.exports = WysijaForm;
|
||||
|
@ -196,13 +196,6 @@ define([
|
||||
var $toggleButton = this.$('> .mailpoet_tools .mailpoet_newsletter_layer_selector');
|
||||
var $overlay = jQuery('.mailpoet_layer_overlay');
|
||||
var $container = this.$('> .mailpoet_container');
|
||||
var enableContainerLayer = function () {
|
||||
that.$el.addClass('mailpoet_container_layer_active');
|
||||
$toggleButton.addClass('mailpoet_container_layer_active');
|
||||
$container.addClass('mailpoet_layer_highlight');
|
||||
$overlay.click(disableContainerLayer);
|
||||
$overlay.show();
|
||||
};
|
||||
var disableContainerLayer = function () {
|
||||
that.$el.removeClass('mailpoet_container_layer_active');
|
||||
$toggleButton.removeClass('mailpoet_container_layer_active');
|
||||
@ -210,6 +203,13 @@ define([
|
||||
$overlay.hide();
|
||||
$overlay.off('click');
|
||||
};
|
||||
var enableContainerLayer = function () {
|
||||
that.$el.addClass('mailpoet_container_layer_active');
|
||||
$toggleButton.addClass('mailpoet_container_layer_active');
|
||||
$container.addClass('mailpoet_layer_highlight');
|
||||
$overlay.click(disableContainerLayer);
|
||||
$overlay.show();
|
||||
};
|
||||
if ($toggleButton.hasClass('mailpoet_container_layer_active')) {
|
||||
disableContainerLayer();
|
||||
} else {
|
||||
|
@ -31,6 +31,16 @@ define(
|
||||
// render template
|
||||
jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(window.exportData));
|
||||
|
||||
function toggleNextStepButton(condition) {
|
||||
var disabled = 'button-disabled';
|
||||
if (condition === 'on') {
|
||||
nextStepButton.removeClass(disabled);
|
||||
}
|
||||
else {
|
||||
nextStepButton.addClass(disabled);
|
||||
}
|
||||
}
|
||||
|
||||
// define reusable variables
|
||||
segmentsContainerElement = jQuery('#export_lists');
|
||||
subscriberFieldsContainerElement = jQuery('#export_columns');
|
||||
@ -128,16 +138,6 @@ define(
|
||||
segmentsContainerElement.val(selectedSegments).trigger('change');
|
||||
});
|
||||
|
||||
function toggleNextStepButton(condition) {
|
||||
var disabled = 'button-disabled';
|
||||
if (condition === 'on') {
|
||||
nextStepButton.removeClass(disabled);
|
||||
}
|
||||
else {
|
||||
nextStepButton.addClass(disabled);
|
||||
}
|
||||
}
|
||||
|
||||
nextStepButton.click(function () {
|
||||
var exportFormat;
|
||||
if (jQuery(this).hasClass('button-disabled')) {
|
||||
|
@ -117,182 +117,6 @@ define(
|
||||
// start step 1
|
||||
showCurrentStep();
|
||||
|
||||
/*
|
||||
* Paste
|
||||
*/
|
||||
pasteInputElement
|
||||
.attr('value', pasteInputPlaceholderElement).css('color', '#999')
|
||||
.focus(function () {
|
||||
if (jQuery(this).val() === pasteInputPlaceholderElement) {
|
||||
jQuery(this).attr('value', '').css('color', '#222');
|
||||
}
|
||||
})
|
||||
.blur(function () {
|
||||
if (jQuery(this).val() === '') {
|
||||
jQuery(this).attr('value', pasteInputPlaceholderElement).css('color', '#999');
|
||||
}
|
||||
})
|
||||
.keyup(function () {
|
||||
toggleNextStepButton(
|
||||
pasteProcessButtonElement,
|
||||
(this.value.trim() !== '') ? 'on' : 'off'
|
||||
);
|
||||
});
|
||||
|
||||
pasteProcessButtonElement.click(function () {
|
||||
var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1;
|
||||
MailPoet.Notice.hide();
|
||||
// get an approximate size of textarea paste in bytes
|
||||
if (pasteSize > window.maxPostSizeBytes) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('maxPostSizeNotice'));
|
||||
return;
|
||||
}
|
||||
// delay loading indicator for 10ms or else it's just too fast :)
|
||||
MailPoet.Modal.loading(true);
|
||||
setTimeout(function () {
|
||||
Papa.parse(pasteInputElement.val(), parseCSV(false));
|
||||
}, 10);
|
||||
});
|
||||
|
||||
/*
|
||||
* CSV file
|
||||
*/
|
||||
uploadElement.change(function () {
|
||||
var ext = this.value.match(/\.(.+)$/);
|
||||
MailPoet.Notice.hide();
|
||||
if (ext === null || ext[1].toLowerCase() !== 'csv') {
|
||||
this.value = '';
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
|
||||
}
|
||||
|
||||
toggleNextStepButton(
|
||||
uploadProcessButtonElement,
|
||||
(this.value.trim() !== '') ? 'on' : 'off'
|
||||
);
|
||||
});
|
||||
|
||||
uploadProcessButtonElement.click(function () {
|
||||
if (uploadElement.val().trim() !== '') {
|
||||
// delay loading indicator for 10ms or else it's just too fast :)
|
||||
MailPoet.Modal.loading(true);
|
||||
setTimeout(function () {
|
||||
uploadElement.parse({
|
||||
config: parseCSV(true)
|
||||
});
|
||||
}, 10);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* MailChimp
|
||||
*/
|
||||
mailChimpKeyInputElement.keyup(function () {
|
||||
if (this.value.trim() === ''
|
||||
|| !/[a-zA-Z0-9]{32}-/.exec(this.value.trim())) {
|
||||
mailChimpListsContainerElement.hide();
|
||||
jQuery('.mailpoet_mailchimp-key-status')
|
||||
.html('')
|
||||
.removeClass('mailpoet_mailchimp-ok mailpoet_mailchimp-error');
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||
}
|
||||
});
|
||||
|
||||
mailChimpKeyVerifyButtonElement.click(function () {
|
||||
MailPoet.Modal.loading(true);
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'importExport',
|
||||
action: 'getMailChimpLists',
|
||||
data: {
|
||||
api_key: mailChimpKeyInputElement.val()
|
||||
}
|
||||
}).always(function () {
|
||||
MailPoet.Modal.loading(false);
|
||||
}).done(function (response) {
|
||||
jQuery('.mailpoet_mailchimp-key-status')
|
||||
.html('')
|
||||
.removeClass()
|
||||
.addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-ok');
|
||||
if (response.data.length === 0) {
|
||||
jQuery('.mailpoet_mailchimp-key-status').html(MailPoet.I18n.t('noMailChimpLists'));
|
||||
mailChimpListsContainerElement.hide();
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||
} else {
|
||||
displayMailChimpLists(response.data);
|
||||
}
|
||||
}).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
mailChimpProcessButtonElement.click(function () {
|
||||
if (mailChimpProcessButtonElement.closest('table a').hasClass('button-disabled')) {
|
||||
return;
|
||||
}
|
||||
MailPoet.Modal.loading(true);
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'importExport',
|
||||
action: 'getMailChimpSubscribers',
|
||||
data: {
|
||||
api_key: mailChimpKeyInputElement.val(),
|
||||
lists: mailChimpListsContainerElement.find('select').val()
|
||||
}
|
||||
}).always(function () {
|
||||
MailPoet.Modal.loading(false);
|
||||
}).done(function (response) {
|
||||
window.importData.step1 = response.data;
|
||||
MailPoet.trackEvent('Subscribers import started', {
|
||||
source: 'MailChimp',
|
||||
'MailPoet Free version': window.mailpoet_version
|
||||
});
|
||||
router.navigate('step2', { trigger: true });
|
||||
}).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function displayMailChimpLists(data) {
|
||||
var listSelectElement = mailChimpListsContainerElement.find('select');
|
||||
if (listSelectElement.data('select2')) {
|
||||
listSelectElement.select2('data', data);
|
||||
listSelectElement.trigger('change');
|
||||
}
|
||||
else {
|
||||
listSelectElement
|
||||
.select2({
|
||||
data: data,
|
||||
width: '20em',
|
||||
templateResult: function (item) {
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
return item.name;
|
||||
}
|
||||
})
|
||||
.change(function () {
|
||||
if (jQuery(this).val() !== null) {
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'on');
|
||||
}
|
||||
else {
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||
}
|
||||
})
|
||||
.trigger('change');
|
||||
}
|
||||
mailChimpListsContainerElement.show();
|
||||
}
|
||||
|
||||
function toggleNextStepButton(element, condition) {
|
||||
var disabled = 'button-disabled';
|
||||
if (condition === 'on') {
|
||||
@ -451,6 +275,183 @@ define(
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function displayMailChimpLists(data) {
|
||||
var listSelectElement = mailChimpListsContainerElement.find('select');
|
||||
if (listSelectElement.data('select2')) {
|
||||
listSelectElement.select2('data', data);
|
||||
listSelectElement.trigger('change');
|
||||
}
|
||||
else {
|
||||
listSelectElement
|
||||
.select2({
|
||||
data: data,
|
||||
width: '20em',
|
||||
templateResult: function (item) {
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
return item.name;
|
||||
}
|
||||
})
|
||||
.change(function () {
|
||||
if (jQuery(this).val() !== null) {
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'on');
|
||||
}
|
||||
else {
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||
}
|
||||
})
|
||||
.trigger('change');
|
||||
}
|
||||
mailChimpListsContainerElement.show();
|
||||
}
|
||||
|
||||
/*
|
||||
* Paste
|
||||
*/
|
||||
pasteInputElement
|
||||
.attr('value', pasteInputPlaceholderElement).css('color', '#999')
|
||||
.focus(function () {
|
||||
if (jQuery(this).val() === pasteInputPlaceholderElement) {
|
||||
jQuery(this).attr('value', '').css('color', '#222');
|
||||
}
|
||||
})
|
||||
.blur(function () {
|
||||
if (jQuery(this).val() === '') {
|
||||
jQuery(this).attr('value', pasteInputPlaceholderElement).css('color', '#999');
|
||||
}
|
||||
})
|
||||
.keyup(function () {
|
||||
toggleNextStepButton(
|
||||
pasteProcessButtonElement,
|
||||
(this.value.trim() !== '') ? 'on' : 'off'
|
||||
);
|
||||
});
|
||||
|
||||
pasteProcessButtonElement.click(function () {
|
||||
var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1;
|
||||
MailPoet.Notice.hide();
|
||||
// get an approximate size of textarea paste in bytes
|
||||
if (pasteSize > window.maxPostSizeBytes) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('maxPostSizeNotice'));
|
||||
return;
|
||||
}
|
||||
// delay loading indicator for 10ms or else it's just too fast :)
|
||||
MailPoet.Modal.loading(true);
|
||||
setTimeout(function () {
|
||||
Papa.parse(pasteInputElement.val(), parseCSV(false));
|
||||
}, 10);
|
||||
});
|
||||
|
||||
/*
|
||||
* CSV file
|
||||
*/
|
||||
uploadElement.change(function () {
|
||||
var ext = this.value.match(/\.(.+)$/);
|
||||
MailPoet.Notice.hide();
|
||||
if (ext === null || ext[1].toLowerCase() !== 'csv') {
|
||||
this.value = '';
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
|
||||
}
|
||||
|
||||
toggleNextStepButton(
|
||||
uploadProcessButtonElement,
|
||||
(this.value.trim() !== '') ? 'on' : 'off'
|
||||
);
|
||||
});
|
||||
|
||||
uploadProcessButtonElement.click(function () {
|
||||
if (uploadElement.val().trim() !== '') {
|
||||
// delay loading indicator for 10ms or else it's just too fast :)
|
||||
MailPoet.Modal.loading(true);
|
||||
setTimeout(function () {
|
||||
uploadElement.parse({
|
||||
config: parseCSV(true)
|
||||
});
|
||||
}, 10);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* MailChimp
|
||||
*/
|
||||
mailChimpKeyInputElement.keyup(function () {
|
||||
if (this.value.trim() === ''
|
||||
|| !/[a-zA-Z0-9]{32}-/.exec(this.value.trim())) {
|
||||
mailChimpListsContainerElement.hide();
|
||||
jQuery('.mailpoet_mailchimp-key-status')
|
||||
.html('')
|
||||
.removeClass('mailpoet_mailchimp-ok mailpoet_mailchimp-error');
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||
}
|
||||
});
|
||||
|
||||
mailChimpKeyVerifyButtonElement.click(function () {
|
||||
MailPoet.Modal.loading(true);
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'importExport',
|
||||
action: 'getMailChimpLists',
|
||||
data: {
|
||||
api_key: mailChimpKeyInputElement.val()
|
||||
}
|
||||
}).always(function () {
|
||||
MailPoet.Modal.loading(false);
|
||||
}).done(function (response) {
|
||||
jQuery('.mailpoet_mailchimp-key-status')
|
||||
.html('')
|
||||
.removeClass()
|
||||
.addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-ok');
|
||||
if (response.data.length === 0) {
|
||||
jQuery('.mailpoet_mailchimp-key-status').html(MailPoet.I18n.t('noMailChimpLists'));
|
||||
mailChimpListsContainerElement.hide();
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||
} else {
|
||||
displayMailChimpLists(response.data);
|
||||
}
|
||||
}).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
mailChimpProcessButtonElement.click(function () {
|
||||
if (mailChimpProcessButtonElement.closest('table a').hasClass('button-disabled')) {
|
||||
return;
|
||||
}
|
||||
MailPoet.Modal.loading(true);
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'importExport',
|
||||
action: 'getMailChimpSubscribers',
|
||||
data: {
|
||||
api_key: mailChimpKeyInputElement.val(),
|
||||
lists: mailChimpListsContainerElement.find('select').val()
|
||||
}
|
||||
}).always(function () {
|
||||
MailPoet.Modal.loading(false);
|
||||
}).done(function (response) {
|
||||
window.importData.step1 = response.data;
|
||||
MailPoet.trackEvent('Subscribers import started', {
|
||||
source: 'MailChimp',
|
||||
'MailPoet Free version': window.mailpoet_version
|
||||
});
|
||||
router.navigate('step2', { trigger: true });
|
||||
}).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.on('route:step2', function () {
|
||||
@ -492,6 +493,15 @@ define(
|
||||
|
||||
showCurrentStep();
|
||||
|
||||
function toggleNextStepButton(condition) {
|
||||
var disabled = 'button-disabled';
|
||||
if (condition === 'on') {
|
||||
nextStepButton.removeClass(disabled);
|
||||
return;
|
||||
}
|
||||
nextStepButton.addClass(disabled);
|
||||
}
|
||||
|
||||
// hide previous statistics/import results
|
||||
jQuery('#subscribers_data_parse_results:visible').html('');
|
||||
jQuery('#subscribers_data_import_results:visible').hide();
|
||||
@ -743,119 +753,6 @@ define(
|
||||
);
|
||||
}
|
||||
|
||||
// render template
|
||||
jQuery('#subscribers_data > table').html(subscribersDataTemplate(subscribers));
|
||||
|
||||
// filter displayed data
|
||||
jQuery('select.mailpoet_subscribers_column_data_match')
|
||||
.select2({
|
||||
data: window.mailpoetColumnsSelect2,
|
||||
width: '15em',
|
||||
templateResult: function (item) {
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
return item.name;
|
||||
}
|
||||
})
|
||||
.on('select2:selecting', function (selectEvent) {
|
||||
var selectElement = this;
|
||||
var selectedOptionId = selectEvent.params.args.data.id;
|
||||
// CREATE CUSTOM FIELD
|
||||
if (selectedOptionId === 'create') {
|
||||
selectEvent.preventDefault();
|
||||
jQuery(selectElement).select2('close');
|
||||
MailPoet.Modal.popup({
|
||||
title: MailPoet.I18n.t('addNewField'),
|
||||
template: jQuery('#form_template_field_form').html()
|
||||
});
|
||||
jQuery('#form_field_new').parsley().on('form:submit', function () {
|
||||
// get data
|
||||
var data = jQuery(this.$element).mailpoetSerializeObject();
|
||||
|
||||
// save custom field
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'customFields',
|
||||
action: 'save',
|
||||
data: data
|
||||
}).done(function (response) {
|
||||
var new_column_data = {
|
||||
id: response.data.id,
|
||||
name: response.data.name,
|
||||
type: response.data.type,
|
||||
params: response.data.params,
|
||||
custom: true
|
||||
};
|
||||
// if this is the first custom column, create an "optgroup"
|
||||
if (window.mailpoetColumnsSelect2.length === 2) {
|
||||
window.mailpoetColumnsSelect2.push({
|
||||
name: MailPoet.I18n.t('userColumns'),
|
||||
children: []
|
||||
});
|
||||
}
|
||||
window.mailpoetColumnsSelect2[2].children.push(new_column_data);
|
||||
window.mailpoetColumns.push(new_column_data);
|
||||
jQuery('select.mailpoet_subscribers_column_data_match')
|
||||
.each(function () {
|
||||
jQuery(this)
|
||||
.html('')
|
||||
.select2('destroy')
|
||||
.select2({
|
||||
data: window.mailpoetColumnsSelect2,
|
||||
width: '15em',
|
||||
templateResult: function (item) {
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
return item.name;
|
||||
}
|
||||
});
|
||||
});
|
||||
jQuery(selectElement).data('column-id', new_column_data.id);
|
||||
jQuery(selectElement).data('validation-rule', false);
|
||||
filterSubscribers();
|
||||
// close popup
|
||||
MailPoet.Modal.close();
|
||||
}).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ positionAfter: '#field_name' }
|
||||
);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
// CHANGE COLUMN
|
||||
else {
|
||||
// check for duplicate values in all select options
|
||||
jQuery('select.mailpoet_subscribers_column_data_match')
|
||||
.each(function () {
|
||||
var element = this;
|
||||
var elementId = jQuery(element).val();
|
||||
// if another column has the same value and it's not an 'ignore', prompt user
|
||||
if (elementId === selectedOptionId
|
||||
&& elementId !== 'ignore') {
|
||||
if (confirm(MailPoet.I18n.t('selectedValueAlreadyMatched') + ' ' + MailPoet.I18n.t('confirmCorrespondingColumn'))) {
|
||||
jQuery(element).data('column-id', 'ignore');
|
||||
}
|
||||
else {
|
||||
selectEvent.preventDefault();
|
||||
jQuery(selectElement).select2('close');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.on('select2:select', function (selectEvent) {
|
||||
var selectElement = this;
|
||||
var selectedOptionId = selectEvent.params.data.id;
|
||||
jQuery(selectElement).data('column-id', selectedOptionId);
|
||||
filterSubscribers();
|
||||
});
|
||||
|
||||
// filter subscribers' data to detect dates, emails, etc.
|
||||
function filterSubscribers() {
|
||||
var subscribersClone = jQuery.extend(true, {}, subscribers);
|
||||
@ -988,14 +885,118 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
function toggleNextStepButton(condition) {
|
||||
var disabled = 'button-disabled';
|
||||
if (condition === 'on') {
|
||||
nextStepButton.removeClass(disabled);
|
||||
return;
|
||||
// render template
|
||||
jQuery('#subscribers_data > table').html(subscribersDataTemplate(subscribers));
|
||||
|
||||
// filter displayed data
|
||||
jQuery('select.mailpoet_subscribers_column_data_match')
|
||||
.select2({
|
||||
data: window.mailpoetColumnsSelect2,
|
||||
width: '15em',
|
||||
templateResult: function (item) {
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
return item.name;
|
||||
}
|
||||
nextStepButton.addClass(disabled);
|
||||
})
|
||||
.on('select2:selecting', function (selectEvent) {
|
||||
var selectElement = this;
|
||||
var selectedOptionId = selectEvent.params.args.data.id;
|
||||
// CREATE CUSTOM FIELD
|
||||
if (selectedOptionId === 'create') {
|
||||
selectEvent.preventDefault();
|
||||
jQuery(selectElement).select2('close');
|
||||
MailPoet.Modal.popup({
|
||||
title: MailPoet.I18n.t('addNewField'),
|
||||
template: jQuery('#form_template_field_form').html()
|
||||
});
|
||||
jQuery('#form_field_new').parsley().on('form:submit', function () {
|
||||
// get data
|
||||
var data = jQuery(this.$element).mailpoetSerializeObject();
|
||||
|
||||
// save custom field
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'customFields',
|
||||
action: 'save',
|
||||
data: data
|
||||
}).done(function (response) {
|
||||
var new_column_data = {
|
||||
id: response.data.id,
|
||||
name: response.data.name,
|
||||
type: response.data.type,
|
||||
params: response.data.params,
|
||||
custom: true
|
||||
};
|
||||
// if this is the first custom column, create an "optgroup"
|
||||
if (window.mailpoetColumnsSelect2.length === 2) {
|
||||
window.mailpoetColumnsSelect2.push({
|
||||
name: MailPoet.I18n.t('userColumns'),
|
||||
children: []
|
||||
});
|
||||
}
|
||||
window.mailpoetColumnsSelect2[2].children.push(new_column_data);
|
||||
window.mailpoetColumns.push(new_column_data);
|
||||
jQuery('select.mailpoet_subscribers_column_data_match')
|
||||
.each(function () {
|
||||
jQuery(this)
|
||||
.html('')
|
||||
.select2('destroy')
|
||||
.select2({
|
||||
data: window.mailpoetColumnsSelect2,
|
||||
width: '15em',
|
||||
templateResult: function (item) {
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
return item.name;
|
||||
}
|
||||
});
|
||||
});
|
||||
jQuery(selectElement).data('column-id', new_column_data.id);
|
||||
jQuery(selectElement).data('validation-rule', false);
|
||||
filterSubscribers();
|
||||
// close popup
|
||||
MailPoet.Modal.close();
|
||||
}).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ positionAfter: '#field_name' }
|
||||
);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
// CHANGE COLUMN
|
||||
else {
|
||||
// check for duplicate values in all select options
|
||||
jQuery('select.mailpoet_subscribers_column_data_match')
|
||||
.each(function () {
|
||||
var element = this;
|
||||
var elementId = jQuery(element).val();
|
||||
// if another column has the same value and it's not an 'ignore', prompt user
|
||||
if (elementId === selectedOptionId
|
||||
&& elementId !== 'ignore') {
|
||||
if (confirm(MailPoet.I18n.t('selectedValueAlreadyMatched') + ' ' + MailPoet.I18n.t('confirmCorrespondingColumn'))) {
|
||||
jQuery(element).data('column-id', 'ignore');
|
||||
}
|
||||
else {
|
||||
selectEvent.preventDefault();
|
||||
jQuery(selectElement).select2('close');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.on('select2:select', function (selectEvent) {
|
||||
var selectElement = this;
|
||||
var selectedOptionId = selectEvent.params.data.id;
|
||||
jQuery(selectElement).data('column-id', selectedOptionId);
|
||||
filterSubscribers();
|
||||
});
|
||||
|
||||
previousStepButton.off().on('click', function () {
|
||||
router.navigate('step1', { trigger: true });
|
||||
|
Reference in New Issue
Block a user