Hook up newsletter editor saving
This commit is contained in:
@ -45,10 +45,10 @@ define([
|
|||||||
|
|
||||||
Module.toJSON = function() {
|
Module.toJSON = function() {
|
||||||
return _.extend({
|
return _.extend({
|
||||||
body: {
|
body: JSON.stringify({
|
||||||
content: App._contentContainer.toJSON(),
|
content: App._contentContainer.toJSON(),
|
||||||
globalStyles: App.getGlobalStyles().toJSON(),
|
globalStyles: App.getGlobalStyles().toJSON(),
|
||||||
},
|
}),
|
||||||
}, App.getNewsletter().toJSON());
|
}, App.getNewsletter().toJSON());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,7 +69,8 @@ define([
|
|||||||
|
|
||||||
App.on('start', function(options) {
|
App.on('start', function(options) {
|
||||||
// TODO: Other newsletter information will be needed as well.
|
// TODO: Other newsletter information will be needed as well.
|
||||||
App._contentContainer = new (this.getBlockTypeModel('container'))(options.newsletter.body.content, {parse: true});
|
var body = JSON.parse(options.newsletter.body);
|
||||||
|
App._contentContainer = new (this.getBlockTypeModel('container'))(body.content, {parse: true});
|
||||||
App._contentContainerView = new (this.getBlockTypeView('container'))({
|
App._contentContainerView = new (this.getBlockTypeView('container'))({
|
||||||
model: App._contentContainer,
|
model: App._contentContainer,
|
||||||
renderOptions: { depth: 0 },
|
renderOptions: { depth: 0 },
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
define([
|
define([
|
||||||
'newsletter_editor/App',
|
'newsletter_editor/App',
|
||||||
'newsletter_editor/components/wordpress',
|
'mailpoet',
|
||||||
'backbone',
|
'backbone',
|
||||||
'backbone.marionette'
|
'backbone.marionette'
|
||||||
], function(App, Wordpress, Backbone, Marionette) {
|
], function(App, MailPoet, Backbone, Marionette) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -17,7 +17,11 @@ define([
|
|||||||
var json = App.toJSON();
|
var json = App.toJSON();
|
||||||
|
|
||||||
// save newsletter
|
// save newsletter
|
||||||
Wordpress.saveNewsletter(json).done(function(response) {
|
MailPoet.Ajax.post({
|
||||||
|
endpoint: 'newsletters',
|
||||||
|
action: 'save',
|
||||||
|
data: 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.'); ?>");
|
||||||
@ -32,9 +36,9 @@ define([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
App.getChannel().trigger('afterEditorSave', json, response);
|
App.getChannel().trigger('afterEditorSave', json, response);
|
||||||
}).fail(function() {
|
}).fail(function(response) {
|
||||||
// TODO: Handle saving errors
|
// TODO: Handle saving errors
|
||||||
App.getChannel().trigger('afterEditorSave', {}, error);
|
App.getChannel().trigger('afterEditorSave', {}, response);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,7 +72,8 @@ define([
|
|||||||
|
|
||||||
App.getAvailableStyles = Module.getAvailableStyles;
|
App.getAvailableStyles = Module.getAvailableStyles;
|
||||||
|
|
||||||
this.setGlobalStyles(options.newsletter.body.globalStyles);
|
var body = JSON.parse(options.newsletter.body);
|
||||||
|
this.setGlobalStyles(body.globalStyles);
|
||||||
});
|
});
|
||||||
|
|
||||||
App.on('start', function(options) {
|
App.on('start', function(options) {
|
||||||
|
Reference in New Issue
Block a user