editor: Store and load blockDefaults in newsletter data

This commit is contained in:
Rostislav Wolny
2018-03-12 15:24:19 +01:00
parent fbfcfcc85b
commit 05dcaeba76
3 changed files with 18 additions and 5 deletions

View File

@ -1,7 +1,8 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'backbone.supermodel' 'backbone.supermodel',
], function (App, SuperModel) { // eslint-disable-line func-names 'underscore'
], function (App, SuperModel, _) { // eslint-disable-line func-names
var Module = {}; var Module = {};
Module.ConfigModel = SuperModel.extend({ Module.ConfigModel = SuperModel.extend({
@ -25,11 +26,17 @@ define([
App.on('before:start', function (BeforeStartApp, options) { // eslint-disable-line func-names App.on('before:start', function (BeforeStartApp, options) { // eslint-disable-line func-names
var Application = BeforeStartApp; var Application = BeforeStartApp;
var config = _.clone(options.config);
// Expose config methods globally // Expose config methods globally
Application.getConfig = Module.getConfig; Application.getConfig = Module.getConfig;
Application.setConfig = Module.setConfig; Application.setConfig = Module.setConfig;
Application.setConfig(options.config); config.blockDefaults = _.extend(
config.blockDefaults,
options.newsletter.body.blockDefaults || {}
);
Application.setConfig(config);
}); });
return Module; return Module;

View File

@ -46,7 +46,8 @@ define([
Module.getBody = function getBody() { Module.getBody = function getBody() {
return { return {
content: App._contentContainer.toJSON(), content: App._contentContainer.toJSON(),
globalStyles: App.getGlobalStyles().toJSON() globalStyles: App.getGlobalStyles().toJSON(),
blockDefaults: _.omit(App.getConfig().toJSON().blockDefaults, 'text', 'image')
}; };
}; };

View File

@ -89,6 +89,9 @@ define([
var newsletterFields = { var newsletterFields = {
subject: 'test newsletter subject' subject: 'test newsletter subject'
}; };
var blockDefaults = {
button: {}
};
EditorApplication._contentContainer = { EditorApplication._contentContainer = {
toJSON: function () { toJSON: function () {
return dataField; return dataField;
@ -108,11 +111,13 @@ define([
} }
}; };
}; };
EditorApplication.getConfig().set('blockDefaults', blockDefaults);
json = ContentComponent.toJSON(); json = ContentComponent.toJSON();
expect(json).to.deep.equal(_.extend({ expect(json).to.deep.equal(_.extend({
body: { body: {
content: dataField, content: dataField,
globalStyles: stylesField globalStyles: stylesField,
blockDefaults: blockDefaults
} }
}, newsletterFields)); }, newsletterFields));
}); });