|
|
|
@ -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); |
|
|
|
}, |
|
|
|
|
|
|
|
|