Save current state after autosave is finished
[MAILPOET-1976]
This commit is contained in:
@@ -4,9 +4,32 @@ import Marionette from 'backbone.marionette';
|
|||||||
var Module = {};
|
var Module = {};
|
||||||
|
|
||||||
Module.HistoryView = Marionette.View.extend({
|
Module.HistoryView = Marionette.View.extend({
|
||||||
|
MAX_HISTORY_STATES: 25,
|
||||||
|
|
||||||
|
model: {
|
||||||
|
states: [], // from newest
|
||||||
|
currentStateIndex: 0,
|
||||||
|
},
|
||||||
|
|
||||||
getTemplate: function getTemplate() {
|
getTemplate: function getTemplate() {
|
||||||
return window.templates.history;
|
return window.templates.history;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
initialize: function initialize() {
|
||||||
|
App.getChannel().on('afterEditorSave', this.setCurrentState, this);
|
||||||
|
},
|
||||||
|
|
||||||
|
setCurrentState: function setCurrentState(json) {
|
||||||
|
if (!json || !json.body) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.model.currentStateIndex > 0) {
|
||||||
|
this.model.states.splice(0, this.model.currentStateIndex);
|
||||||
|
}
|
||||||
|
this.model.states.unshift(json.body);
|
||||||
|
this.model.currentStateIndex = 0;
|
||||||
|
this.model.states.length = Math.min(this.model.states.length, this.MAX_HISTORY_STATES);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
App.on('start', function appStart(StartApp) {
|
App.on('start', function appStart(StartApp) {
|
||||||
|
Reference in New Issue
Block a user