editor: status bar
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 17 Apr 2014 09:44:03 +0000 (11:44 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 23 Apr 2014 11:05:04 +0000 (13:05 +0200)
src/editor/modules.js
src/editor/modules/rng/rng.js
src/editor/modules/statusBar/statusBar.html [new file with mode: 0644]
src/editor/modules/statusBar/statusBar.js [new file with mode: 0644]
src/editor/modules/statusBar/statusBar.less [new file with mode: 0644]
src/editor/styles/main.less

index f7c5f6e..6b92a5e 100644 (file)
@@ -10,6 +10,7 @@ define(function(require) {
         data: require('modules/data/data'),
         rng: require('modules/rng/rng'),
         mainBar: require('modules/mainBar/mainBar'),
+        statusBar: require('modules/statusBar/statusBar'),
         indicator: require('modules/indicator/indicator'),
         
         sourceEditor: require('modules/sourceEditor/sourceEditor'),
index e15c94b..6a3271b 100644 (file)
@@ -107,7 +107,7 @@ return function(sandbox) {
             sandbox.getModule('mainBar').setCommandEnabled('drop-draft', usingDraft);
             sandbox.getModule('mainBar').setCommandEnabled('save', usingDraft);
 
-            _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'metadataEditor', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
+            _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'metadataEditor', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer', 'statusBar'], function(moduleName) {
                 sandbox.getModule(moduleName).start();
             });
             
@@ -294,6 +294,21 @@ return function(sandbox) {
         }
     };
 
+    eventHandlers.statusBar = {
+        ready: function() {
+            views.mainLayout.setView('bottomPanel', sandbox.getModule('statusBar').getView());
+        }
+    };
+
+    eventHandlers.__all__ = {
+        actionHovered: function(action) {
+            sandbox.getModule('statusBar').showAction(action);
+        },
+        actionOff: function() {
+            sandbox.getModule('statusBar').clearAction();
+        }
+    };
+
     window.addEventListener('beforeunload', function(event) {
         var txt = gettext('Do you really want to exit?');
         if(documentIsDirty) {
@@ -319,10 +334,16 @@ return function(sandbox) {
             if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
                 logger.debug('Handling event ' + eventRepr);
                 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
-            } else {
-                logger.warning('No event handler for ' + eventRepr);
+                return;
+            }
+
+            if(eventHandlers.__all__[eventName]) {
+                logger.debug('Handling event ' + eventRepr);
+                eventHandlers.__all__[eventName].apply(eventHandlers.__all__, args);
+                return;
             }
 
+            logger.warning('No event handler for ' + eventRepr);
         }
     };
 };
diff --git a/src/editor/modules/statusBar/statusBar.html b/src/editor/modules/statusBar/statusBar.html
new file mode 100644 (file)
index 0000000..0473d59
--- /dev/null
@@ -0,0 +1 @@
+<div id="rng-module-statusBar"></div>
\ No newline at end of file
diff --git a/src/editor/modules/statusBar/statusBar.js b/src/editor/modules/statusBar/statusBar.js
new file mode 100644 (file)
index 0000000..5ad7c6b
--- /dev/null
@@ -0,0 +1,42 @@
+define(function(require) {
+    
+'use strict';
+/* globals gettext */
+
+var $ = require('libs/jquery'),
+    template = require('libs/text!modules/statusBar/statusBar.html'),
+    logging = require('fnpjs/logging/logging');
+
+var logger = logging.getLogger('statusBar');
+
+return function(sandbox){
+
+    var view = $(template);
+
+    return {
+        start: function() {
+            return sandbox.publish('ready');
+        },
+        getView: function() {
+            return view;
+        },
+        showAction: function(action) {
+            var state = action.getState(),
+                description = state.description;
+            if(!description) {
+                description = state.allowed ? gettext('Undescribed action') : gettext('Action not allowed');
+                logger.info('Undescribed action: ' + action.name);
+            }
+            view.text(description);
+            if(!state.allowed) {
+                view.prepend('<span class="badge badge-warning" style="margin-right: 5px">!</span>');
+            }
+        },
+        clearAction: function() {
+            view.text('');
+        }
+    };
+
+};
+
+});
\ No newline at end of file
diff --git a/src/editor/modules/statusBar/statusBar.less b/src/editor/modules/statusBar/statusBar.less
new file mode 100644 (file)
index 0000000..cbaa2f5
--- /dev/null
@@ -0,0 +1,8 @@
+#rng-module-statusBar {
+    border-width: 1px 0 0 0;
+    border-style: solid;
+    border-color: #ddd;
+    font-size: 0.8em;
+    height: 100%;
+    padding: 5px;
+}
\ No newline at end of file
index 82bf8d5..411a2aa 100644 (file)
@@ -15,3 +15,4 @@
 @import '../modules/nodeFamilyTree/nodeFamilyTree.less';
 @import '../modules/metadataEditor/metadataEditor.less';
 @import '../modules/diffViewer/diffViewer.less';
+@import '../modules/statusBar/statusBar.less';