ES5 vars-on-top
This commit is contained in:
@ -46,7 +46,6 @@
|
|||||||
"camelcase": 0,
|
"camelcase": 0,
|
||||||
"padded-blocks": 0,
|
"padded-blocks": 0,
|
||||||
"strict": 0,
|
"strict": 0,
|
||||||
"vars-on-top": 0,
|
|
||||||
"no-var": 0,
|
"no-var": 0,
|
||||||
"no-unused-vars": 0,
|
"no-unused-vars": 0,
|
||||||
"object-shorthand": 0,
|
"object-shorthand": 0,
|
||||||
|
@ -2,11 +2,10 @@ function requestFailed(errorMessage, xhr) {
|
|||||||
if (xhr.responseJSON) {
|
if (xhr.responseJSON) {
|
||||||
return xhr.responseJSON;
|
return xhr.responseJSON;
|
||||||
}
|
}
|
||||||
var message = errorMessage.replace('%d', xhr.status);
|
|
||||||
return {
|
return {
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
message: message
|
message: errorMessage.replace('%d', xhr.status)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@ -54,11 +53,13 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function (mp, jQuery, _) {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
request: function(method, options) {
|
request: function(method, options) {
|
||||||
|
var params;
|
||||||
|
var deferred;
|
||||||
// set options
|
// set options
|
||||||
this.init(options);
|
this.init(options);
|
||||||
|
|
||||||
// set request params
|
// set request params
|
||||||
var params = this.getParams();
|
params = this.getParams();
|
||||||
|
|
||||||
// remove null values from the data object
|
// remove null values from the data object
|
||||||
if (_.isObject(params.data)) {
|
if (_.isObject(params.data)) {
|
||||||
@ -68,7 +69,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function (mp, jQuery, _) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ajax request
|
// ajax request
|
||||||
var deferred = jQuery.post(
|
deferred = jQuery.post(
|
||||||
this.options.url,
|
this.options.url,
|
||||||
params,
|
params,
|
||||||
null,
|
null,
|
||||||
|
@ -43,9 +43,10 @@ define('date',
|
|||||||
},
|
},
|
||||||
format: function (date, opts) {
|
format: function (date, opts) {
|
||||||
var options = opts || {};
|
var options = opts || {};
|
||||||
|
var momentDate;
|
||||||
this.init(options);
|
this.init(options);
|
||||||
|
|
||||||
var momentDate = Moment(date, this.convertFormat(options.parseFormat));
|
momentDate = Moment(date, this.convertFormat(options.parseFormat));
|
||||||
if (options.offset === 0) momentDate = momentDate.utc();
|
if (options.offset === 0) momentDate = momentDate.utc();
|
||||||
return momentDate.format(this.convertFormat(this.options.format));
|
return momentDate.format(this.convertFormat(this.options.format));
|
||||||
},
|
},
|
||||||
@ -71,6 +72,11 @@ define('date',
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
convertFormat: function(format) {
|
convertFormat: function(format) {
|
||||||
|
var replacements;
|
||||||
|
var convertedFormat;
|
||||||
|
var escapeToken;
|
||||||
|
var index;
|
||||||
|
var token;
|
||||||
var format_mappings = {
|
var format_mappings = {
|
||||||
date: {
|
date: {
|
||||||
d: 'DD',
|
d: 'DD',
|
||||||
@ -140,12 +146,11 @@ define('date',
|
|||||||
|
|
||||||
if (!format || format.length <= 0) return format;
|
if (!format || format.length <= 0) return format;
|
||||||
|
|
||||||
var replacements = format_mappings['date'];
|
replacements = format_mappings['date'];
|
||||||
|
convertedFormat = [];
|
||||||
|
escapeToken = false;
|
||||||
|
|
||||||
var convertedFormat = [];
|
for(index = 0, token = ''; format.charAt(index); index += 1){
|
||||||
var escapeToken = false;
|
|
||||||
|
|
||||||
for (var index = 0, token = ''; format.charAt(index); index += 1) {
|
|
||||||
token = format.charAt(index);
|
token = format.charAt(index);
|
||||||
if (escapeToken === true) {
|
if (escapeToken === true) {
|
||||||
convertedFormat.push('[' + token + ']');
|
convertedFormat.push('[' + token + ']');
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var Observable;
|
||||||
|
var WysijaHistory;
|
||||||
|
var WysijaForm;
|
||||||
|
|
||||||
Event.cacheDelegated = {};
|
Event.cacheDelegated = {};
|
||||||
Object.extend(document, (function () {
|
Object.extend(document, (function () {
|
||||||
var cache = Event.cacheDelegated;
|
var cache = Event.cacheDelegated;
|
||||||
@ -30,19 +34,21 @@ Object.extend(document, (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function destroyWrapper(selector, eventName, handler) {
|
function destroyWrapper(selector, eventName, handler) {
|
||||||
|
var wrapper;
|
||||||
var c = getCacheForSelector(selector);
|
var c = getCacheForSelector(selector);
|
||||||
if(!c[eventName]) return false;
|
if(!c[eventName]) return false;
|
||||||
var wrapper = findWrapper(selector, eventName, handler);
|
wrapper = findWrapper(selector, eventName, handler);
|
||||||
c[eventName] = c[eventName].without(wrapper);
|
c[eventName] = c[eventName].without(wrapper);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWrapper(selector, eventName, handler, context) {
|
function createWrapper(selector, eventName, handler, context) {
|
||||||
var wrapper;
|
var wrapper;
|
||||||
|
var element;
|
||||||
var c = getWrappersForSelector(selector, eventName);
|
var c = getWrappersForSelector(selector, eventName);
|
||||||
if(c.pluck('handler').include(handler)) return false;
|
if(c.pluck('handler').include(handler)) return false;
|
||||||
wrapper = function(event) {
|
wrapper = function(event) {
|
||||||
var element = event.findElement(selector);
|
element = event.findElement(selector);
|
||||||
if(element) handler.call(context || element, event, element);
|
if(element) handler.call(context || element, event, element);
|
||||||
};
|
};
|
||||||
wrapper.handler = handler;
|
wrapper.handler = handler;
|
||||||
@ -57,6 +63,7 @@ Object.extend(document, (function () {
|
|||||||
},
|
},
|
||||||
stopDelegating: function (selector, eventName, handler) {
|
stopDelegating: function (selector, eventName, handler) {
|
||||||
var length = arguments.length;
|
var length = arguments.length;
|
||||||
|
var wrapper;
|
||||||
switch(length) {
|
switch(length) {
|
||||||
case 2:
|
case 2:
|
||||||
getWrappersForSelector(selector, eventName).each(function (wrapper) {
|
getWrappersForSelector(selector, eventName).each(function (wrapper) {
|
||||||
@ -74,7 +81,7 @@ Object.extend(document, (function () {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
var wrapper = destroyWrapper.apply(null, arguments);
|
wrapper = destroyWrapper.apply(null, arguments);
|
||||||
if(wrapper) document.stopObserving(eventName, wrapper);
|
if(wrapper) document.stopObserving(eventName, wrapper);
|
||||||
}
|
}
|
||||||
return document;
|
return document;
|
||||||
@ -82,7 +89,7 @@ Object.extend(document, (function () {
|
|||||||
};
|
};
|
||||||
})());
|
})());
|
||||||
|
|
||||||
var Observable = (function () {
|
Observable = (function() {
|
||||||
function getEventName(nameA, namespace) {
|
function getEventName(nameA, namespace) {
|
||||||
var name = nameA.substring(2);
|
var name = nameA.substring(2);
|
||||||
if (namespace) name = namespace + ':' + name;
|
if (namespace) name = namespace + ':' + name;
|
||||||
@ -112,9 +119,9 @@ var Observable = (function () {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
observe: function(selector) {
|
observe: function(selector) {
|
||||||
|
var klass = this;
|
||||||
if(!this.handlers) this.handlers = {};
|
if(!this.handlers) this.handlers = {};
|
||||||
if(this.handlers[selector]) return;
|
if(this.handlers[selector]) return;
|
||||||
var klass = this;
|
|
||||||
if(this.prototype.onDomLoaded) {
|
if(this.prototype.onDomLoaded) {
|
||||||
if(document.loaded) {
|
if(document.loaded) {
|
||||||
onDomLoad(selector, klass);
|
onDomLoad(selector, klass);
|
||||||
@ -147,9 +154,9 @@ Object.extend(window.Droppables, {
|
|||||||
return proceed(drop);
|
return proceed(drop);
|
||||||
}),
|
}),
|
||||||
show: function(point, element) {
|
show: function(point, element) {
|
||||||
if(!this.drops.length) return;
|
|
||||||
var drop;
|
var drop;
|
||||||
var affected = [];
|
var affected = [];
|
||||||
|
if(!this.drops.length) return;
|
||||||
this.drops.each(function(drop) {
|
this.drops.each(function(drop) {
|
||||||
if(window.Droppables.isAffected(point, element, drop)) affected.push(drop);
|
if(window.Droppables.isAffected(point, element, drop)) affected.push(drop);
|
||||||
});
|
});
|
||||||
@ -197,7 +204,7 @@ Object.extend(window.Droppables, {
|
|||||||
- set a maximum number of items to be stored
|
- set a maximum number of items to be stored
|
||||||
|
|
||||||
*/
|
*/
|
||||||
var WysijaHistory = {
|
WysijaHistory = {
|
||||||
container: 'mailpoet_form_history',
|
container: 'mailpoet_form_history',
|
||||||
size: 30,
|
size: 30,
|
||||||
enqueue: function (element) {
|
enqueue: function (element) {
|
||||||
@ -241,7 +248,7 @@ var WysijaHistory = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* MailPoet Form */
|
/* MailPoet Form */
|
||||||
var WysijaForm = {
|
WysijaForm = {
|
||||||
version: '0.7',
|
version: '0.7',
|
||||||
options: {
|
options: {
|
||||||
container: 'mailpoet_form_container',
|
container: 'mailpoet_form_container',
|
||||||
@ -294,6 +301,7 @@ var WysijaForm = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
load: function(data) {
|
load: function(data) {
|
||||||
|
var settings_elements;
|
||||||
if(data === undefined) return;
|
if(data === undefined) return;
|
||||||
|
|
||||||
// load body
|
// load body
|
||||||
@ -304,7 +312,7 @@ var WysijaForm = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// load settings
|
// load settings
|
||||||
var settings_elements = window.$('mailpoet_form_settings').getElements();
|
settings_elements = window.$('mailpoet_form_settings').getElements();
|
||||||
settings_elements.each(function(setting) {
|
settings_elements.each(function(setting) {
|
||||||
// skip lists
|
// skip lists
|
||||||
if (setting.name === 'segments') {
|
if (setting.name === 'segments') {
|
||||||
@ -403,6 +411,7 @@ var WysijaForm = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
toggleWidgets: function() {
|
toggleWidgets: function() {
|
||||||
|
var hasSegmentSelection;
|
||||||
window.$$('a[wysija_unique="1"]').invoke('removeClassName', 'disabled');
|
window.$$('a[wysija_unique="1"]').invoke('removeClassName', 'disabled');
|
||||||
|
|
||||||
// loop through each unique field already inserted in the editor and disable its toolbar equivalent
|
// loop through each unique field already inserted in the editor and disable its toolbar equivalent
|
||||||
@ -413,7 +422,7 @@ var WysijaForm = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var hasSegmentSelection = WysijaForm.hasSegmentSelection();
|
hasSegmentSelection = WysijaForm.hasSegmentSelection();
|
||||||
|
|
||||||
if (hasSegmentSelection) {
|
if (hasSegmentSelection) {
|
||||||
window.$('mailpoet_form_segments').writeAttribute('required', false).disable();
|
window.$('mailpoet_form_segments').writeAttribute('required', false).disable();
|
||||||
@ -428,8 +437,9 @@ var WysijaForm = {
|
|||||||
},
|
},
|
||||||
isSegmentSelectionValid: function () {
|
isSegmentSelectionValid: function () {
|
||||||
var segment_selection = window.$$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]')[0];
|
var segment_selection = window.$$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]')[0];
|
||||||
|
var block;
|
||||||
if(segment_selection !== undefined) {
|
if(segment_selection !== undefined) {
|
||||||
var block = WysijaForm.get(segment_selection).block.getData();
|
block = WysijaForm.get(segment_selection).block.getData();
|
||||||
return (
|
return (
|
||||||
(block.params.values !== undefined)
|
(block.params.values !== undefined)
|
||||||
&&
|
&&
|
||||||
@ -439,10 +449,12 @@ var WysijaForm = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
setBlockPositions: function(event, target) {
|
setBlockPositions: function(event, target) {
|
||||||
|
var index = 1;
|
||||||
|
var block_placeholder;
|
||||||
|
var previous_placeholder;
|
||||||
// release dragging lock
|
// release dragging lock
|
||||||
WysijaForm.locks.dragging = false;
|
WysijaForm.locks.dragging = false;
|
||||||
|
|
||||||
var index = 1;
|
|
||||||
WysijaForm.getBlocks().each(function(container) {
|
WysijaForm.getBlocks().each(function(container) {
|
||||||
container.setPosition(index++);
|
container.setPosition(index++);
|
||||||
// remove z-index value to avoid issues when resizing images
|
// remove z-index value to avoid issues when resizing images
|
||||||
@ -455,8 +467,8 @@ var WysijaForm = {
|
|||||||
|
|
||||||
if (target !== undefined) {
|
if (target !== undefined) {
|
||||||
// get placeholders (previous placeholder matches the placeholder linked to the next block)
|
// get placeholders (previous placeholder matches the placeholder linked to the next block)
|
||||||
var block_placeholder = window.$(target.element.readAttribute('wysija_placeholder'));
|
block_placeholder = window.$(target.element.readAttribute('wysija_placeholder'));
|
||||||
var previous_placeholder = target.element.previous('.block_placeholder');
|
previous_placeholder = target.element.previous('.block_placeholder');
|
||||||
|
|
||||||
if (block_placeholder !== null) {
|
if (block_placeholder !== null) {
|
||||||
// put block placeholder before the current block
|
// put block placeholder before the current block
|
||||||
@ -491,12 +503,15 @@ var WysijaForm = {
|
|||||||
var is_visible = (parentPos.top <= (WysijaForm.scroll.top + viewportHeight));
|
var is_visible = (parentPos.top <= (WysijaForm.scroll.top + viewportHeight));
|
||||||
var buttonMargin = 5;
|
var buttonMargin = 5;
|
||||||
var relativeTop = buttonMargin;
|
var relativeTop = buttonMargin;
|
||||||
|
var absoluteTop;
|
||||||
|
var parentTop;
|
||||||
|
var parentBottom;
|
||||||
|
|
||||||
if (is_visible) {
|
if (is_visible) {
|
||||||
// desired position is set to center of viewport
|
// desired position is set to center of viewport
|
||||||
var absoluteTop = parseInt(WysijaForm.scroll.top + ((viewportHeight / 2) - (element.getHeight() / 2)), 10);
|
absoluteTop = parseInt(WysijaForm.scroll.top + ((viewportHeight / 2) - (element.getHeight() / 2)), 10);
|
||||||
var parentTop = parseInt(parentPos.top - blockPadding, 10);
|
parentTop = parseInt(parentPos.top - blockPadding, 10);
|
||||||
var parentBottom = parseInt(parentPos.top + parentDim.height - blockPadding, 10);
|
parentBottom = parseInt(parentPos.top + parentDim.height - blockPadding, 10);
|
||||||
|
|
||||||
// always center
|
// always center
|
||||||
relativeTop = parseInt((parentDim.height / 2) - (element.getHeight() / 2), 10);
|
relativeTop = parseInt((parentDim.height / 2) - (element.getHeight() / 2), 10);
|
||||||
@ -521,9 +536,10 @@ var WysijaForm = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
setToolbarPosition: function() {
|
setToolbarPosition: function() {
|
||||||
|
var position;
|
||||||
WysijaForm.initToolbarPosition();
|
WysijaForm.initToolbarPosition();
|
||||||
|
|
||||||
var position = {
|
position = {
|
||||||
top: WysijaForm.toolbar.y + 'px',
|
top: WysijaForm.toolbar.y + 'px',
|
||||||
visibility: 'visible'
|
visibility: 'visible'
|
||||||
};
|
};
|
||||||
@ -587,10 +603,12 @@ var WysijaForm = {
|
|||||||
instances: {},
|
instances: {},
|
||||||
get: function (element, typ) {
|
get: function (element, typ) {
|
||||||
var type = typ;
|
var type = typ;
|
||||||
|
var id;
|
||||||
|
var instance;
|
||||||
if(type === undefined) type = 'block';
|
if(type === undefined) type = 'block';
|
||||||
// identify element
|
// identify element
|
||||||
var id = element.identify();
|
id = element.identify();
|
||||||
var instance = WysijaForm.instances[id] || new WysijaForm[type.capitalize().camelize()](id);
|
instance = WysijaForm.instances[id] || new WysijaForm[type.capitalize().camelize()](id);
|
||||||
|
|
||||||
WysijaForm.instances[id] = instance;
|
WysijaForm.instances[id] = instance;
|
||||||
return instance;
|
return instance;
|
||||||
@ -769,15 +787,17 @@ WysijaForm.Block = window.Class.create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
makeBlockDroppable: function() {
|
makeBlockDroppable: function() {
|
||||||
|
var block_placeholder;
|
||||||
if(this.isBlockDroppableEnabled() === false) {
|
if(this.isBlockDroppableEnabled() === false) {
|
||||||
var block_placeholder = this.getBlockDroppable();
|
block_placeholder = this.getBlockDroppable();
|
||||||
window.Droppables.add(block_placeholder.identify(), WysijaForm.blockDropOptions);
|
window.Droppables.add(block_placeholder.identify(), WysijaForm.blockDropOptions);
|
||||||
block_placeholder.addClassName('enabled');
|
block_placeholder.addClassName('enabled');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeBlockDroppable: function() {
|
removeBlockDroppable: function() {
|
||||||
|
var block_placeholder;
|
||||||
if(this.isBlockDroppableEnabled()) {
|
if(this.isBlockDroppableEnabled()) {
|
||||||
var block_placeholder = this.getBlockDroppable();
|
block_placeholder = this.getBlockDroppable();
|
||||||
window.Droppables.remove(block_placeholder.identify());
|
window.Droppables.remove(block_placeholder.identify());
|
||||||
block_placeholder.removeClassName('enabled');
|
block_placeholder.removeClassName('enabled');
|
||||||
}
|
}
|
||||||
@ -809,6 +829,8 @@ WysijaForm.Block = window.Class.create({
|
|||||||
return this.element.down('.wysija_controls');
|
return this.element.down('.wysija_controls');
|
||||||
},
|
},
|
||||||
setupControls: function() {
|
setupControls: function() {
|
||||||
|
var block;
|
||||||
|
var field;
|
||||||
// enable controls
|
// enable controls
|
||||||
this.controls = this.getControls();
|
this.controls = this.getControls();
|
||||||
|
|
||||||
@ -859,9 +881,9 @@ WysijaForm.Block = window.Class.create({
|
|||||||
if (this.settingsButton !== null) {
|
if (this.settingsButton !== null) {
|
||||||
this.settingsButton.observe('click', function (event) {
|
this.settingsButton.observe('click', function (event) {
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
var block = window.$(event.target).up('.mailpoet_form_block') || null;
|
block = window.$(event.target).up('.mailpoet_form_block') || null;
|
||||||
if(block !== null) {
|
if(block !== null) {
|
||||||
var field = WysijaForm.getFieldData(block);
|
field = WysijaForm.getFieldData(block);
|
||||||
this.editSettings();
|
this.editSettings();
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
@ -907,18 +929,24 @@ WysijaForm.Block = window.Class.create({
|
|||||||
/* Invoked on item dropped */
|
/* Invoked on item dropped */
|
||||||
WysijaForm.Block.create = function (createBlock, target) {
|
WysijaForm.Block.create = function (createBlock, target) {
|
||||||
var block = createBlock;
|
var block = createBlock;
|
||||||
|
var body;
|
||||||
|
var block_template;
|
||||||
|
var template;
|
||||||
|
var output;
|
||||||
|
var settings_segments;
|
||||||
|
var element;
|
||||||
if(window.$('form_template_' + block.type) === null) {
|
if(window.$('form_template_' + block.type) === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var body = window.$(WysijaForm.options.body);
|
body = window.$(WysijaForm.options.body);
|
||||||
var block_template = window.Handlebars.compile(window.$('form_template_block').innerHTML);
|
block_template = window.Handlebars.compile(window.$('form_template_block').innerHTML);
|
||||||
var template = window.Handlebars.compile(window.$('form_template_' + block.type).innerHTML);
|
template = window.Handlebars.compile(window.$('form_template_' + block.type).innerHTML);
|
||||||
var output = '';
|
output = '';
|
||||||
|
|
||||||
if(block.type === 'segment') {
|
if(block.type === 'segment') {
|
||||||
if(block.params.values === undefined) {
|
if(block.params.values === undefined) {
|
||||||
var settings_segments = window.jQuery('#mailpoet_form_segments').val();
|
settings_segments = window.jQuery('#mailpoet_form_segments').val();
|
||||||
if(settings_segments !== null && settings_segments.length > 0){
|
if(settings_segments !== null && settings_segments.length > 0){
|
||||||
block.params.values = window.mailpoet_segments.filter(function(segment) {
|
block.params.values = window.mailpoet_segments.filter(function(segment) {
|
||||||
return (settings_segments.indexOf(segment.id) !== -1);
|
return (settings_segments.indexOf(segment.id) !== -1);
|
||||||
@ -938,7 +966,7 @@ WysijaForm.Block.create = function (createBlock, target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the drop target was the bottom placeholder
|
// if the drop target was the bottom placeholder
|
||||||
var element = null;
|
element = null;
|
||||||
if(target.identify() === 'block_placeholder') {
|
if(target.identify() === 'block_placeholder') {
|
||||||
// insert block at the bottom
|
// insert block at the bottom
|
||||||
element = body.insert(output);
|
element = body.insert(output);
|
||||||
@ -986,8 +1014,8 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
|
|||||||
this.setupControls();
|
this.setupControls();
|
||||||
},
|
},
|
||||||
save: function() {
|
save: function() {
|
||||||
info('widget -> save');
|
|
||||||
var data = this.getData();
|
var data = this.getData();
|
||||||
|
info('widget -> save');
|
||||||
|
|
||||||
if (data.element !== undefined) {
|
if (data.element !== undefined) {
|
||||||
delete data.element;
|
delete data.element;
|
||||||
@ -1022,16 +1050,20 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
|
|||||||
this.removeBlock();
|
this.removeBlock();
|
||||||
},
|
},
|
||||||
redraw: function(data) {
|
redraw: function(data) {
|
||||||
|
var options;
|
||||||
|
var block_template;
|
||||||
|
var template;
|
||||||
|
var params;
|
||||||
// set parameters
|
// set parameters
|
||||||
this.setData(data);
|
this.setData(data);
|
||||||
var options = this.getData();
|
options = this.getData();
|
||||||
// redraw block
|
// redraw block
|
||||||
var block_template = window.Handlebars.compile(window.$('form_template_block').innerHTML);
|
block_template = window.Handlebars.compile(window.$('form_template_block').innerHTML);
|
||||||
var template = window.Handlebars.compile(window.$('form_template_' + options.type).innerHTML);
|
template = window.Handlebars.compile(window.$('form_template_' + options.type).innerHTML);
|
||||||
var data = window.$H(options).merge({
|
params = window.$H(options).merge({
|
||||||
template: template(options)
|
template: template(options)
|
||||||
}).toObject();
|
}).toObject();
|
||||||
this.element.replace(block_template(data));
|
this.element.replace(block_template(params));
|
||||||
|
|
||||||
WysijaForm.init();
|
WysijaForm.init();
|
||||||
},
|
},
|
||||||
@ -1063,8 +1095,8 @@ function info(value) {
|
|||||||
var noop = 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 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 length = methods.length;
|
||||||
window.console = {};
|
|
||||||
var console = {};
|
var console = {};
|
||||||
|
window.console = {};
|
||||||
while(length--) {
|
while(length--) {
|
||||||
console[methods[length]] = noop;
|
console[methods[length]] = noop;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) {
|
|||||||
Handlebars.registerHelper('concat', function() {
|
Handlebars.registerHelper('concat', function() {
|
||||||
var size = (arguments.length - 1);
|
var size = (arguments.length - 1);
|
||||||
var output = '';
|
var output = '';
|
||||||
for(var i = 0; i < size; i++) {
|
var i;
|
||||||
|
for(i = 0; i < size; i++) {
|
||||||
output += arguments[i];
|
output += arguments[i];
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
@ -13,13 +14,14 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) {
|
|||||||
return Number(value).toLocaleString();
|
return Number(value).toLocaleString();
|
||||||
});
|
});
|
||||||
Handlebars.registerHelper('date_format', function(timestamp, block) {
|
Handlebars.registerHelper('date_format', function(timestamp, block) {
|
||||||
|
var f;
|
||||||
if(window.moment) {
|
if(window.moment) {
|
||||||
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
|
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set date format
|
// set date format
|
||||||
var f = block.hash.format || 'MMM Do, YYYY';
|
f = block.hash.format || 'MMM Do, YYYY';
|
||||||
// check if we passed a timestamp
|
// check if we passed a timestamp
|
||||||
if(parseInt(timestamp, 10) == timestamp) {
|
if(parseInt(timestamp, 10) == timestamp) {
|
||||||
return window.moment.unix(timestamp).format(f);
|
return window.moment.unix(timestamp).format(f);
|
||||||
@ -37,6 +39,7 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
|
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
|
||||||
|
var values;
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case '==':
|
case '==':
|
||||||
return (v1 == v2) ? options.fn(this) : options.inverse(this);
|
return (v1 == v2) ? options.fn(this) : options.inverse(this);
|
||||||
@ -59,7 +62,7 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) {
|
|||||||
case '||':
|
case '||':
|
||||||
return (v1 || v2) ? options.fn(this) : options.inverse(this);
|
return (v1 || v2) ? options.fn(this) : options.inverse(this);
|
||||||
case 'in':
|
case 'in':
|
||||||
var values = v2.split(',');
|
values = v2.split(',');
|
||||||
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
|
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
|
||||||
default:
|
default:
|
||||||
return options.inverse(this);
|
return options.inverse(this);
|
||||||
@ -96,10 +99,11 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) {
|
|||||||
|
|
||||||
|
|
||||||
Handlebars.registerHelper('rsa_key', function(value, block) {
|
Handlebars.registerHelper('rsa_key', function(value, block) {
|
||||||
|
var lines;
|
||||||
// extract all lines into an array
|
// extract all lines into an array
|
||||||
if(value === undefined) return '';
|
if(value === undefined) return '';
|
||||||
|
|
||||||
var lines = value.trim().split('\n');
|
lines = value.trim().split('\n');
|
||||||
|
|
||||||
// remove header & footer
|
// remove header & footer
|
||||||
lines.shift();
|
lines.shift();
|
||||||
@ -126,10 +130,10 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) {
|
|||||||
*/
|
*/
|
||||||
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
|
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
|
||||||
var strAppend = append;
|
var strAppend = append;
|
||||||
|
var sanitized = str.replace(/(<([^>]+)>)/g, '');
|
||||||
if (strAppend === undefined) {
|
if (strAppend === undefined) {
|
||||||
strAppend = '';
|
strAppend = '';
|
||||||
}
|
}
|
||||||
var sanitized = str.replace(/(<([^>]+)>)/g, '');
|
|
||||||
if (sanitized.length > limit) {
|
if (sanitized.length > limit) {
|
||||||
return sanitized.substr(0, limit - strAppend.length) + strAppend;
|
return sanitized.substr(0, limit - strAppend.length) + strAppend;
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,6 +116,7 @@ define('modal', ['mailpoet', 'jquery'],
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
init: function(options) {
|
init: function(options) {
|
||||||
|
var modal;
|
||||||
if(this.initialized === true) {
|
if(this.initialized === true) {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
@ -134,7 +135,7 @@ define('modal', ['mailpoet', 'jquery'],
|
|||||||
if (this.options.type !== null) {
|
if (this.options.type !== null) {
|
||||||
// insert modal depending on its type
|
// insert modal depending on its type
|
||||||
if(this.options.type === 'popup') {
|
if(this.options.type === 'popup') {
|
||||||
var modal = this.compileTemplate(
|
modal = this.compileTemplate(
|
||||||
this.templates[this.options.type]
|
this.templates[this.options.type]
|
||||||
);
|
);
|
||||||
// create modal
|
// create modal
|
||||||
@ -343,20 +344,21 @@ define('modal', ['mailpoet', 'jquery'],
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
setPosition: function() {
|
setPosition: function() {
|
||||||
|
var screenWidth;
|
||||||
|
var screenHeight;
|
||||||
|
var modalWidth;
|
||||||
|
var modalHeight;
|
||||||
switch(this.options.type) {
|
switch(this.options.type) {
|
||||||
case 'popup':
|
case 'popup':
|
||||||
var screenWidth = jQuery(window).width();
|
screenWidth = jQuery(window).width();
|
||||||
var screenHeight = jQuery(window).height();
|
screenHeight = jQuery(window).height();
|
||||||
var modalWidth = jQuery('.mailpoet_'+ this.options.type +'_wrapper').width();
|
modalWidth = jQuery('.mailpoet_'+ this.options.type +'_wrapper').width();
|
||||||
var modalHeight = jQuery('.mailpoet_'+ this.options.type +'_wrapper').height();
|
modalHeight = jQuery('.mailpoet_'+ this.options.type +'_wrapper').height();
|
||||||
|
|
||||||
var top = Math.max(48, parseInt((screenHeight / 2) - (modalHeight / 2)));
|
|
||||||
var left = Math.max(0, parseInt((screenWidth / 2) - (modalWidth / 2)));
|
|
||||||
|
|
||||||
// set position of popup depending on screen dimensions.
|
// set position of popup depending on screen dimensions.
|
||||||
jQuery('#mailpoet_popup').css({
|
jQuery('#mailpoet_popup').css({
|
||||||
top: top,
|
top: Math.max(48, parseInt((screenHeight / 2) - (modalHeight / 2))),
|
||||||
left: left
|
left: Math.max(0, parseInt((screenWidth / 2) - (modalWidth / 2)))
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'panel':
|
case 'panel':
|
||||||
|
@ -197,6 +197,7 @@ define([
|
|||||||
var index;
|
var index;
|
||||||
var tempCollection;
|
var tempCollection;
|
||||||
var tempCollection2;
|
var tempCollection2;
|
||||||
|
var tempModel;
|
||||||
|
|
||||||
if (dropPosition === undefined) return;
|
if (dropPosition === undefined) return;
|
||||||
|
|
||||||
@ -220,7 +221,7 @@ define([
|
|||||||
} else {
|
} else {
|
||||||
// Special insertion by replacing target block with collection
|
// Special insertion by replacing target block with collection
|
||||||
// and inserting dropModel into that
|
// and inserting dropModel into that
|
||||||
var tempModel = viewCollection.at(dropPosition.index);
|
tempModel = viewCollection.at(dropPosition.index);
|
||||||
|
|
||||||
tempCollection = new (window.EditorApplication.getBlockTypeModel('container'))({
|
tempCollection = new (window.EditorApplication.getBlockTypeModel('container'))({
|
||||||
orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical'
|
orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical'
|
||||||
|
@ -49,18 +49,21 @@ define([
|
|||||||
|
|
||||||
onstart: function (startEvent) {
|
onstart: function (startEvent) {
|
||||||
var event = startEvent;
|
var event = startEvent;
|
||||||
|
|
||||||
if (that.options.cloneOriginal === true) {
|
|
||||||
// Use substitution instead of a clone
|
|
||||||
var tempClone = (_.isFunction(that.options.onDragSubstituteBy)) ? that.options.onDragSubstituteBy(that) : undefined;
|
|
||||||
// Or use a clone
|
|
||||||
var clone = tempClone || event.target.cloneNode(true);
|
|
||||||
|
|
||||||
var $original = jQuery(event.target);
|
|
||||||
var $clone = jQuery(clone);
|
|
||||||
var centerXOffset;
|
var centerXOffset;
|
||||||
var centerYOffset;
|
var centerYOffset;
|
||||||
var parentOffset;
|
var parentOffset;
|
||||||
|
var tempClone;
|
||||||
|
var clone;
|
||||||
|
var $original;
|
||||||
|
var $clone;
|
||||||
|
|
||||||
|
if (that.options.cloneOriginal === true) {
|
||||||
|
// Use substitution instead of a clone
|
||||||
|
tempClone = (_.isFunction(that.options.onDragSubstituteBy)) ? that.options.onDragSubstituteBy(that) : undefined;
|
||||||
|
// Or use a clone
|
||||||
|
clone = tempClone || event.target.cloneNode(true);
|
||||||
|
$original = jQuery(event.target);
|
||||||
|
$clone = jQuery(clone);
|
||||||
|
|
||||||
$clone.addClass('mailpoet_droppable_active');
|
$clone.addClass('mailpoet_droppable_active');
|
||||||
$clone.css('position', 'absolute');
|
$clone.css('position', 'absolute');
|
||||||
|
@ -43,12 +43,13 @@ define([
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
|
var blocks;
|
||||||
var models = App.findModels(function(model) {
|
var models = App.findModels(function(model) {
|
||||||
return model.get('type') === 'automatedLatestContent';
|
return model.get('type') === 'automatedLatestContent';
|
||||||
}) || [];
|
}) || [];
|
||||||
|
|
||||||
if (models.length === 0) return;
|
if (models.length === 0) return;
|
||||||
var blocks = _.map(models, function (model) {
|
blocks = _.map(models, function(model) {
|
||||||
return model.toJSON();
|
return model.toJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -213,12 +214,13 @@ define([
|
|||||||
},
|
},
|
||||||
transport: function (options, success, failure) {
|
transport: function (options, success, failure) {
|
||||||
var taxonomies;
|
var taxonomies;
|
||||||
|
var termsPromise;
|
||||||
var promise = CommunicationComponent.getTaxonomies(
|
var promise = CommunicationComponent.getTaxonomies(
|
||||||
that.model.get('contentType')
|
that.model.get('contentType')
|
||||||
).then(function (tax) {
|
).then(function (tax) {
|
||||||
taxonomies = tax;
|
taxonomies = tax;
|
||||||
// Fetch available terms based on the list of taxonomies already fetched
|
// Fetch available terms based on the list of taxonomies already fetched
|
||||||
var promise = CommunicationComponent.getTerms({
|
termsPromise = CommunicationComponent.getTerms({
|
||||||
search: options.data.term,
|
search: options.data.term,
|
||||||
taxonomies: _.keys(taxonomies)
|
taxonomies: _.keys(taxonomies)
|
||||||
}).then(function (terms) {
|
}).then(function (terms) {
|
||||||
@ -227,7 +229,7 @@ define([
|
|||||||
terms: terms
|
terms: terms
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return promise;
|
return termsPromise;
|
||||||
});
|
});
|
||||||
|
|
||||||
promise.then(success);
|
promise.then(success);
|
||||||
|
@ -241,8 +241,9 @@ define([
|
|||||||
ColorPickerBehavior: {}
|
ColorPickerBehavior: {}
|
||||||
},
|
},
|
||||||
initialize: function(params) {
|
initialize: function(params) {
|
||||||
|
var panelParams;
|
||||||
this.model.trigger('startEditing');
|
this.model.trigger('startEditing');
|
||||||
var panelParams = {
|
panelParams = {
|
||||||
element: this.$el,
|
element: this.$el,
|
||||||
template: '',
|
template: '',
|
||||||
position: 'right',
|
position: 'right',
|
||||||
|
@ -49,8 +49,8 @@ define([
|
|||||||
}, base.BlockView.prototype.behaviors),
|
}, base.BlockView.prototype.behaviors),
|
||||||
onDragSubstituteBy: function() { return Module.DividerWidgetView; },
|
onDragSubstituteBy: function() { return Module.DividerWidgetView; },
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
|
||||||
var that = this;
|
var that = this;
|
||||||
|
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||||
|
|
||||||
// Listen for attempts to change all dividers in one go
|
// Listen for attempts to change all dividers in one go
|
||||||
this._replaceDividerHandler = function (data) { that.model.set(data); that.model.trigger('applyToAll'); };
|
this._replaceDividerHandler = function (data) { that.model.set(data); that.model.trigger('applyToAll'); };
|
||||||
|
@ -127,13 +127,16 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
showMediaManager: function() {
|
showMediaManager: function() {
|
||||||
|
var that = this;
|
||||||
|
var MediaManager;
|
||||||
|
var theFrame;
|
||||||
if (this._mediaManager) {
|
if (this._mediaManager) {
|
||||||
this._mediaManager.resetSelections();
|
this._mediaManager.resetSelections();
|
||||||
this._mediaManager.open();
|
this._mediaManager.open();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var MediaManager = window.wp.media.view.MediaFrame.Select.extend({
|
MediaManager = window.wp.media.view.MediaFrame.Select.extend({
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
window.wp.media.view.MediaFrame.prototype.initialize.apply(this, arguments);
|
window.wp.media.view.MediaFrame.prototype.initialize.apply(this, arguments);
|
||||||
@ -196,6 +199,7 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
bindHandlers: function() {
|
bindHandlers: function() {
|
||||||
|
var handlers;
|
||||||
// from Select
|
// from Select
|
||||||
this.on('router:create:browse', this.createRouter, this);
|
this.on('router:create:browse', this.createRouter, this);
|
||||||
this.on('router:render:browse', this.browseRouter, this);
|
this.on('router:render:browse', this.browseRouter, this);
|
||||||
@ -210,7 +214,7 @@ define([
|
|||||||
|
|
||||||
this.on('updateExcluded', this.browseContent, this);
|
this.on('updateExcluded', this.browseContent, this);
|
||||||
|
|
||||||
var handlers = {
|
handlers = {
|
||||||
content: {
|
content: {
|
||||||
embed: 'embedContent',
|
embed: 'embedContent',
|
||||||
'edit-selection': 'editSelectionContent'
|
'edit-selection': 'editSelectionContent'
|
||||||
@ -321,7 +325,7 @@ define([
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var theFrame = new MediaManager({
|
theFrame = new MediaManager({
|
||||||
id: 'mailpoet-media-manager',
|
id: 'mailpoet-media-manager',
|
||||||
frame: 'select',
|
frame: 'select',
|
||||||
title: 'Select image',
|
title: 'Select image',
|
||||||
@ -335,7 +339,6 @@ define([
|
|||||||
text: 'Select'
|
text: 'Select'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var that = this;
|
|
||||||
this._mediaManager = theFrame;
|
this._mediaManager = theFrame;
|
||||||
|
|
||||||
this._mediaManager.on('insert', function () {
|
this._mediaManager.on('insert', function () {
|
||||||
|
@ -41,6 +41,11 @@ define([
|
|||||||
|
|
||||||
var Module = {};
|
var Module = {};
|
||||||
var base = BaseBlock;
|
var base = BaseBlock;
|
||||||
|
var PostsDisplayOptionsSettingsView;
|
||||||
|
var SinglePostSelectionSettingsView;
|
||||||
|
var EmptyPostSelectionSettingsView;
|
||||||
|
var PostSelectionSettingsView;
|
||||||
|
var PostsSelectionCollectionView;
|
||||||
|
|
||||||
Module.PostsBlockModel = base.BlockModel.extend({
|
Module.PostsBlockModel = base.BlockModel.extend({
|
||||||
stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'],
|
stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'],
|
||||||
@ -190,13 +195,15 @@ define([
|
|||||||
this.model.reply('blockView', this.notifyAboutSelf, this);
|
this.model.reply('blockView', this.notifyAboutSelf, this);
|
||||||
},
|
},
|
||||||
onRender: function() {
|
onRender: function() {
|
||||||
|
var ContainerView;
|
||||||
|
var renderOptions;
|
||||||
if (!this.getRegion('toolsRegion').hasView()) {
|
if (!this.getRegion('toolsRegion').hasView()) {
|
||||||
this.showChildView('toolsRegion', this.toolsView);
|
this.showChildView('toolsRegion', this.toolsView);
|
||||||
}
|
}
|
||||||
this.trigger('showSettings');
|
this.trigger('showSettings');
|
||||||
|
|
||||||
var ContainerView = App.getBlockTypeView('container');
|
ContainerView = App.getBlockTypeView('container');
|
||||||
var renderOptions = {
|
renderOptions = {
|
||||||
disableTextEditor: true,
|
disableTextEditor: true,
|
||||||
disableDragAndDrop: true,
|
disableDragAndDrop: true,
|
||||||
emptyContainerMessage: MailPoet.I18n.t('noPostsToDisplay')
|
emptyContainerMessage: MailPoet.I18n.t('noPostsToDisplay')
|
||||||
@ -283,7 +290,7 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var PostsSelectionCollectionView = Marionette.CollectionView.extend({
|
PostsSelectionCollectionView = Marionette.CollectionView.extend({
|
||||||
className: 'mailpoet_post_scroll_container',
|
className: 'mailpoet_post_scroll_container',
|
||||||
childView: function () { return SinglePostSelectionSettingsView; },
|
childView: function () { return SinglePostSelectionSettingsView; },
|
||||||
emptyView: function () { return EmptyPostSelectionSettingsView; },
|
emptyView: function () { return EmptyPostSelectionSettingsView; },
|
||||||
@ -307,7 +314,7 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var PostSelectionSettingsView = Marionette.View.extend({
|
PostSelectionSettingsView = Marionette.View.extend({
|
||||||
getTemplate: function() { return window.templates.postSelectionPostsBlockSettings; },
|
getTemplate: function() { return window.templates.postSelectionPostsBlockSettings; },
|
||||||
regions: {
|
regions: {
|
||||||
posts: '.mailpoet_post_selection_container'
|
posts: '.mailpoet_post_selection_container'
|
||||||
@ -334,9 +341,10 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onRender: function() {
|
onRender: function() {
|
||||||
|
var postsView;
|
||||||
// Dynamically update available post types
|
// Dynamically update available post types
|
||||||
CommunicationComponent.getPostTypes().done(_.bind(this._updateContentTypes, this));
|
CommunicationComponent.getPostTypes().done(_.bind(this._updateContentTypes, this));
|
||||||
var postsView = new PostsSelectionCollectionView({
|
postsView = new PostsSelectionCollectionView({
|
||||||
collection: this.model.get('_availablePosts'),
|
collection: this.model.get('_availablePosts'),
|
||||||
blockModel: this.model
|
blockModel: this.model
|
||||||
});
|
});
|
||||||
@ -358,12 +366,13 @@ define([
|
|||||||
},
|
},
|
||||||
transport: function (options, success, failure) {
|
transport: function (options, success, failure) {
|
||||||
var taxonomies;
|
var taxonomies;
|
||||||
|
var termsPromise;
|
||||||
var promise = CommunicationComponent.getTaxonomies(
|
var promise = CommunicationComponent.getTaxonomies(
|
||||||
that.model.get('contentType')
|
that.model.get('contentType')
|
||||||
).then(function (tax) {
|
).then(function (tax) {
|
||||||
taxonomies = tax;
|
taxonomies = tax;
|
||||||
// Fetch available terms based on the list of taxonomies already fetched
|
// Fetch available terms based on the list of taxonomies already fetched
|
||||||
var promise = CommunicationComponent.getTerms({
|
termsPromise = CommunicationComponent.getTerms({
|
||||||
search: options.data.term,
|
search: options.data.term,
|
||||||
taxonomies: _.keys(taxonomies)
|
taxonomies: _.keys(taxonomies)
|
||||||
}).then(function (terms) {
|
}).then(function (terms) {
|
||||||
@ -372,7 +381,7 @@ define([
|
|||||||
terms: terms
|
terms: terms
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return promise;
|
return termsPromise;
|
||||||
});
|
});
|
||||||
|
|
||||||
promise.then(success);
|
promise.then(success);
|
||||||
@ -427,11 +436,11 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var EmptyPostSelectionSettingsView = Marionette.View.extend({
|
EmptyPostSelectionSettingsView = Marionette.View.extend({
|
||||||
getTemplate: function() { return window.templates.emptyPostPostsBlockSettings; }
|
getTemplate: function() { return window.templates.emptyPostPostsBlockSettings; }
|
||||||
});
|
});
|
||||||
|
|
||||||
var SinglePostSelectionSettingsView = Marionette.View.extend({
|
SinglePostSelectionSettingsView = Marionette.View.extend({
|
||||||
getTemplate: function() { return window.templates.singlePostPostsBlockSettings; },
|
getTemplate: function() { return window.templates.singlePostPostsBlockSettings; },
|
||||||
events: function() {
|
events: function() {
|
||||||
return {
|
return {
|
||||||
@ -458,7 +467,7 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
|
PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
|
||||||
getTemplate: function() { return window.templates.displayOptionsPostsBlockSettings; },
|
getTemplate: function() { return window.templates.displayOptionsPostsBlockSettings; },
|
||||||
events: function() {
|
events: function() {
|
||||||
return {
|
return {
|
||||||
|
@ -19,6 +19,7 @@ define([
|
|||||||
var SocialBlockSettingsIconView;
|
var SocialBlockSettingsIconView;
|
||||||
var SocialBlockSettingsIconCollectionView;
|
var SocialBlockSettingsIconCollectionView;
|
||||||
var SocialBlockSettingsStylesView;
|
var SocialBlockSettingsStylesView;
|
||||||
|
var SocialIconView;
|
||||||
|
|
||||||
Module.SocialIconModel = SuperModel.extend({
|
Module.SocialIconModel = SuperModel.extend({
|
||||||
defaults: function () {
|
defaults: function () {
|
||||||
@ -83,7 +84,7 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var SocialIconView = Marionette.View.extend({
|
SocialIconView = Marionette.View.extend({
|
||||||
tagName: 'span',
|
tagName: 'span',
|
||||||
getTemplate: function () { return window.templates.socialIconBlock; },
|
getTemplate: function () { return window.templates.socialIconBlock; },
|
||||||
modelEvents: {
|
modelEvents: {
|
||||||
|
@ -7,15 +7,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function(root, factory) {
|
(function(root, factory) {
|
||||||
|
var Marionette = require('backbone.marionette');
|
||||||
|
var Radio = require('backbone.radio');
|
||||||
|
var _ = require('underscore');
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
define(['backbone.marionette', 'backbone.radio', 'underscore'], function (Marionette, Radio, _) {
|
define(['backbone.marionette', 'backbone.radio', 'underscore'], function (Marionette, Radio, _) {
|
||||||
return factory(Marionette, Radio, _);
|
return factory(Marionette, Radio, _);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (typeof exports !== 'undefined') {
|
else if (typeof exports !== 'undefined') {
|
||||||
var Marionette = require('backbone.marionette');
|
|
||||||
var Radio = require('backbone.radio');
|
|
||||||
var _ = require('underscore');
|
|
||||||
module.exports = factory(Marionette, Radio, _);
|
module.exports = factory(Marionette, Radio, _);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -291,12 +291,13 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
validateNewsletter: function(jsonObject) {
|
validateNewsletter: function(jsonObject) {
|
||||||
|
var contents;
|
||||||
if (!App._contentContainer.isValid()) {
|
if (!App._contentContainer.isValid()) {
|
||||||
this.showValidationError(App._contentContainer.validationError);
|
this.showValidationError(App._contentContainer.validationError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var contents = JSON.stringify(jsonObject);
|
contents = JSON.stringify(jsonObject);
|
||||||
if (App.getConfig().get('validation.validateUnsubscribeLinkPresent') &&
|
if (App.getConfig().get('validation.validateUnsubscribeLinkPresent') &&
|
||||||
contents.indexOf('[link:subscription_unsubscribe_url]') < 0 &&
|
contents.indexOf('[link:subscription_unsubscribe_url]') < 0 &&
|
||||||
contents.indexOf('[link:subscription_unsubscribe]') < 0) {
|
contents.indexOf('[link:subscription_unsubscribe]') < 0) {
|
||||||
@ -340,9 +341,11 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Module.beforeExitWithUnsavedChanges = function(e) {
|
Module.beforeExitWithUnsavedChanges = function(e) {
|
||||||
|
var message;
|
||||||
|
var event;
|
||||||
if (saveTimeout) {
|
if (saveTimeout) {
|
||||||
var message = MailPoet.I18n.t('unsavedChangesWillBeLost');
|
message = MailPoet.I18n.t('unsavedChangesWillBeLost');
|
||||||
var event = e || window.event;
|
event = e || window.event;
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
event.returnValue = message;
|
event.returnValue = message;
|
||||||
|
@ -23,7 +23,7 @@ define([
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Module = {};
|
var Module = {};
|
||||||
|
var SidebarView;
|
||||||
// Widget handlers for use to create new content blocks via drag&drop
|
// Widget handlers for use to create new content blocks via drag&drop
|
||||||
Module._contentWidgets = new (Backbone.Collection.extend({
|
Module._contentWidgets = new (Backbone.Collection.extend({
|
||||||
model: SuperModel.extend({
|
model: SuperModel.extend({
|
||||||
@ -52,7 +52,7 @@ define([
|
|||||||
Module.registerLayoutWidget = function (widget) { return Module._layoutWidgets.add(widget); };
|
Module.registerLayoutWidget = function (widget) { return Module._layoutWidgets.add(widget); };
|
||||||
Module.getLayoutWidgets = function () { return Module._layoutWidgets; };
|
Module.getLayoutWidgets = function () { return Module._layoutWidgets; };
|
||||||
|
|
||||||
var SidebarView = Marionette.View.extend({
|
SidebarView = Marionette.View.extend({
|
||||||
getTemplate: function() { return window.templates.sidebar; },
|
getTemplate: function() { return window.templates.sidebar; },
|
||||||
regions: {
|
regions: {
|
||||||
contentRegion: '.mailpoet_content_region',
|
contentRegion: '.mailpoet_content_region',
|
||||||
@ -266,11 +266,12 @@ define([
|
|||||||
}).always(function () {
|
}).always(function () {
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
|
var view;
|
||||||
this.previewView = new Module.NewsletterPreviewView({
|
this.previewView = new Module.NewsletterPreviewView({
|
||||||
previewUrl: response.meta.preview_url
|
previewUrl: response.meta.preview_url
|
||||||
});
|
});
|
||||||
|
|
||||||
var view = this.previewView.render();
|
view = this.previewView.render();
|
||||||
this.previewView.$el.css('height', '100%');
|
this.previewView.$el.css('height', '100%');
|
||||||
|
|
||||||
MailPoet.Modal.popup({
|
MailPoet.Modal.popup({
|
||||||
|
@ -71,13 +71,15 @@ define([
|
|||||||
|
|
||||||
App.on('before:start', function (App, options) {
|
App.on('before:start', function (App, options) {
|
||||||
var Application = App;
|
var Application = App;
|
||||||
|
var body;
|
||||||
|
var globalStyles;
|
||||||
// Expose style methods to global application
|
// Expose style methods to global application
|
||||||
Application.getGlobalStyles = Module.getGlobalStyles;
|
Application.getGlobalStyles = Module.getGlobalStyles;
|
||||||
Application.setGlobalStyles = Module.setGlobalStyles;
|
Application.setGlobalStyles = Module.setGlobalStyles;
|
||||||
Application.getAvailableStyles = Module.getAvailableStyles;
|
Application.getAvailableStyles = Module.getAvailableStyles;
|
||||||
|
|
||||||
var body = options.newsletter.body;
|
body = options.newsletter.body;
|
||||||
var globalStyles = (_.has(body, 'globalStyles')) ? body.globalStyles : {};
|
globalStyles = (_.has(body, 'globalStyles')) ? body.globalStyles : {};
|
||||||
this.setGlobalStyles(globalStyles);
|
this.setGlobalStyles(globalStyles);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -26,15 +26,17 @@ tinymce.PluginManager.add('mailpoet_shortcodes', function(editor, url) {
|
|||||||
onclick: function() {
|
onclick: function() {
|
||||||
var shortcodes = [];
|
var shortcodes = [];
|
||||||
var configShortcodes = editor.settings.mailpoet_shortcodes;
|
var configShortcodes = editor.settings.mailpoet_shortcodes;
|
||||||
|
var segment;
|
||||||
|
var i;
|
||||||
|
|
||||||
for (var segment in configShortcodes) {
|
for (segment in configShortcodes) {
|
||||||
if (configShortcodes.hasOwnProperty(segment)) {
|
if (configShortcodes.hasOwnProperty(segment)) {
|
||||||
shortcodes.push({
|
shortcodes.push({
|
||||||
type: 'label',
|
type: 'label',
|
||||||
text: segment
|
text: segment
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var i = 0; i < configShortcodes[segment].length; i += 1) {
|
for (i = 0; i < configShortcodes[segment].length; i += 1) {
|
||||||
shortcodes.push({
|
shortcodes.push({
|
||||||
type: 'button',
|
type: 'button',
|
||||||
text: configShortcodes[segment][i].text,
|
text: configShortcodes[segment][i].text,
|
||||||
|
@ -47,6 +47,8 @@ define('notice', ['mailpoet', 'jquery'], function (mp, jQuery) {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
createNotice: function() {
|
createNotice: function() {
|
||||||
|
var onClose;
|
||||||
|
var positionAfter;
|
||||||
// clone element
|
// clone element
|
||||||
this.element = jQuery('#mailpoet_notice_' + this.options.type).clone();
|
this.element = jQuery('#mailpoet_notice_' + this.options.type).clone();
|
||||||
|
|
||||||
@ -62,7 +64,6 @@ define('notice', ['mailpoet', 'jquery'], function (mp, jQuery) {
|
|||||||
this.element.removeAttr('id');
|
this.element.removeAttr('id');
|
||||||
|
|
||||||
// insert notice after its parent
|
// insert notice after its parent
|
||||||
var positionAfter;
|
|
||||||
if (typeof this.options.positionAfter === 'object') {
|
if (typeof this.options.positionAfter === 'object') {
|
||||||
positionAfter = this.options.positionAfter;
|
positionAfter = this.options.positionAfter;
|
||||||
} else if (typeof this.options.positionAfter === 'string') {
|
} else if (typeof this.options.positionAfter === 'string') {
|
||||||
@ -73,7 +74,7 @@ define('notice', ['mailpoet', 'jquery'], function (mp, jQuery) {
|
|||||||
positionAfter.after(this.element);
|
positionAfter.after(this.element);
|
||||||
|
|
||||||
// setup onClose callback
|
// setup onClose callback
|
||||||
var onClose = null;
|
onClose = null;
|
||||||
if (this.options.onClose !== null) {
|
if (this.options.onClose !== null) {
|
||||||
onClose = this.options.onClose;
|
onClose = this.options.onClose;
|
||||||
}
|
}
|
||||||
@ -177,12 +178,13 @@ define('notice', ['mailpoet', 'jquery'], function (mp, jQuery) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
hide: function(all) {
|
hide: function(all) {
|
||||||
|
var id;
|
||||||
if (all !== undefined && all === true) {
|
if (all !== undefined && all === true) {
|
||||||
// all notices
|
// all notices
|
||||||
jQuery('.mailpoet_notice:not([id])').trigger('close');
|
jQuery('.mailpoet_notice:not([id])').trigger('close');
|
||||||
} else if (all !== undefined && jQuery.isArray(all)) {
|
} else if (all !== undefined && jQuery.isArray(all)) {
|
||||||
// array of ids
|
// array of ids
|
||||||
for (var id in all) {
|
for (id in all) {
|
||||||
jQuery('[data-id="' + all[id] + '"]').trigger('close');
|
jQuery('[data-id="' + all[id] + '"]').trigger('close');
|
||||||
}
|
}
|
||||||
} if (all !== undefined) {
|
} if (all !== undefined) {
|
||||||
|
@ -5,7 +5,7 @@ define(
|
|||||||
function (
|
function (
|
||||||
MailPoet
|
MailPoet
|
||||||
) {
|
) {
|
||||||
|
var element;
|
||||||
function eventHandler() {
|
function eventHandler() {
|
||||||
if (confirm(MailPoet.I18n.t('reinstallConfirmation'))) {
|
if (confirm(MailPoet.I18n.t('reinstallConfirmation'))) {
|
||||||
MailPoet.trackEvent(
|
MailPoet.trackEvent(
|
||||||
@ -36,7 +36,7 @@ define(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var element = document.getElementById('mailpoet_reinstall');
|
element = document.getElementById('mailpoet_reinstall');
|
||||||
if (element) {
|
if (element) {
|
||||||
element.addEventListener('click', eventHandler, false);
|
element.addEventListener('click', eventHandler, false);
|
||||||
}
|
}
|
||||||
|
@ -17,22 +17,29 @@ define(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jQuery(document).ready(function () {
|
jQuery(document).ready(function () {
|
||||||
|
var segmentsContainerElement;
|
||||||
|
var subscriberFieldsContainerElement;
|
||||||
|
var exportConfirmedOptionElement;
|
||||||
|
var groupBySegmentOptionElement;
|
||||||
|
var nextStepButton;
|
||||||
|
var renderSegmentsAndFields;
|
||||||
|
var subscribers_export_template;
|
||||||
if (!window.exportData.segments) {
|
if (!window.exportData.segments) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var subscribers_export_template =
|
subscribers_export_template =
|
||||||
Handlebars.compile(jQuery('#mailpoet_subscribers_export_template').html());
|
Handlebars.compile(jQuery('#mailpoet_subscribers_export_template').html());
|
||||||
|
|
||||||
// render template
|
// render template
|
||||||
jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(window.exportData));
|
jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(window.exportData));
|
||||||
|
|
||||||
// define reusable variables
|
// define reusable variables
|
||||||
var segmentsContainerElement = jQuery('#export_lists');
|
segmentsContainerElement = jQuery('#export_lists');
|
||||||
var subscriberFieldsContainerElement = jQuery('#export_columns');
|
subscriberFieldsContainerElement = jQuery('#export_columns');
|
||||||
var exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]');
|
exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]');
|
||||||
var groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]');
|
groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]');
|
||||||
var nextStepButton = jQuery('a.mailpoet_export_process');
|
nextStepButton = jQuery('a.mailpoet_export_process');
|
||||||
var renderSegmentsAndFields = function (container, data) {
|
renderSegmentsAndFields = function (container, data) {
|
||||||
if (container.data('select2')) {
|
if (container.data('select2')) {
|
||||||
container
|
container
|
||||||
.html('')
|
.html('')
|
||||||
@ -60,12 +67,13 @@ define(
|
|||||||
'select',
|
'select',
|
||||||
'deselect'
|
'deselect'
|
||||||
];
|
];
|
||||||
|
var allOptions;
|
||||||
if (_.contains(fieldsToExclude, selectedOptionId)) {
|
if (_.contains(fieldsToExclude, selectedOptionId)) {
|
||||||
selectEvent.preventDefault();
|
selectEvent.preventDefault();
|
||||||
if (selectedOptionId === 'deselect') {
|
if (selectedOptionId === 'deselect') {
|
||||||
jQuery(selectElement).val('').trigger('change');
|
jQuery(selectElement).val('').trigger('change');
|
||||||
} else {
|
} else {
|
||||||
var allOptions = [];
|
allOptions = [];
|
||||||
_.each(container.find('option'), function (field) {
|
_.each(container.find('option'), function (field) {
|
||||||
if (!_.contains(fieldsToExclude, field.value)) {
|
if (!_.contains(fieldsToExclude, field.value)) {
|
||||||
allOptions.push(field.value);
|
allOptions.push(field.value);
|
||||||
@ -133,11 +141,12 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
nextStepButton.click(function () {
|
nextStepButton.click(function () {
|
||||||
|
var exportFormat;
|
||||||
if (jQuery(this).hasClass('button-disabled')) {
|
if (jQuery(this).hasClass('button-disabled')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
var exportFormat = jQuery(':radio[name="option_format"]:checked').val();
|
exportFormat = jQuery(':radio[name="option_format"]:checked').val();
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
api_version: window.mailpoet_api_version,
|
api_version: window.mailpoet_api_version,
|
||||||
endpoint: 'ImportExport',
|
endpoint: 'ImportExport',
|
||||||
|
@ -25,9 +25,10 @@ define(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jQuery(document).ready(function () {
|
jQuery(document).ready(function () {
|
||||||
|
var router;
|
||||||
jQuery('input[name="select_method"]').attr('checked', false);
|
jQuery('input[name="select_method"]').attr('checked', false);
|
||||||
// configure router
|
// configure router
|
||||||
var router = new (Backbone.Router.extend({
|
router = new (Backbone.Router.extend({
|
||||||
routes: {
|
routes: {
|
||||||
'': 'home',
|
'': 'home',
|
||||||
step1: 'step1',
|
step1: 'step1',
|
||||||
@ -50,6 +51,18 @@ define(
|
|||||||
* STEP 1 (upload or copy/paste)
|
* STEP 1 (upload or copy/paste)
|
||||||
*/
|
*/
|
||||||
router.on('route:step1', function () {
|
router.on('route:step1', function () {
|
||||||
|
var methodProcessContainerTemplate;
|
||||||
|
var currentStepE;
|
||||||
|
var methodSelectionElement;
|
||||||
|
var pasteInputElement;
|
||||||
|
var pasteInputPlaceholderElement;
|
||||||
|
var pasteProcessButtonElement;
|
||||||
|
var mailChimpKeyInputElement;
|
||||||
|
var mailChimpKeyVerifyButtonElement;
|
||||||
|
var mailChimpListsContainerElement;
|
||||||
|
var mailChimpProcessButtonElement;
|
||||||
|
var uploadElement;
|
||||||
|
var uploadProcessButtonElement;
|
||||||
// set or reset temporary validation rule on all columns
|
// set or reset temporary validation rule on all columns
|
||||||
window.mailpoetColumns = jQuery.map(window.mailpoetColumns, function (column, columnIndex) {
|
window.mailpoetColumns = jQuery.map(window.mailpoetColumns, function (column, columnIndex) {
|
||||||
var col = column;
|
var col = column;
|
||||||
@ -63,34 +76,34 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// render process button for each method
|
// render process button for each method
|
||||||
var methodProcessContainerTemplate =
|
methodProcessContainerTemplate =
|
||||||
Handlebars.compile(jQuery('#method_process_template').html());
|
Handlebars.compile(jQuery('#method_process_template').html());
|
||||||
jQuery('.mailpoet_method_process').html(methodProcessContainerTemplate());
|
jQuery('.mailpoet_method_process').html(methodProcessContainerTemplate());
|
||||||
|
|
||||||
// define reusable variables
|
// define reusable variables
|
||||||
var currentStepE = jQuery(location.hash);
|
currentStepE = jQuery(location.hash);
|
||||||
var methodSelectionElement = jQuery('#select_method');
|
methodSelectionElement = jQuery('#select_method');
|
||||||
var pasteInputElement = jQuery('#paste_input');
|
pasteInputElement = jQuery('#paste_input');
|
||||||
var pasteInputPlaceholderElement =
|
pasteInputPlaceholderElement =
|
||||||
pasteInputElement.data('placeholder').replace(/\\n/g, '\n');
|
pasteInputElement.data('placeholder').replace(/\\n/g, '\n');
|
||||||
var pasteProcessButtonElement =
|
pasteProcessButtonElement =
|
||||||
jQuery('#method_paste > div.mailpoet_method_process')
|
jQuery('#method_paste > div.mailpoet_method_process')
|
||||||
.find('a.mailpoet_process');
|
.find('a.mailpoet_process');
|
||||||
var mailChimpKeyInputElement = jQuery('#mailchimp_key');
|
mailChimpKeyInputElement = jQuery('#mailchimp_key');
|
||||||
var mailChimpKeyVerifyButtonElement = jQuery('#mailchimp_key_verify');
|
mailChimpKeyVerifyButtonElement = jQuery('#mailchimp_key_verify');
|
||||||
var mailChimpListsContainerElement = jQuery('#mailchimp_lists');
|
mailChimpListsContainerElement = jQuery('#mailchimp_lists');
|
||||||
var mailChimpProcessButtonElement = jQuery('#method_mailchimp > div.mailpoet_method_process')
|
mailChimpProcessButtonElement = jQuery('#method_mailchimp > div.mailpoet_method_process')
|
||||||
.find('a.mailpoet_process');
|
.find('a.mailpoet_process');
|
||||||
var uploadElement = jQuery('#file_local');
|
uploadElement = jQuery('#file_local');
|
||||||
var uploadProcessButtonElement =
|
uploadProcessButtonElement =
|
||||||
jQuery('#method_file > div.mailpoet_method_process')
|
jQuery('#method_file > div.mailpoet_method_process')
|
||||||
.find('a.mailpoet_process');
|
.find('a.mailpoet_process');
|
||||||
|
|
||||||
// define method change behavior
|
// define method change behavior
|
||||||
methodSelectionElement.change(function () {
|
methodSelectionElement.change(function () {
|
||||||
MailPoet.Notice.hide();
|
|
||||||
var available_methods = jQuery(':radio[name="select_method"]');
|
var available_methods = jQuery(':radio[name="select_method"]');
|
||||||
var selected_method = available_methods.index(available_methods.filter(':checked'));
|
var selected_method = available_methods.index(available_methods.filter(':checked'));
|
||||||
|
MailPoet.Notice.hide();
|
||||||
// hide all methods
|
// hide all methods
|
||||||
currentStepE.find('.inside')
|
currentStepE.find('.inside')
|
||||||
.children('div[id^="method_"]')
|
.children('div[id^="method_"]')
|
||||||
@ -129,9 +142,9 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
pasteProcessButtonElement.click(function () {
|
pasteProcessButtonElement.click(function () {
|
||||||
|
var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1;
|
||||||
MailPoet.Notice.hide();
|
MailPoet.Notice.hide();
|
||||||
// get an approximate size of textarea paste in bytes
|
// get an approximate size of textarea paste in bytes
|
||||||
var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1;
|
|
||||||
if (pasteSize > window.maxPostSizeBytes) {
|
if (pasteSize > window.maxPostSizeBytes) {
|
||||||
MailPoet.Notice.error(MailPoet.I18n.t('maxPostSizeNotice'));
|
MailPoet.Notice.error(MailPoet.I18n.t('maxPostSizeNotice'));
|
||||||
return;
|
return;
|
||||||
@ -147,8 +160,8 @@ define(
|
|||||||
* CSV file
|
* CSV file
|
||||||
*/
|
*/
|
||||||
uploadElement.change(function () {
|
uploadElement.change(function () {
|
||||||
MailPoet.Notice.hide();
|
|
||||||
var ext = this.value.match(/\.(.+)$/);
|
var ext = this.value.match(/\.(.+)$/);
|
||||||
|
MailPoet.Notice.hide();
|
||||||
if (ext === null || ext[1].toLowerCase() !== 'csv') {
|
if (ext === null || ext[1].toLowerCase() !== 'csv') {
|
||||||
this.value = '';
|
this.value = '';
|
||||||
MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
|
MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
|
||||||
@ -345,11 +358,18 @@ define(
|
|||||||
MailPoet.Notice.error(MailPoet.I18n.t('dataProcessingError'));
|
MailPoet.Notice.error(MailPoet.I18n.t('dataProcessingError'));
|
||||||
},
|
},
|
||||||
complete: function (CSV) {
|
complete: function (CSV) {
|
||||||
for (var rowCount in CSV.data) {
|
var email;
|
||||||
var rowData = CSV.data[rowCount].map(function (el) {
|
var emailAddress;
|
||||||
|
var column;
|
||||||
|
var rowCount;
|
||||||
|
var rowData;
|
||||||
|
var rowColumnCount;
|
||||||
|
var errorNotice;
|
||||||
|
for (rowCount in CSV.data) {
|
||||||
|
rowData = CSV.data[rowCount].map(function (el) {
|
||||||
return el.trim();
|
return el.trim();
|
||||||
});
|
});
|
||||||
var rowColumnCount = rowData.length;
|
rowColumnCount = rowData.length;
|
||||||
// set the number of row elements based on the first non-empty row
|
// set the number of row elements based on the first non-empty row
|
||||||
if (columnCount === null) {
|
if (columnCount === null) {
|
||||||
columnCount = rowColumnCount;
|
columnCount = rowColumnCount;
|
||||||
@ -363,8 +383,8 @@ define(
|
|||||||
// determine position of email address inside an array; this is
|
// determine position of email address inside an array; this is
|
||||||
// done once and then email regex is run just on that element for each row
|
// done once and then email regex is run just on that element for each row
|
||||||
if (emailColumnPosition === null) {
|
if (emailColumnPosition === null) {
|
||||||
for (var column in rowData) {
|
for (column in rowData) {
|
||||||
var emailAddress = detectAndCleanupEmail(rowData[column]);
|
emailAddress = detectAndCleanupEmail(rowData[column]);
|
||||||
if (emailColumnPosition === null
|
if (emailColumnPosition === null
|
||||||
&& window.emailRegex.test(emailAddress)) {
|
&& window.emailRegex.test(emailAddress)) {
|
||||||
emailColumnPosition = column;
|
emailColumnPosition = column;
|
||||||
@ -381,7 +401,7 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (rowData[emailColumnPosition] !== '') {
|
else if (rowData[emailColumnPosition] !== '') {
|
||||||
var email = detectAndCleanupEmail(rowData[emailColumnPosition]);
|
email = detectAndCleanupEmail(rowData[emailColumnPosition]);
|
||||||
if (_.has(parsedEmails, email)) {
|
if (_.has(parsedEmails, email)) {
|
||||||
duplicateEmails.push(email);
|
duplicateEmails.push(email);
|
||||||
}
|
}
|
||||||
@ -425,7 +445,7 @@ define(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
var errorNotice = MailPoet.I18n.t('noValidRecords');
|
errorNotice = MailPoet.I18n.t('noValidRecords');
|
||||||
errorNotice = errorNotice.replace('[link]', MailPoet.I18n.t('csvKBLink'));
|
errorNotice = errorNotice.replace('[link]', MailPoet.I18n.t('csvKBLink'));
|
||||||
errorNotice = errorNotice.replace('[/link]', '</a>');
|
errorNotice = errorNotice.replace('[/link]', '</a>');
|
||||||
MailPoet.Notice.error(errorNotice);
|
MailPoet.Notice.error(errorNotice);
|
||||||
@ -436,28 +456,41 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.on('route:step2', function () {
|
router.on('route:step2', function () {
|
||||||
|
var nextStepButton;
|
||||||
|
var previousStepButton;
|
||||||
|
var subscribers;
|
||||||
|
var subscribersDataTemplate;
|
||||||
|
var subscribersDataTemplatePartial;
|
||||||
|
var subscribersDataParseResultsTemplate;
|
||||||
|
var segmentSelectElement;
|
||||||
|
var maxRowsToShow;
|
||||||
|
var filler;
|
||||||
|
var fillerArray;
|
||||||
|
var fillerPosition;
|
||||||
|
var import_results;
|
||||||
|
var duplicates;
|
||||||
|
var email;
|
||||||
if (typeof (window.importData.step1) === 'undefined') {
|
if (typeof (window.importData.step1) === 'undefined') {
|
||||||
router.navigate('step1', { trigger: true });
|
router.navigate('step1', { trigger: true });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// define reusable variables
|
// define reusable variables
|
||||||
var nextStepButton = jQuery('#step2_process');
|
nextStepButton = jQuery('#step2_process');
|
||||||
var previousStepButton = jQuery('#return_to_step1');
|
previousStepButton = jQuery('#return_to_step1');
|
||||||
// create a copy of subscribers object for further manipulation
|
// create a copy of subscribers object for further manipulation
|
||||||
var subscribers = jQuery.extend(true, {}, window.importData.step1);
|
subscribers = jQuery.extend(true, {}, window.importData.step1);
|
||||||
var subscribersDataTemplate = Handlebars.compile(jQuery('#subscribers_data_template').html());
|
subscribersDataTemplate = Handlebars.compile(jQuery('#subscribers_data_template').html());
|
||||||
var subscribersDataTemplatePartial = Handlebars.compile(jQuery('#subscribers_data_template_partial').html());
|
subscribersDataTemplatePartial = Handlebars.compile(jQuery('#subscribers_data_template_partial').html());
|
||||||
var subscribersDataParseResultsTemplate = Handlebars.compile(jQuery('#subscribers_data_parse_results_template').html());
|
subscribersDataParseResultsTemplate = Handlebars.compile(jQuery('#subscribers_data_parse_results_template').html());
|
||||||
var segmentSelectElement = jQuery('#mailpoet_segments_select');
|
segmentSelectElement = jQuery('#mailpoet_segments_select');
|
||||||
var maxRowsToShow = 10;
|
maxRowsToShow = 10;
|
||||||
var filler = '. . .';
|
filler = '. . .';
|
||||||
// create an array of filler data with the same number of
|
// create an array of filler data with the same number of
|
||||||
// elements as in the subscribers' data row
|
// elements as in the subscribers' data row
|
||||||
var fillerArray = Array.apply(
|
fillerArray = Array.apply(
|
||||||
null,
|
null,
|
||||||
new Array(subscribers.subscribers[0].length)
|
new Array(subscribers.subscribers[0].length)
|
||||||
).map(String.prototype.valueOf, filler);
|
).map(String.prototype.valueOf, filler);
|
||||||
var fillerPosition;
|
|
||||||
|
|
||||||
showCurrentStep();
|
showCurrentStep();
|
||||||
|
|
||||||
@ -469,12 +502,12 @@ define(
|
|||||||
if (subscribers.invalid.length || subscribers.duplicate.length) {
|
if (subscribers.invalid.length || subscribers.duplicate.length) {
|
||||||
// count repeating e-mails inside duplicate array and present them in
|
// count repeating e-mails inside duplicate array and present them in
|
||||||
// 'email (xN)' format
|
// 'email (xN)' format
|
||||||
var duplicates = {};
|
duplicates = {};
|
||||||
subscribers.duplicate.forEach(function (email) {
|
subscribers.duplicate.forEach(function (email) {
|
||||||
duplicates[email] = (duplicates[email] || 0) + 1;
|
duplicates[email] = (duplicates[email] || 0) + 1;
|
||||||
});
|
});
|
||||||
subscribers.duplicate = [];
|
subscribers.duplicate = [];
|
||||||
for (var email in duplicates) {
|
for (email in duplicates) {
|
||||||
if (duplicates[email] > 1) {
|
if (duplicates[email] > 1) {
|
||||||
subscribers.duplicate.push(email + ' (x' + duplicates[email] + ')');
|
subscribers.duplicate.push(email + ' (x' + duplicates[email] + ')');
|
||||||
}
|
}
|
||||||
@ -483,7 +516,7 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var import_results = {
|
import_results = {
|
||||||
notice: MailPoet.I18n.t('importNoticeSkipped').replace(
|
notice: MailPoet.I18n.t('importNoticeSkipped').replace(
|
||||||
'%1$s',
|
'%1$s',
|
||||||
'<strong>' + (subscribers.invalid.length + subscribers.duplicate.length) + '</strong>'
|
'<strong>' + (subscribers.invalid.length + subscribers.duplicate.length) + '</strong>'
|
||||||
@ -588,13 +621,14 @@ define(
|
|||||||
description: segmentDescription
|
description: segmentDescription
|
||||||
}
|
}
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
|
var selected_values;
|
||||||
window.mailpoetSegments.push({
|
window.mailpoetSegments.push({
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
name: response.data.name,
|
name: response.data.name,
|
||||||
subscriberCount: 0
|
subscriberCount: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
var selected_values = segmentSelectElement.val();
|
selected_values = segmentSelectElement.val();
|
||||||
if (selected_values === null) {
|
if (selected_values === null) {
|
||||||
selected_values = [response.data.id];
|
selected_values = [response.data.id];
|
||||||
} else {
|
} else {
|
||||||
@ -633,16 +667,21 @@ define(
|
|||||||
function (subscribers, options) {
|
function (subscribers, options) {
|
||||||
var displayedColumns = [];
|
var displayedColumns = [];
|
||||||
var displayedColumnsIds = [];
|
var displayedColumnsIds = [];
|
||||||
|
var i;
|
||||||
|
var columnData;
|
||||||
|
var columnId;
|
||||||
|
var headerName;
|
||||||
|
var headerNameMatch;
|
||||||
// go through all elements of the first row in subscribers data
|
// go through all elements of the first row in subscribers data
|
||||||
for (var i in subscribers.subscribers[0]) {
|
for (i in subscribers.subscribers[0]) {
|
||||||
var columnData = subscribers.subscribers[0][i];
|
columnData = subscribers.subscribers[0][i];
|
||||||
var columnId = 'ignore'; // set default column type
|
columnId = 'ignore'; // set default column type
|
||||||
// if the column is not undefined and has a valid e-mail, set type as email
|
// if the column is not undefined and has a valid e-mail, set type as email
|
||||||
if (columnData % 1 !== 0 && window.emailRegex.test(columnData)) {
|
if (columnData % 1 !== 0 && window.emailRegex.test(columnData)) {
|
||||||
columnId = 'email';
|
columnId = 'email';
|
||||||
} else if (subscribers.header) {
|
} else if (subscribers.header) {
|
||||||
var headerName = subscribers.header[i];
|
headerName = subscribers.header[i];
|
||||||
var headerNameMatch = window.mailpoetColumns.map(function (el) {
|
headerNameMatch = window.mailpoetColumns.map(function (el) {
|
||||||
return el.name;
|
return el.name;
|
||||||
}).indexOf(headerName);
|
}).indexOf(headerName);
|
||||||
// set column type using header
|
// set column type using header
|
||||||
@ -821,12 +860,13 @@ define(
|
|||||||
|
|
||||||
// filter subscribers' data to detect dates, emails, etc.
|
// filter subscribers' data to detect dates, emails, etc.
|
||||||
function filterSubscribers() {
|
function filterSubscribers() {
|
||||||
|
var subscribersClone = jQuery.extend(true, {}, subscribers);
|
||||||
|
var preventNextStep = false;
|
||||||
|
var displayedColumns;
|
||||||
jQuery(
|
jQuery(
|
||||||
'[data-id="notice_invalidEmail"], [data-id="notice_invalidDate"]')
|
'[data-id="notice_invalidEmail"], [data-id="notice_invalidDate"]')
|
||||||
.remove();
|
.remove();
|
||||||
var subscribersClone = jQuery.extend(true, {}, subscribers);
|
displayedColumns = jQuery.map(
|
||||||
var preventNextStep = false;
|
|
||||||
var displayedColumns = jQuery.map(
|
|
||||||
jQuery('.mailpoet_subscribers_column_data_match'), function (element, elementIndex) {
|
jQuery('.mailpoet_subscribers_column_data_match'), function (element, elementIndex) {
|
||||||
var columnId = jQuery(element).data('column-id');
|
var columnId = jQuery(element).data('column-id');
|
||||||
var validationRule = jQuery(element).data('validation-rule');
|
var validationRule = jQuery(element).data('validation-rule');
|
||||||
@ -835,6 +875,11 @@ define(
|
|||||||
});
|
});
|
||||||
// iterate through the object of mailpoet columns
|
// iterate through the object of mailpoet columns
|
||||||
jQuery.map(window.mailpoetColumns, function (column, columnIndex) {
|
jQuery.map(window.mailpoetColumns, function (column, columnIndex) {
|
||||||
|
var firstRowData;
|
||||||
|
var validationRule;
|
||||||
|
var testedFormat;
|
||||||
|
var format;
|
||||||
|
var allowedDateFormats;
|
||||||
// check if the column id matches the selected id of one of the
|
// check if the column id matches the selected id of one of the
|
||||||
// subscriber's data columns
|
// subscriber's data columns
|
||||||
var matchedColumn = _.find(displayedColumns, function (data) { return data.id === column.id; });
|
var matchedColumn = _.find(displayedColumns, function (data) { return data.id === column.id; });
|
||||||
@ -858,7 +903,7 @@ define(
|
|||||||
}
|
}
|
||||||
// DATE filter: if column type is date, check if we can recognize it
|
// DATE filter: if column type is date, check if we can recognize it
|
||||||
if (column.type === 'date' && matchedColumn) {
|
if (column.type === 'date' && matchedColumn) {
|
||||||
var allowedDateFormats = [
|
allowedDateFormats = [
|
||||||
Moment.ISO_8601,
|
Moment.ISO_8601,
|
||||||
'YYYY/MM/DD',
|
'YYYY/MM/DD',
|
||||||
'MM/DD/YYYY',
|
'MM/DD/YYYY',
|
||||||
@ -869,9 +914,8 @@ define(
|
|||||||
'YYYY/MM',
|
'YYYY/MM',
|
||||||
'YYYY'
|
'YYYY'
|
||||||
];
|
];
|
||||||
var firstRowData = subscribersClone.subscribers[0][matchedColumn.index];
|
firstRowData = subscribersClone.subscribers[0][matchedColumn.index];
|
||||||
var validationRule = false;
|
validationRule = false;
|
||||||
var testedFormat;
|
|
||||||
// check if date exists
|
// check if date exists
|
||||||
if (firstRowData.trim() === '') {
|
if (firstRowData.trim() === '') {
|
||||||
subscribersClone.subscribers[0][matchedColumn.index] =
|
subscribersClone.subscribers[0][matchedColumn.index] =
|
||||||
@ -882,7 +926,7 @@ define(
|
|||||||
preventNextStep = true;
|
preventNextStep = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (var format in allowedDateFormats) {
|
for (format in allowedDateFormats) {
|
||||||
testedFormat = allowedDateFormats[format];
|
testedFormat = allowedDateFormats[format];
|
||||||
if (Moment(firstRowData, testedFormat, true).isValid()) {
|
if (Moment(firstRowData, testedFormat, true).isValid()) {
|
||||||
validationRule = (typeof(testedFormat) === 'function') ?
|
validationRule = (typeof(testedFormat) === 'function') ?
|
||||||
@ -900,8 +944,8 @@ define(
|
|||||||
jQuery.map(subscribersClone.subscribers, function (dataSubscribers, index) {
|
jQuery.map(subscribersClone.subscribers, function (dataSubscribers, index) {
|
||||||
var data = dataSubscribers;
|
var data = dataSubscribers;
|
||||||
var rowData = data[matchedColumn.index];
|
var rowData = data[matchedColumn.index];
|
||||||
if (index === fillerPosition || rowData.trim() === '') return;
|
|
||||||
var date = Moment(rowData, testedFormat, true);
|
var date = Moment(rowData, testedFormat, true);
|
||||||
|
if (index === fillerPosition || rowData.trim() === '') return;
|
||||||
// validate date
|
// validate date
|
||||||
if (date.isValid()) {
|
if (date.isValid()) {
|
||||||
data[matchedColumn.index] = new Handlebars.SafeString(
|
data[matchedColumn.index] = new Handlebars.SafeString(
|
||||||
@ -960,11 +1004,6 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
nextStepButton.off().on('click', function () {
|
nextStepButton.off().on('click', function () {
|
||||||
if (jQuery(this).hasClass('button-disabled')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MailPoet.Modal.loading(true);
|
|
||||||
|
|
||||||
var columns = {};
|
var columns = {};
|
||||||
var queue = new jQuery.AsyncQueue();
|
var queue = new jQuery.AsyncQueue();
|
||||||
var batchNumber = 0;
|
var batchNumber = 0;
|
||||||
@ -977,7 +1016,14 @@ define(
|
|||||||
errors: [],
|
errors: [],
|
||||||
segments: []
|
segments: []
|
||||||
};
|
};
|
||||||
var splitSubscribers = function (subscribers, size) {
|
var subscribers;
|
||||||
|
var splitSubscribers;
|
||||||
|
|
||||||
|
if (jQuery(this).hasClass('button-disabled')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MailPoet.Modal.loading(true);
|
||||||
|
splitSubscribers = function (subscribers, size) {
|
||||||
return subscribers.reduce(function (res, item, index) {
|
return subscribers.reduce(function (res, item, index) {
|
||||||
if (index % size === 0) {
|
if (index % size === 0) {
|
||||||
res.push([]);
|
res.push([]);
|
||||||
@ -986,7 +1032,7 @@ define(
|
|||||||
return res;
|
return res;
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
var subscribers = splitSubscribers(window.importData.step1.subscribers, batchSize);
|
subscribers = splitSubscribers(window.importData.step1.subscribers, batchSize);
|
||||||
|
|
||||||
_.each(jQuery('select.mailpoet_subscribers_column_data_match'),
|
_.each(jQuery('select.mailpoet_subscribers_column_data_match'),
|
||||||
function (column, columnIndex) {
|
function (column, columnIndex) {
|
||||||
@ -1057,6 +1103,9 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.on('route:step3', function () {
|
router.on('route:step3', function () {
|
||||||
|
var subscribersDataImportResultsTemplate;
|
||||||
|
var exportMenuElement;
|
||||||
|
var importResults;
|
||||||
if (typeof (window.importData.step2) === 'undefined') {
|
if (typeof (window.importData.step2) === 'undefined') {
|
||||||
router.navigate('step2', { trigger: true });
|
router.navigate('step2', { trigger: true });
|
||||||
return;
|
return;
|
||||||
@ -1075,10 +1124,10 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// display statistics
|
// display statistics
|
||||||
var subscribersDataImportResultsTemplate =
|
subscribersDataImportResultsTemplate =
|
||||||
Handlebars.compile(jQuery('#subscribers_data_import_results_template').html());
|
Handlebars.compile(jQuery('#subscribers_data_import_results_template').html());
|
||||||
var exportMenuElement = jQuery('span.mailpoet_export');
|
exportMenuElement = jQuery('span.mailpoet_export');
|
||||||
var importResults = {
|
importResults = {
|
||||||
created: (window.importData.step2.created)
|
created: (window.importData.step2.created)
|
||||||
? MailPoet.I18n.t('subscribersCreated')
|
? MailPoet.I18n.t('subscribersCreated')
|
||||||
.replace('%1$s', '<strong>' + window.importData.step2.created.toLocaleString() + '</strong>')
|
.replace('%1$s', '<strong>' + window.importData.step2.created.toLocaleString() + '</strong>')
|
||||||
|
Reference in New Issue
Block a user