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;
14 $scope.showAngularCirc = false;
16 $scope.reprintLast = function (e) {
17 egCore.print.reprintLast();
18 return e.preventDefault();
21 function navTo(path) {
23 if (path.match(/^\/eg2\//)) {
24 // Hotkey for /eg2/ page. Go directly to the
26 $window.location.href = path;
30 path = path.replace(/^\.\//,'');
31 $window.location.href = egCore.env.basePath + path;
34 // adds a keyboard shortcut
35 // http://chieffancypants.github.io/angular-hotkeys/
36 $scope.addHotkey = function(key, path, desc, elm) {
37 angular.forEach(key.split(' '), function (k) {
40 allowIn: ['INPUT','SELECT','TEXTAREA'],
42 callback: function(e) {
44 if (path) return navTo(path);
45 return $timeout(function(){$(elm).trigger('click')});
51 function find_accesskeys(elm) {
52 elm = angular.element(elm);
53 if (elm.attr('eg-accesskey')) {
55 elm.attr('eg-accesskey'),
57 elm.attr('eg-accesskey-desc'),
61 angular.forEach(elm.children(), find_accesskeys);
64 $scope.retrieveLastRecord = function() {
65 var last_record = egCore.hatch.getLocalItem("eg.cat.last_record_retrieved");
67 $window.location.href =
68 '/eg2/staff/catalog/record/' + last_record;
72 $scope.applyLocale = function(locale) {
73 // EGWeb.pm can change the locale for us w/ the right param
74 // Note: avoid using $location.search() to derive a new
75 // URL, since it creates an intermediate path change.
76 // Instead, use the ham-fisted approach of killing any
77 // search args and applying the args we want.
78 $window.location.href = egCore.env.basePath +
79 '?set_eg_locale=' + encodeURIComponent(locale);
82 $scope.changeOperatorUndo = function() {
83 egOpChange.changeOperatorUndo().then(function() {
84 $scope.op_changed = false;
85 $scope.username = egCore.auth.user().usrname();
89 $scope.changeOperator = function() {
90 egOpChange.changeOperator().then(function() {
91 $scope.op_changed = egCore.auth.OCtoken() ? true : false;
92 $scope.username = egCore.auth.user().usrname();
96 $scope.currentToken = function () {
97 return egCore.auth.token();
100 // Returns true if the browser is connected to Hatch
101 $scope.hatchConnected = function() {
102 return egCore.hatch.hatchAvailable;
105 // tied to logout link
106 $scope.logout = function() {
107 egCore.auth.logout();
111 $scope.offlineDisabled = function() {
112 return egLovefield.cannotConnect;
115 egCore.startup.go().then(
117 if (egCore.auth.user()) {
118 $scope.op_changed = egCore.auth.OCtoken() ? true : false;
119 $scope.username = egCore.auth.user().usrname();
120 $scope.user_id = egCore.auth.user().id();
121 $scope.ws_ou = egCore.auth.user().ws_ou();
122 $scope.workstation = egCore.auth.workstation();
124 egCore.org.settings([
125 'ui.staff.max_recent_patrons',
126 'ui.staff.traditional_catalog.enabled',
127 'ui.staff.angular_circ.enabled',
128 'ui.staff.angular_acq_selection.enabled',
130 ]).then(function(s) {
131 var val = s['ui.staff.max_recent_patrons'];
132 $scope.showRecentPatron = val > 0;
133 $scope.showRecentPatrons = val > 1;
135 val = s['ui.staff.traditional_catalog.enabled'];
136 $scope.showTraditionalCatalog = (val !== false);
137 $scope.showAngularAcq =
138 s['ui.staff.angular_acq_selection.enabled'];
139 $scope.enableCurbside = s['circ.curbside'];
141 if (s['ui.staff.angular_circ.enabled']) {
142 egCore.perm.hasPermHere('ACCESS_ANGULAR_CIRC')
143 .then(function(yes) { $scope.showAngularCirc = yes; });
146 // need to defer initialization of hotkeys to this point
147 // as it depends on various settings.
148 $timeout(function(){find_accesskeys($element)});
151 // fallback initialization of hotkeys
152 $timeout(function(){find_accesskeys($element)});