piskel/src/js/service/SavedStatusService.js
Guillaume Martigny 58a1a6b043 Dirty status compare last save state index and current state index
Signed-off-by:Guillaume Martigny <guillaume.martigny@gmail.com>
2016-05-22 15:03:47 +02:00

38 lines
1.2 KiB
JavaScript

(function () {
var ns = $.namespace('pskl.service');
ns.SavedStatusService = function (piskelController, historyService) {
this.piskelController = piskelController;
this.historyService = historyService;
this.lastSavedStateIndex = '';
};
ns.SavedStatusService.prototype.init = function () {
$.subscribe(Events.TOOL_RELEASED, this.onToolReleased.bind(this));
$.subscribe(Events.PISKEL_RESET, this.onPiskelReset.bind(this));
$.subscribe(Events.PISKEL_SAVED, this.onPiskelSaved.bind(this));
this.lastSavedStateIndex = this.historyService.getCurrentStateIndex();
};
ns.SavedStatusService.prototype.onToolReleased = function () {
this.updateDirtyStatus();
};
ns.SavedStatusService.prototype.onPiskelReset = function () {
this.updateDirtyStatus();
};
ns.SavedStatusService.prototype.onPiskelSaved = function () {
this.lastSavedStateIndex = this.historyService.getCurrentStateIndex();
$.publish(Events.PISKEL_SAVED_STATUS_UPDATE);
};
ns.SavedStatusService.prototype.updateDirtyStatus = function () {
$.publish(Events.PISKEL_SAVED_STATUS_UPDATE);
};
ns.SavedStatusService.prototype.isDirty = function () {
return (this.lastSavedStateIndex != this.historyService.getCurrentStateIndex());
};
})();