diff booket.js @ 26:8c2f3e72d514

Create new view for notifications Create new view for notifications which handles the keyboard shortcuts overlay message and the unsaved changes notification. This ensures that the unsaved changes notification is always visible, even when the save form expander is closed.
author Guido Berhoerster <guido+booket@berhoerster.name>
date Mon, 06 Oct 2014 13:52:50 +0200
parents b2c9c4fb8d4c
children
line wrap: on
line diff
--- a/booket.js	Mon Oct 06 12:19:52 2014 +0200
+++ b/booket.js	Mon Oct 06 13:52:50 2014 +0200
@@ -921,15 +921,18 @@
  * view
  */
 
-var KeyboardShortcutsView = function () {
-    document.addEventListener('keydown', this);
-    document.addEventListener('keyup', this);
+var NotificationsView = function () {
+    this.unsavedChangesElement =
+        document.querySelector('#notifications .unsaved-changes-message');
 
     this.shortcutKeysOverlayElement =
         document.querySelector('#keyboard-shortcuts');
+
+    document.addEventListener('keydown', this);
+    document.addEventListener('keyup', this);
 };
 
-KeyboardShortcutsView.prototype.handleEvent = function (e) {
+NotificationsView.prototype.handleEvent = function (e) {
     var elements;
     var i;
 
@@ -943,6 +946,10 @@
     }
 };
 
+NotificationsView.prototype.onUnsavedChangesChanged = function (unsavedChanges) {
+    this.unsavedChangesElement.hidden = !unsavedChanges;
+};
+
 
 var TagView = function () {
     var tagsElement;
@@ -1110,9 +1117,6 @@
     this.tagInputTemplate = document.querySelector('#tag-input-template');
     saveFormElement = document.querySelector('form#save-form');
 
-    this.unsavedChangesElement =
-        saveFormElement.querySelector('.unsaved-changes-message');
-
     this.saveLinkElement = saveFormElement.querySelector('a#save-link');
 
     // create new editor form from template
@@ -1321,10 +1325,6 @@
     window.alert('Failed to parse bookmark file:\n' + message);
 };
 
-ActionsView.prototype.onUnsavedChangesChanged = function (unsavedChanges) {
-    this.unsavedChangesElement.hidden = !unsavedChanges;
-};
-
 
 var BookmarkView = function () {
     var searchFormElement;
@@ -1710,10 +1710,10 @@
  * controller
  */
 
-var BooketController = function(bookmarkModel, keyboardShortcutsView,
+var BooketController = function(bookmarkModel, notificationsView,
         actionsView, tagView, bookmarkView) {
     this.bookmarkModel = bookmarkModel;
-    this.keyboardShortcutsView = keyboardShortcutsView;
+    this.notificationsView = notificationsView;
     this.actionsView = actionsView;
     this.tagView = tagView;
     this.bookmarkView = bookmarkView;
@@ -1734,7 +1734,7 @@
     this.bookmarkModel.addObserver('export-file',
         this.actionsView.onExportFile.bind(this.actionsView));
     this.bookmarkModel.addObserver('unsaved-changes-changed',
-        this.actionsView.onUnsavedChangesChanged.bind(this.actionsView));
+        this.notificationsView.onUnsavedChangesChanged.bind(this.notificationsView));
     this.bookmarkModel.addObserver('tag-added',
         this.tagView.onTagAdded.bind(this.tagView));
     this.bookmarkModel.addObserver('tag-count-changed',
@@ -1899,18 +1899,18 @@
 document.addEventListener('DOMContentLoaded', function (e) {
     var controller;
     var bookmarkModel;
-    var keyboardShortcutsView;
+    var notificationsView;
     var actionsView;
     var tagView;
     var bookmarkView;
     var hashChangeEvent;
 
     bookmarkModel = new BookmarkModel();
-    keyboardShortcutsView = new KeyboardShortcutsView();
+    notificationsView = new NotificationsView();
     tagView = new TagView();
     actionsView = new ActionsView();
     bookmarkView = new BookmarkView();
-    controller = new BooketController(bookmarkModel, keyboardShortcutsView,
+    controller = new BooketController(bookmarkModel, notificationsView,
         actionsView, tagView, bookmarkView);
 
     // initialize state from the current URL