Save current state after autosave is finished

[MAILPOET-1976]
This commit is contained in:
Ján Mikláš
2019-05-29 12:25:30 +02:00
committed by M. Shull
parent e20d0804ec
commit b64ba9f9b1

View File

@@ -4,9 +4,32 @@ import Marionette from 'backbone.marionette';
var Module = {};
Module.HistoryView = Marionette.View.extend({
MAX_HISTORY_STATES: 25,
model: {
states: [], // from newest
currentStateIndex: 0,
},
getTemplate: function getTemplate() {
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) {