turn navbar into a directive for hotkey integration
authorBill Erickson <berick@esilibrary.com>
Thu, 8 May 2014 14:00:08 +0000 (10:00 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 8 May 2014 14:00:08 +0000 (10:00 -0400)
includes a sample hotkey (eg-accesskey) declaration -- more work to do
here

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/t_base.tt2
Open-ILS/src/templates/staff/t_base_js.tt2
Open-ILS/src/templates/staff/t_navbar.tt2
Open-ILS/web/js/ui/default/staff/navbar.js [deleted file]
Open-ILS/web/js/ui/default/staff/services/core.js
Open-ILS/web/js/ui/default/staff/services/navbar.js [new file with mode: 0644]

index aade37c..4476612 100644 (file)
@@ -9,11 +9,18 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!-- TODO: remote hosted CSS should be hosted locally instead -->
     <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
+    <link rel="stylesheet" href="[% ctx.media_prefix %]/js/ui/default/staff/build/hotkeys.min.css" />
     <link rel="stylesheet" href="[% ctx.base_path %]/staff/css/style.css" />
     <link rel="stylesheet" href="[% ctx.base_path %]/staff/css/print.css" type="text/css" media="print" />
   </head>
   <body>
-    [% INCLUDE "staff/t_navbar.tt2" %]
+    <!-- load the navbar template inline since it's used on every page -->
+    <script type="text/ng-template" id="eg-navbar-template">
+      [% INCLUDE "staff/t_navbar.tt2" %]
+    </script>
+    <!-- instantiate the navbar by invoking it's name -->
+    <eg-navbar></eg-navbar>
+
     <div id="top-content-container" class="container">[% content %]</div>
     [% 
       # status bar along bottom of page
index 2231801..bf0cc98 100644 (file)
@@ -1,8 +1,5 @@
-<!-- TODO: remotely hosted JS should be hosted locally -->
-<!-- TODO: combine and minify JS -->
-
 [% 
-  EG_VERSION = '0.0.1'; # FIXME: build optoin
+  EG_VERSION = '0.0.1'; # FIXME: build option
   EXPAND_JS_IMPORTS = 1; # FIXME: env option?
 %]
 
@@ -34,7 +31,7 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/startup.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/hatch.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/coresvc.js"></script>
-<script src="[% ctx.media_prefix %]/js/ui/default/staff/navbar.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/services/navbar.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/statusbar.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/ui.js"></script>
 
index bf09320..0d56a24 100644 (file)
@@ -16,7 +16,7 @@
   <div class="navbar-header">
     <button type="button" class="navbar-toggle" 
         ng-init="navCollapsed = true" ng-click="navCollapsed = !navCollapsed">
-      <span class="sr-only">Toggle navigation</span>
+      <span class="sr-only">[% l('Toggle navigation') %]</span>
       <span class="icon-bar"></span>
       <span class="icon-bar"></span>
       <span class="icon-bar"></span>
@@ -27,7 +27,6 @@
     <ul class="nav navbar-nav">
       <li><a href='./' title="[% l('Home') %]" target="_self"
         class="glyphicon glyphicon-home"></a><li>
-        <!-- " vim -->
 
       <!-- circulation -->
       <li class="dropdown">
             </a>
           </li>
           <li>
-            <a href="./circ/patron/search" target="_self">
+            <a href="./circ/patron/search" target="_self"
+              eg-accesskey="[% l('alt+s') %]" 
+              eg-accesskey-desc="[% l('Patron search by name, address, etc.') %]">
               <span class="glyphicon glyphicon-search"></span>
-              [% l('Patron Search') %]
+              <span eg-accesskey-label>[% l('Patron Search') %]</span>
             </a>
           </li>
           <li>
diff --git a/Open-ILS/web/js/ui/default/staff/navbar.js b/Open-ILS/web/js/ui/default/staff/navbar.js
deleted file mode 100644 (file)
index 375473e..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Free-floating controller which can be used by any app.
- */
-function NavCtrl($scope, $window, $location, egCore) {
-
-    $scope.applyLocale = function(locale) {
-        // EGWeb.pm can change the locale for us w/ the right param
-        $window.location.href = 
-            $location.search('set_eg_locale', locale).absUrl();
-    }
-
-    // tied to logout link
-    $scope.logout = function() {
-        egCore.auth.logout();
-        return true;
-    };
-
-    /**
-     * Two important things happening here.
-     *
-     * 1. Since this is a standalone controller, which may execute at
-     * any time during page load, we have no gaurantee that needed
-     * startup actions, session retrieval being the main one, have taken
-     * place yet. So we kick off the startup chain ourselves and run
-     * actions when it's done. Note this does not mean startup runs
-     * multiple times. If it's already started, we just pick up the
-     * existing startup promise.
-     *
-     * 2. We are updating the $scope asynchronously, but since it's
-     * done inside a promise resolver, another $digest() loop will
-     * run and pick up our changes.  No $scope.$apply() needed.
-     */
-    if ($location.path() != '/login') {
-        // avoiding rending user info on the login page
-
-        egCore.startup.go().then(
-            function() {
-                $scope.username = egCore.auth.user().usrname();
-                $scope.workstation = egCore.auth.workstation();
-            }
-        );
-    }
-}
-
-// minify-safe dependency injection
-NavCtrl.$inject = ['$scope', '$window', '$location', 'egCore'];
-
index c43ca39..e0ef021 100644 (file)
@@ -3,4 +3,4 @@
  * egCoreMod houses all of the services, etc. required by all pages
  * for basic functionality.
  */
-angular.module('egCoreMod', []);
+angular.module('egCoreMod', ['cfp.hotkeys']);
diff --git a/Open-ILS/web/js/ui/default/staff/services/navbar.js b/Open-ILS/web/js/ui/default/staff/services/navbar.js
new file mode 100644 (file)
index 0000000..eb0d25e
--- /dev/null
@@ -0,0 +1,73 @@
+angular.module('egCoreMod')
+
+.directive('egNavbar', function() {
+    return {
+        restrict : 'AE',
+        transclude : true,
+        templateUrl : 'eg-navbar-template',
+        link : function(scope, element, attrs) {
+
+            // Find all eg-accesskey entries within the menu and attach
+            // hotkey handlers for each.  
+            // jqlite doesn't support selectors, so we have to 
+            // manually navigate to the elements we're interested in.
+            function inspect(elm) {
+                elm = angular.element(elm);
+                if (elm.attr('eg-accesskey')) {
+                    scope.addHotkey(
+                        elm.attr('eg-accesskey'),
+                        elm.attr('href'),
+                        elm.attr('eg-accesskey-desc')
+                    );
+                }
+                angular.forEach(elm.children(), inspect);
+            }
+            inspect(element);
+        },
+
+        controller:['$scope','$window','$location','hotkeys','egCore',
+            function($scope , $window , $location , hotkeys , egCore) {
+
+                function navTo(path) {                                           
+                    // $location.path() does not want a leading ".",
+                    // which <a>'s will have
+                    path = path.replace(/^\./,'');
+
+                    // navigates to the requested path as a new page
+                    $window.location.href = $location.path(path).absUrl();                
+                }       
+
+                // adds a keyboard shortcut
+                // http://chieffancypants.github.io/angular-hotkeys/
+                $scope.addHotkey = function(key, path, desc) {                 
+                    hotkeys.add(key, desc, function() { navTo(path) });
+                };
+
+                $scope.applyLocale = function(locale) {
+                    // EGWeb.pm can change the locale for us w/ the right param
+                    $window.location.href = 
+                        $location.search('set_eg_locale', locale).absUrl();
+                }
+
+                // tied to logout link
+                $scope.logout = function() {
+                    egCore.auth.logout();
+                    return true;
+                };
+
+                // display the username and workstation after startup completes
+                if ($location.path() != '/login') {
+                    // avoiding rending user info on the login page
+
+                    egCore.startup.go().then(
+                        function() {
+                            $scope.username = egCore.auth.user().usrname();
+                            $scope.workstation = egCore.auth.workstation();
+                        }
+                    );
+                }
+            }
+        ]
+    }
+});