1 angular.module('egCoreMod')
3 .directive('egNavbar', function() {
7 templateUrl : 'eg-navbar-template',
8 link : function(scope, element, attrs) {
10 // Find all eg-accesskey entries within the menu and attach
11 // hotkey handlers for each.
12 // jqlite doesn't support selectors, so we have to
13 // manually navigate to the elements we're interested in.
14 function inspect(elm) {
15 elm = angular.element(elm);
16 if (elm.attr('eg-accesskey')) {
18 elm.attr('eg-accesskey'),
20 elm.attr('eg-accesskey-desc')
23 angular.forEach(elm.children(), inspect);
28 controller:['$scope','$window','$location','hotkeys','egCore',
29 function($scope , $window , $location , hotkeys , egCore) {
31 function navTo(path) {
32 // $location.path() does not want a leading ".",
33 // which <a>'s will have.
34 // Note: avoid using $location.path() to derive the new
35 // URL, since it creates an intermediate path change.
36 path = path.replace(/^\./,'');
37 var reg = new RegExp($location.path());
38 $window.location.href =
39 $window.location.href.replace(reg, path);
42 // adds a keyboard shortcut
43 // http://chieffancypants.github.io/angular-hotkeys/
44 $scope.addHotkey = function(key, path, desc) {
45 hotkeys.add(key, desc, function(e) { e.preventDefault(); navTo(path); });
48 $scope.retrieveLastRecord = function() {
49 var last_record = egCore.hatch.getLocalItem("eg.cat.last_record_retrieved");
51 $window.location.href =
52 egCore.env.basePath + 'cat/catalog/record/' + last_record;
56 $scope.applyLocale = function(locale) {
57 // EGWeb.pm can change the locale for us w/ the right param
58 // Note: avoid using $location.search() to derive a new
59 // URL, since it creates an intermediate path change.
60 // Instead, use the ham-fisted approach of killing any
61 // search args and applying the args we want.
62 $window.location.href =
63 $window.location.href.replace(
65 '?set_eg_locale=' + encodeURIComponent(locale)
69 // tied to logout link
70 $scope.logout = function() {
75 egCore.startup.go().then(
77 if (egCore.auth.user()) {
78 $scope.username = egCore.auth.user().usrname();
79 $scope.workstation = egCore.auth.workstation();