Mercurial > projects > booket
diff booket.js @ 18:3642bb668af1
Indicate if there are unsaved changes
author | Guido Berhoerster <guido+booket@berhoerster.name> |
---|---|
date | Tue, 30 Sep 2014 21:32:39 +0200 |
parents | 64272f2105da |
children | 4a4d9527c06f |
line wrap: on
line diff
--- a/booket.js Mon Sep 29 22:39:17 2014 +0200 +++ b/booket.js Tue Sep 30 21:32:39 2014 +0200 @@ -453,7 +453,7 @@ var BookmarkModel = function () { ObservableMixin.call(this); - this.unsavedChanges = false; + this._unsavedChanges = false; this.loadFileReader = null; this.importFileReader= null; this._bookmarks = new StringMap(); @@ -466,6 +466,18 @@ extend(BookmarkModel, ObservableMixin); +Object.defineProperty(BookmarkModel.prototype, 'unsavedChanges', { + set: function (value) { + if (this._unsavedChanges !== value) { + this._unsavedChanges = value; + this.notify('unsaved-changes-changed', value) + } + }, + get: function () { + return this._unsavedChanges; + } +}); + BookmarkModel.prototype.add = function (bookmarks) { var addedBookmarkUrls = new StringSet(); @@ -1051,6 +1063,9 @@ saveFormElement = document.querySelector('form#save-form'); saveFormElement.addEventListener('submit', this); + this.unsavedChangesElement = + saveFormElement.querySelector('.unsaved-changes-message'); + this.saveLinkElement = saveFormElement.querySelector('a#save-link'); loadFormElement = document.querySelector('form#load-form'); @@ -1243,6 +1258,10 @@ window.alert('Failed to parse bookmark file:\n' + message); }; +ActionsView.prototype.onUnsavedChangesChanged = function (unsavedChanges) { + this.unsavedChangesElement.hidden = !unsavedChanges; +}; + var BookmarkView = function () { var searchFormElement; @@ -1623,6 +1642,8 @@ this.actionsView.onSaveFile.bind(this.actionsView)); this.bookmarkModel.addObserver('export-file', this.actionsView.onExportFile.bind(this.actionsView)); + this.bookmarkModel.addObserver('unsaved-changes-changed', + this.actionsView.onUnsavedChangesChanged.bind(this.actionsView)); this.bookmarkModel.addObserver('tag-added', this.tagView.onTagAdded.bind(this.tagView)); this.bookmarkModel.addObserver('tag-count-changed',