1 angular.module('egCoreMod')
3 .directive('egNavbar', function() {
7 templateUrl : 'eg-navbar-template',
8 controller:['$scope','$window','$location','$timeout','hotkeys','$rootScope',
9 'egCore','$uibModal','ngToast','egOpChange','$element','egLovefield',
10 function($scope , $window , $location , $timeout , hotkeys , $rootScope ,
11 egCore , $uibModal , ngToast , egOpChange , $element , egLovefield) {
13 $scope.rs = $rootScope;
15 $scope.reprintLast = function (e) {
16 egCore.print.reprintLast();
17 return e.preventDefault();
20 function navTo(path) {
21 path = path.replace(/^\.\//,'');
22 $window.location.href = egCore.env.basePath + path;
25 // adds a keyboard shortcut
26 // http://chieffancypants.github.io/angular-hotkeys/
27 $scope.addHotkey = function(key, path, desc, elm) {
28 angular.forEach(key.split(' '), function (k) {
31 allowIn: ['INPUT','SELECT','TEXTAREA'],
33 callback: function(e) {
35 if (path) return navTo(path);
36 return $timeout(function(){$(elm).trigger('click')});
42 function find_accesskeys(elm) {
43 elm = angular.element(elm);
44 if (elm.attr('eg-accesskey')) {
46 elm.attr('eg-accesskey'),
48 elm.attr('eg-accesskey-desc'),
52 angular.forEach(elm.children(), find_accesskeys);
55 $scope.retrieveLastRecord = function() {
56 var last_record = egCore.hatch.getLocalItem("eg.cat.last_record_retrieved");
58 $window.location.href =
59 egCore.env.basePath + 'cat/catalog/record/' + last_record;
63 $scope.applyLocale = function(locale) {
64 // EGWeb.pm can change the locale for us w/ the right param
65 // Note: avoid using $location.search() to derive a new
66 // URL, since it creates an intermediate path change.
67 // Instead, use the ham-fisted approach of killing any
68 // search args and applying the args we want.
69 $window.location.href =
70 $window.location.href.replace(
72 '?set_eg_locale=' + encodeURIComponent(locale)
76 $scope.changeOperatorUndo = function() {
77 egOpChange.changeOperatorUndo().then(function() {
78 $scope.op_changed = false;
79 $scope.username = egCore.auth.user().usrname();
83 $scope.changeOperator = function() {
84 egOpChange.changeOperator().then(function() {
85 $scope.op_changed = egCore.auth.OCtoken() ? true : false;
86 $scope.username = egCore.auth.user().usrname();
90 $scope.currentToken = function () {
91 return egCore.auth.token();
94 // Returns true if the browser is connected to Hatch
95 $scope.hatchConnected = function() {
96 return egCore.hatch.hatchAvailable;
99 // tied to logout link
100 $scope.logout = function() {
101 egCore.auth.logout();
105 $scope.offlineDisabled = function() {
106 return egLovefield.cannotConnect;
109 egCore.startup.go().then(
111 if (egCore.auth.user()) {
112 $scope.op_changed = egCore.auth.OCtoken() ? true : false;
113 $scope.username = egCore.auth.user().usrname();
114 $scope.workstation = egCore.auth.workstation();
116 egCore.org.settings([
117 'ui.staff.max_recent_patrons',
118 'ui.staff.angular_catalog.enabled'
119 ]).then(function(s) {
120 var val = s['ui.staff.max_recent_patrons'];
121 $scope.showRecentPatron = val > 0;
122 $scope.showRecentPatrons = val > 1;
124 $scope.showAngularCatalog =
125 s['ui.staff.angular_catalog.enabled'];
128 // need to defer initialization of hotkeys to this point
129 // as some of them are conditional on whether one is logged in
130 // or is working in offline circulation mode
131 $timeout(function(){find_accesskeys($element)});