Fix newsletter corruption when going back to editor from last newsletter step
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'backbone.supermodel',
|
||||
'underscore'
|
||||
], function(App, SuperModel, _) {
|
||||
'underscore',
|
||||
'mailpoet'
|
||||
], function(App, SuperModel, _, MailPoet) {
|
||||
"use strict";
|
||||
|
||||
var Module = {};
|
||||
@@ -81,7 +82,13 @@ define([
|
||||
|
||||
App.on('start', function(options) {
|
||||
var body = options.newsletter.body;
|
||||
App._contentContainer = new (App.getBlockTypeModel('container'))(body.content, {parse: true});
|
||||
var content = (_.has(body, 'content')) ? body.content : {};
|
||||
|
||||
if (!_.has(options.newsletter, 'body') || !_.isObject(options.newsletter.body)) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('newsletterBodyIsCorrupted'));
|
||||
}
|
||||
|
||||
App._contentContainer = new (App.getBlockTypeModel('container'))(content, {parse: true});
|
||||
App._contentContainerView = new (App.getBlockTypeView('container'))({
|
||||
model: App._contentContainer,
|
||||
renderOptions: { depth: 0 },
|
||||
|
@@ -69,11 +69,11 @@ define([
|
||||
// Expose style methods to global application
|
||||
App.getGlobalStyles = Module.getGlobalStyles;
|
||||
App.setGlobalStyles = Module.setGlobalStyles;
|
||||
|
||||
App.getAvailableStyles = Module.getAvailableStyles;
|
||||
|
||||
var body = options.newsletter.body;
|
||||
this.setGlobalStyles(body.globalStyles);
|
||||
var globalStyles = (_.has(body, 'globalStyles')) ? body.globalStyles : {};
|
||||
this.setGlobalStyles(globalStyles);
|
||||
});
|
||||
|
||||
App.on('start', function(options) {
|
||||
|
@@ -173,15 +173,20 @@ define(
|
||||
var data = this.state.item;
|
||||
this.setState({ loading: true });
|
||||
|
||||
// Ensure that body is JSON encoded
|
||||
if (!_.isUndefined(data.body)) {
|
||||
data.body = JSON.stringify(data.body);
|
||||
}
|
||||
// Store only properties that can be changed on this page
|
||||
const IGNORED_NEWSLETTER_PROPERTIES = [
|
||||
'preheader', 'body', 'created_at', 'deleted_at', 'hash',
|
||||
'status', 'updated_at', 'type'
|
||||
];
|
||||
const newsletterData = _.omit(
|
||||
data,
|
||||
IGNORED_NEWSLETTER_PROPERTIES
|
||||
);
|
||||
|
||||
return MailPoet.Ajax.post({
|
||||
endpoint: 'newsletters',
|
||||
action: 'save',
|
||||
data: data,
|
||||
data: newsletterData,
|
||||
}).always(() => {
|
||||
this.setState({ loading: false });
|
||||
});
|
||||
|
Reference in New Issue
Block a user