Browse Source

Update how changesCount is handled

pull/458/head
Artur Arseniev 8 years ago
parent
commit
bb97caa862
  1. 3
      index.html
  2. 20
      src/editor/model/Editor.js

3
index.html

@ -1326,6 +1326,9 @@
editor.on('storage:store', function(e) {
console.log('STORE ', e);
})
editor.on('change:changesCount', function(e) {
console.log('update changesCount ', editor.getModel().get('changesCount'));
})
editor.on('styleManager:change:text-shadow', function(view) {
var model = view.model;

20
src/editor/model/Editor.js

@ -63,7 +63,7 @@ module.exports = Backbone.Model.extend({
this.initUndoManager();
this.on('change:selectedComponent', this.componentSelected, this);
this.on('change:changesCount', this.updateBeforeUnload, this);
this.on('change:changesCount', this.updateChanges, this);
},
/**
@ -100,21 +100,28 @@ module.exports = Backbone.Model.extend({
}
},
/**
* Set the alert before unload in case it's requested
* and there are unsaved changes
* @private
*/
updateBeforeUnload() {
var changes = this.get('changesCount');
updateChanges() {
const stm = this.get('StorageManager');
const changes = this.get('changesCount');
if (this.config.noticeOnUnload && changes) {
window.onbeforeunload = e => 1;
} else {
window.onbeforeunload = null;
}
if (stm.isAutosave() && changes >= stm.getStepsBeforeSave()) {
this.store();
}
},
/**
* Load generic module
* @param {String} moduleName Module name
@ -199,17 +206,22 @@ module.exports = Backbone.Model.extend({
timedInterval && clearInterval(timedInterval);
timedInterval = setTimeout(() => {
if (!opt.avoidStore) {
this.set('changesCount', this.get('changesCount') + 1, opt)
}
/*
var count = this.get('changesCount') + 1;
var stm = this.get('StorageManager');
this.set('changesCount', count);
if (!stm.isAutosave() || count < stm.getStepsBeforeSave()) {
return;
}
if (!opt.avoidStore) {
this.set('changesCount', count)
this.store();
}
*/
}, 0);
},

Loading…
Cancel
Save