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) {
22 if (path.match(/^\/eg2\//)) {
23 // Hotkey for /eg2/ page. Go directly to the
25 $window.location.href = path;
29 path = path.replace(/^\.\//,'');
30 $window.location.href = egCore.env.basePath + path;
33 // adds a keyboard shortcut
34 // http://chieffancypants.github.io/angular-hotkeys/
35 $scope.addHotkey = function(key, path, desc, elm) {
36 angular.forEach(key.split(' '), function (k) {
39 allowIn: ['INPUT','SELECT','TEXTAREA'],
41 callback: function(e) {
43 if (path) return navTo(path);
44 return $timeout(function(){$(elm).trigger('click')});
50 function find_accesskeys(elm) {
51 elm = angular.element(elm);
52 if (elm.attr('eg-accesskey')) {
54 elm.attr('eg-accesskey'),
56 elm.attr('eg-accesskey-desc'),
60 angular.forEach(elm.children(), find_accesskeys);
63 $scope.retrieveLastRecord = function() {
64 var last_record = egCore.hatch.getLocalItem("eg.cat.last_record_retrieved");
66 $window.location.href =
67 '/eg2/staff/catalog/record/' + last_record;
71 $scope.applyLocale = function(locale) {
72 // EGWeb.pm can change the locale for us w/ the right param
73 // Note: avoid using $location.search() to derive a new
74 // URL, since it creates an intermediate path change.
75 // Instead, use the ham-fisted approach of killing any
76 // search args and applying the args we want.
77 $window.location.href = egCore.env.basePath +
78 '?set_eg_locale=' + encodeURIComponent(locale);
81 $scope.changeOperatorUndo = function() {
82 egOpChange.changeOperatorUndo().then(function() {
83 $scope.op_changed = false;
84 $scope.username = egCore.auth.user().usrname();
88 $scope.changeOperator = function() {
89 egOpChange.changeOperator().then(function() {
90 $scope.op_changed = egCore.auth.OCtoken() ? true : false;
91 $scope.username = egCore.auth.user().usrname();
95 $scope.currentToken = function () {
96 return egCore.auth.token();
99 // Returns true if the browser is connected to Hatch
100 $scope.hatchConnected = function() {
101 return egCore.hatch.hatchAvailable;
104 // tied to logout link
105 $scope.logout = function() {
106 egCore.auth.logout();
110 $scope.offlineDisabled = function() {
111 return egLovefield.cannotConnect;
114 egCore.startup.go().then(
116 if (egCore.auth.user()) {
117 $scope.op_changed = egCore.auth.OCtoken() ? true : false;
118 $scope.username = egCore.auth.user().usrname();
119 $scope.user_id = egCore.auth.user().id();
120 $scope.ws_ou = egCore.auth.user().ws_ou();
121 $scope.workstation = egCore.auth.workstation();
123 egCore.org.settings([
124 'ui.staff.max_recent_patrons',
125 'ui.staff.angular_catalog.enabled',
127 ]).then(function(s) {
128 var val = s['ui.staff.max_recent_patrons'];
129 $scope.showRecentPatron = val > 0;
130 $scope.showRecentPatrons = val > 1;
132 $scope.showAngularCatalog =
133 s['ui.staff.angular_catalog.enabled'];
134 $scope.enableCurbside =
137 // need to defer initialization of hotkeys to this point
138 // as it depends on various settings.
139 $timeout(function(){find_accesskeys($element)});
142 // fallback initialization of hotkeys
143 $timeout(function(){find_accesskeys($element)});