Save newsletter before sending preview [MAILPOET-702]
This commit is contained in:
@ -40,7 +40,7 @@ define([
|
|||||||
App.getChannel().trigger('beforeEditorSave', json);
|
App.getChannel().trigger('beforeEditorSave', json);
|
||||||
|
|
||||||
// save newsletter
|
// save newsletter
|
||||||
CommunicationComponent.saveNewsletter(json).done(function(response) {
|
return CommunicationComponent.saveNewsletter(json).done(function(response) {
|
||||||
if(response.success !== undefined && response.success === true) {
|
if(response.success !== undefined && response.success === true) {
|
||||||
// TODO: Handle translations
|
// TODO: Handle translations
|
||||||
//MailPoet.Notice.success("<?php _e('Newsletter has been saved.'); ?>");
|
//MailPoet.Notice.success("<?php _e('Newsletter has been saved.'); ?>");
|
||||||
@ -66,6 +66,14 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// For getting a promise after triggering save event
|
||||||
|
Module.saveAndProvidePromise = function(saveResult) {
|
||||||
|
var promise = Module.save();
|
||||||
|
if (saveResult !== undefined) {
|
||||||
|
saveResult.promise = promise;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Module.getThumbnail = function(element, options) {
|
Module.getThumbnail = function(element, options) {
|
||||||
var promise = html2canvas(element, options || {});
|
var promise = html2canvas(element, options || {});
|
||||||
|
|
||||||
@ -335,12 +343,12 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
App.on('before:start', function(options) {
|
App.on('before:start', function(options) {
|
||||||
App.save = Module.save;
|
App.save = Module.saveAndProvidePromise;
|
||||||
App.getChannel().on('autoSave', Module.autoSave);
|
App.getChannel().on('autoSave', Module.autoSave);
|
||||||
|
|
||||||
window.onbeforeunload = Module.beforeExitWithUnsavedChanges;
|
window.onbeforeunload = Module.beforeExitWithUnsavedChanges;
|
||||||
|
|
||||||
App.getChannel().on('save', function() { App.save(); });
|
App.getChannel().on('save', function(saveResult) { App.save(saveResult); });
|
||||||
});
|
});
|
||||||
|
|
||||||
App.on('start', function(options) {
|
App.on('start', function(options) {
|
||||||
|
@ -301,6 +301,11 @@ define([
|
|||||||
// send test email
|
// send test email
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
|
|
||||||
|
// save before sending
|
||||||
|
var saveResult = {promise: null};
|
||||||
|
App.getChannel().trigger('save', saveResult);
|
||||||
|
|
||||||
|
saveResult.promise.always(function() {
|
||||||
CommunicationComponent.previewNewsletter(data).always(function() {
|
CommunicationComponent.previewNewsletter(data).always(function() {
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
@ -315,6 +320,7 @@ define([
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -90,6 +90,16 @@ define([
|
|||||||
|
|
||||||
mock.verify();
|
mock.verify();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('provides a promise if a result container is passed to save event', function() {
|
||||||
|
var spy = sinon.spy(module, 'save'),
|
||||||
|
saveResult = {promise: null};
|
||||||
|
module.saveAndProvidePromise(saveResult);
|
||||||
|
spy.restore();
|
||||||
|
expect(spy.calledOnce).to.be.true;
|
||||||
|
expect(saveResult.promise).to.be.an('object');
|
||||||
|
expect(saveResult.promise.then).to.be.a('function');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('view', function() {
|
describe('view', function() {
|
||||||
|
Reference in New Issue
Block a user