From c11ad12846df3142b19a343144fe1d2a82b97569 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 17 Apr 2014 11:44:03 +0200 Subject: [PATCH] editor: status bar --- src/editor/modules.js | 1 + src/editor/modules/rng/rng.js | 27 +++++++++++-- src/editor/modules/statusBar/statusBar.html | 1 + src/editor/modules/statusBar/statusBar.js | 42 +++++++++++++++++++++ src/editor/modules/statusBar/statusBar.less | 8 ++++ src/editor/styles/main.less | 1 + 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/editor/modules/statusBar/statusBar.html create mode 100644 src/editor/modules/statusBar/statusBar.js create mode 100644 src/editor/modules/statusBar/statusBar.less diff --git a/src/editor/modules.js b/src/editor/modules.js index f7c5f6e..6b92a5e 100644 --- a/src/editor/modules.js +++ b/src/editor/modules.js @@ -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'), diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index e15c94b..6a3271b 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -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 index 0000000..0473d59 --- /dev/null +++ b/src/editor/modules/statusBar/statusBar.html @@ -0,0 +1 @@ +
\ 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 index 0000000..5ad7c6b --- /dev/null +++ b/src/editor/modules/statusBar/statusBar.js @@ -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('!'); + } + }, + 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 index 0000000..cbaa2f5 --- /dev/null +++ b/src/editor/modules/statusBar/statusBar.less @@ -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 diff --git a/src/editor/styles/main.less b/src/editor/styles/main.less index 82bf8d5..411a2aa 100644 --- a/src/editor/styles/main.less +++ b/src/editor/styles/main.less @@ -15,3 +15,4 @@ @import '../modules/nodeFamilyTree/nodeFamilyTree.less'; @import '../modules/metadataEditor/metadataEditor.less'; @import '../modules/diffViewer/diffViewer.less'; +@import '../modules/statusBar/statusBar.less'; -- 2.20.1