editor: Update config blockDefaults by latest used value per type

This commit is contained in:
Rostislav Wolny
2018-03-12 15:15:30 +01:00
parent 1c5a0bb5bd
commit 1d9b4839f7
6 changed files with 64 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ define([
stale: [], // Attributes to be removed upon saving
initialize: function initialize() {
this.on('change', function onChange() {
this._updateDefaults();
App.getChannel().trigger('autoSave');
});
},
@@ -39,6 +40,9 @@ define([
// TODO: Investigate for a better solution
return JSON.parse(JSON.stringify(jQuery.extend(blockDefaults, defaults || {})));
},
_updateDefaults: function updateDefaults() {
App.getConfig().set('blockDefaults.' + this.get('type'), this.toJSON());
},
toJSON: function toJSON() {
// Remove stale attributes from resulting JSON object
return _.omit(SuperModel.prototype.toJSON.call(this), this.stale);