editor: Update config blockDefaults by latest used value per type
This commit is contained in:
@ -22,6 +22,7 @@ define([
|
|||||||
stale: [], // Attributes to be removed upon saving
|
stale: [], // Attributes to be removed upon saving
|
||||||
initialize: function initialize() {
|
initialize: function initialize() {
|
||||||
this.on('change', function onChange() {
|
this.on('change', function onChange() {
|
||||||
|
this._updateDefaults();
|
||||||
App.getChannel().trigger('autoSave');
|
App.getChannel().trigger('autoSave');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -39,6 +40,9 @@ define([
|
|||||||
// TODO: Investigate for a better solution
|
// TODO: Investigate for a better solution
|
||||||
return JSON.parse(JSON.stringify(jQuery.extend(blockDefaults, defaults || {})));
|
return JSON.parse(JSON.stringify(jQuery.extend(blockDefaults, defaults || {})));
|
||||||
},
|
},
|
||||||
|
_updateDefaults: function updateDefaults() {
|
||||||
|
App.getConfig().set('blockDefaults.' + this.get('type'), this.toJSON());
|
||||||
|
},
|
||||||
toJSON: function toJSON() {
|
toJSON: function toJSON() {
|
||||||
// Remove stale attributes from resulting JSON object
|
// Remove stale attributes from resulting JSON object
|
||||||
return _.omit(SuperModel.prototype.toJSON.call(this), this.stale);
|
return _.omit(SuperModel.prototype.toJSON.call(this), this.stale);
|
||||||
|
@ -6,6 +6,7 @@ define([
|
|||||||
'newsletter_editor/blocks/button'
|
'newsletter_editor/blocks/button'
|
||||||
], function (App, ButtonBlock) {
|
], function (App, ButtonBlock) {
|
||||||
var EditorApplication = App;
|
var EditorApplication = App;
|
||||||
|
var sandbox;
|
||||||
|
|
||||||
describe('Button', function () {
|
describe('Button', function () {
|
||||||
describe('model', function () {
|
describe('model', function () {
|
||||||
@ -17,12 +18,14 @@ define([
|
|||||||
blockDefaults: {}
|
blockDefaults: {}
|
||||||
});
|
});
|
||||||
model = new (ButtonBlock.ButtonBlockModel)();
|
model = new (ButtonBlock.ButtonBlockModel)();
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
if (EditorApplication.getChannel) {
|
if (EditorApplication.getChannel) {
|
||||||
delete EditorApplication.getChannel;
|
delete EditorApplication.getChannel;
|
||||||
}
|
}
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a button type', function () {
|
it('has a button type', function () {
|
||||||
@ -107,6 +110,14 @@ define([
|
|||||||
mock.verify();
|
mock.verify();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates blockDefaults.button when changed', function () {
|
||||||
|
var stub = sandbox.stub(EditorApplication.getConfig(), 'set');
|
||||||
|
model.trigger('change');
|
||||||
|
expect(stub.callCount).to.equal(1);
|
||||||
|
expect(stub.getCall(0).args[0]).to.equal('blockDefaults.button');
|
||||||
|
expect(stub.getCall(0).args[1]).to.deep.equal(model.toJSON());
|
||||||
|
});
|
||||||
|
|
||||||
it('uses defaults from config when they are set', function () {
|
it('uses defaults from config when they are set', function () {
|
||||||
global.stubConfig(EditorApplication, {
|
global.stubConfig(EditorApplication, {
|
||||||
blockDefaults: {
|
blockDefaults: {
|
||||||
|
@ -6,6 +6,7 @@ define([
|
|||||||
'newsletter_editor/blocks/divider'
|
'newsletter_editor/blocks/divider'
|
||||||
], function (App, DividerBlock) {
|
], function (App, DividerBlock) {
|
||||||
var EditorApplication = App;
|
var EditorApplication = App;
|
||||||
|
var sandbox;
|
||||||
|
|
||||||
describe('Divider', function () {
|
describe('Divider', function () {
|
||||||
describe('model', function () {
|
describe('model', function () {
|
||||||
@ -18,10 +19,12 @@ define([
|
|||||||
});
|
});
|
||||||
global.stubAvailableStyles(EditorApplication);
|
global.stubAvailableStyles(EditorApplication);
|
||||||
model = new (DividerBlock.DividerBlockModel)();
|
model = new (DividerBlock.DividerBlockModel)();
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
delete EditorApplication.getChannel;
|
delete EditorApplication.getChannel;
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a divider type', function () {
|
it('has a divider type', function () {
|
||||||
@ -94,6 +97,14 @@ define([
|
|||||||
expect(innerModel.get('styles.block.borderWidth')).to.equal('7px');
|
expect(innerModel.get('styles.block.borderWidth')).to.equal('7px');
|
||||||
expect(innerModel.get('styles.block.borderColor')).to.equal('#345678');
|
expect(innerModel.get('styles.block.borderColor')).to.equal('#345678');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates blockDefaults.divider when changed', function () {
|
||||||
|
var stub = sandbox.stub(EditorApplication.getConfig(), 'set');
|
||||||
|
model.trigger('change');
|
||||||
|
expect(stub.callCount).to.equal(1);
|
||||||
|
expect(stub.getCall(0).args[0]).to.equal('blockDefaults.divider');
|
||||||
|
expect(stub.getCall(0).args[1]).to.deep.equal(model.toJSON());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('block view', function () {
|
describe('block view', function () {
|
||||||
|
@ -10,12 +10,18 @@ define([
|
|||||||
describe('Footer', function () {
|
describe('Footer', function () {
|
||||||
describe('model', function () {
|
describe('model', function () {
|
||||||
var model;
|
var model;
|
||||||
|
var sandbox;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
global.stubChannel(EditorApplication);
|
global.stubChannel(EditorApplication);
|
||||||
global.stubConfig(EditorApplication, {
|
global.stubConfig(EditorApplication, {
|
||||||
blockDefaults: {}
|
blockDefaults: {}
|
||||||
});
|
});
|
||||||
model = new (FooterBlock.FooterBlockModel)();
|
model = new (FooterBlock.FooterBlockModel)();
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a footer type', function () {
|
it('has a footer type', function () {
|
||||||
@ -113,6 +119,14 @@ define([
|
|||||||
expect(innerModel.get('styles.link.fontColor')).to.equal('#345678');
|
expect(innerModel.get('styles.link.fontColor')).to.equal('#345678');
|
||||||
expect(innerModel.get('styles.link.textDecoration')).to.equal('underline');
|
expect(innerModel.get('styles.link.textDecoration')).to.equal('underline');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates blockDefaults.footer when changed', function () {
|
||||||
|
var stub = sandbox.stub(EditorApplication.getConfig(), 'set');
|
||||||
|
model.trigger('change');
|
||||||
|
expect(stub.callCount).to.equal(1);
|
||||||
|
expect(stub.getCall(0).args[0]).to.equal('blockDefaults.footer');
|
||||||
|
expect(stub.getCall(0).args[1]).to.deep.equal(model.toJSON());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('block view', function () {
|
describe('block view', function () {
|
||||||
|
@ -10,12 +10,17 @@ define([
|
|||||||
describe('Header', function () {
|
describe('Header', function () {
|
||||||
describe('model', function () {
|
describe('model', function () {
|
||||||
var model;
|
var model;
|
||||||
|
var sandbox;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
global.stubChannel(EditorApplication);
|
global.stubChannel(EditorApplication);
|
||||||
global.stubConfig(EditorApplication, {
|
global.stubConfig(EditorApplication, {
|
||||||
blockDefaults: {}
|
blockDefaults: {}
|
||||||
});
|
});
|
||||||
model = new (HeaderBlock.HeaderBlockModel)();
|
model = new (HeaderBlock.HeaderBlockModel)();
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
|
});
|
||||||
|
afterEach(function () {
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a header type', function () {
|
it('has a header type', function () {
|
||||||
@ -113,6 +118,14 @@ define([
|
|||||||
expect(innerModel.get('styles.link.fontColor')).to.equal('#345678');
|
expect(innerModel.get('styles.link.fontColor')).to.equal('#345678');
|
||||||
expect(innerModel.get('styles.link.textDecoration')).to.equal('underline');
|
expect(innerModel.get('styles.link.textDecoration')).to.equal('underline');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates blockDefaults.header when changed', function () {
|
||||||
|
var stub = sandbox.stub(EditorApplication.getConfig(), 'set');
|
||||||
|
model.trigger('change');
|
||||||
|
expect(stub.callCount).to.equal(1);
|
||||||
|
expect(stub.getCall(0).args[0]).to.equal('blockDefaults.header');
|
||||||
|
expect(stub.getCall(0).args[1]).to.deep.equal(model.toJSON());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('block view', function () {
|
describe('block view', function () {
|
||||||
|
@ -10,6 +10,7 @@ define([
|
|||||||
describe('Spacer', function () {
|
describe('Spacer', function () {
|
||||||
describe('model', function () {
|
describe('model', function () {
|
||||||
var model;
|
var model;
|
||||||
|
var sandbox;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
global.stubChannel(EditorApplication);
|
global.stubChannel(EditorApplication);
|
||||||
@ -18,10 +19,12 @@ define([
|
|||||||
});
|
});
|
||||||
global.stubAvailableStyles(EditorApplication);
|
global.stubAvailableStyles(EditorApplication);
|
||||||
model = new (SpacerBlock.SpacerBlockModel)();
|
model = new (SpacerBlock.SpacerBlockModel)();
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
delete EditorApplication.getChannel;
|
delete EditorApplication.getChannel;
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has spacer type', function () {
|
it('has spacer type', function () {
|
||||||
@ -72,6 +75,14 @@ define([
|
|||||||
expect(model.get('styles.block.backgroundColor')).to.equal('#567890');
|
expect(model.get('styles.block.backgroundColor')).to.equal('#567890');
|
||||||
expect(model.get('styles.block.height')).to.equal('19px');
|
expect(model.get('styles.block.height')).to.equal('19px');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates blockDefaults.spacer when changed', function () {
|
||||||
|
var stub = sandbox.stub(EditorApplication.getConfig(), 'set');
|
||||||
|
model.trigger('change');
|
||||||
|
expect(stub.callCount).to.equal(1);
|
||||||
|
expect(stub.getCall(0).args[0]).to.equal('blockDefaults.spacer');
|
||||||
|
expect(stub.getCall(0).args[1]).to.deep.equal(model.toJSON());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('block view', function () {
|
describe('block view', function () {
|
||||||
|
Reference in New Issue
Block a user