comparison 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
comparison
equal deleted inserted replaced
17:8445c729ba97 18:3642bb668af1
451 451
452 452
453 var BookmarkModel = function () { 453 var BookmarkModel = function () {
454 ObservableMixin.call(this); 454 ObservableMixin.call(this);
455 455
456 this.unsavedChanges = false; 456 this._unsavedChanges = false;
457 this.loadFileReader = null; 457 this.loadFileReader = null;
458 this.importFileReader= null; 458 this.importFileReader= null;
459 this._bookmarks = new StringMap(); 459 this._bookmarks = new StringMap();
460 this._tagCount = new StringMap(); 460 this._tagCount = new StringMap();
461 this._filterTags = new StringSet(); 461 this._filterTags = new StringSet();
463 this._filteredBookmarks = new StringSet(); 463 this._filteredBookmarks = new StringSet();
464 this._searchedBookmarks = new StringSet(); 464 this._searchedBookmarks = new StringSet();
465 }; 465 };
466 466
467 extend(BookmarkModel, ObservableMixin); 467 extend(BookmarkModel, ObservableMixin);
468
469 Object.defineProperty(BookmarkModel.prototype, 'unsavedChanges', {
470 set: function (value) {
471 if (this._unsavedChanges !== value) {
472 this._unsavedChanges = value;
473 this.notify('unsaved-changes-changed', value)
474 }
475 },
476 get: function () {
477 return this._unsavedChanges;
478 }
479 });
468 480
469 BookmarkModel.prototype.add = function (bookmarks) { 481 BookmarkModel.prototype.add = function (bookmarks) {
470 var addedBookmarkUrls = new StringSet(); 482 var addedBookmarkUrls = new StringSet();
471 483
472 // argument can be a single bookmark or a list of bookmarks 484 // argument can be a single bookmark or a list of bookmarks
1049 1061
1050 this.tagInputTemplate = document.querySelector('#tag-input-template'); 1062 this.tagInputTemplate = document.querySelector('#tag-input-template');
1051 saveFormElement = document.querySelector('form#save-form'); 1063 saveFormElement = document.querySelector('form#save-form');
1052 saveFormElement.addEventListener('submit', this); 1064 saveFormElement.addEventListener('submit', this);
1053 1065
1066 this.unsavedChangesElement =
1067 saveFormElement.querySelector('.unsaved-changes-message');
1068
1054 this.saveLinkElement = saveFormElement.querySelector('a#save-link'); 1069 this.saveLinkElement = saveFormElement.querySelector('a#save-link');
1055 1070
1056 loadFormElement = document.querySelector('form#load-form'); 1071 loadFormElement = document.querySelector('form#load-form');
1057 loadFormElement.addEventListener('submit', this); 1072 loadFormElement.addEventListener('submit', this);
1058 1073
1239 window.alert('Failed to load bookmark file:\n' + message); 1254 window.alert('Failed to load bookmark file:\n' + message);
1240 }; 1255 };
1241 1256
1242 ActionsView.prototype.onParseFileError = function (message) { 1257 ActionsView.prototype.onParseFileError = function (message) {
1243 window.alert('Failed to parse bookmark file:\n' + message); 1258 window.alert('Failed to parse bookmark file:\n' + message);
1259 };
1260
1261 ActionsView.prototype.onUnsavedChangesChanged = function (unsavedChanges) {
1262 this.unsavedChangesElement.hidden = !unsavedChanges;
1244 }; 1263 };
1245 1264
1246 1265
1247 var BookmarkView = function () { 1266 var BookmarkView = function () {
1248 var searchFormElement; 1267 var searchFormElement;
1621 this.actionsView.onParseFileError.bind(this.actionsView)); 1640 this.actionsView.onParseFileError.bind(this.actionsView));
1622 this.bookmarkModel.addObserver('save-file', 1641 this.bookmarkModel.addObserver('save-file',
1623 this.actionsView.onSaveFile.bind(this.actionsView)); 1642 this.actionsView.onSaveFile.bind(this.actionsView));
1624 this.bookmarkModel.addObserver('export-file', 1643 this.bookmarkModel.addObserver('export-file',
1625 this.actionsView.onExportFile.bind(this.actionsView)); 1644 this.actionsView.onExportFile.bind(this.actionsView));
1645 this.bookmarkModel.addObserver('unsaved-changes-changed',
1646 this.actionsView.onUnsavedChangesChanged.bind(this.actionsView));
1626 this.bookmarkModel.addObserver('tag-added', 1647 this.bookmarkModel.addObserver('tag-added',
1627 this.tagView.onTagAdded.bind(this.tagView)); 1648 this.tagView.onTagAdded.bind(this.tagView));
1628 this.bookmarkModel.addObserver('tag-count-changed', 1649 this.bookmarkModel.addObserver('tag-count-changed',
1629 this.tagView.onTagCountChanged.bind(this.tagView)); 1650 this.tagView.onTagCountChanged.bind(this.tagView));
1630 this.bookmarkModel.addObserver('tag-deleted', 1651 this.bookmarkModel.addObserver('tag-deleted',