]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/services/navbar.js
LP2061136 - Stamping 1405 DB upgrade script
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / services / navbar.js
1 angular.module('egCoreMod')
2
3 .directive('egNavbar', function() {
4     return {
5         restrict : 'AE',
6         transclude : true,
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) {
12
13                 $scope.rs = $rootScope;
14                 $scope.showAngularCirc = false;
15
16                 $scope.reprintLast = function (e) {
17                     egCore.print.reprintLast();
18                     return e.preventDefault();
19                 }
20
21                 function navTo(path) {
22
23                     if (path.match(/^\/eg2\//)) {
24                         // Hotkey for /eg2/ page.  Go directly to the
25                         // provided URL.
26                         $window.location.href = path;
27                         return;
28                     }
29
30                     path = path.replace(/^\.\//,'');
31                     $window.location.href = egCore.env.basePath + path;
32                 }       
33
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) {
38                         hotkeys.add({
39                             combo: k,
40                             allowIn: ['INPUT','SELECT','TEXTAREA'],
41                             description: desc,
42                             callback: function(e) {
43                                 e.preventDefault();
44                                 if (path) return navTo(path);
45                                 return $timeout(function(){$(elm).trigger('click')});
46                             }
47                         });
48                     });
49                 };
50
51                 function find_accesskeys(elm) {
52                     elm = angular.element(elm);
53                     if (elm.attr('eg-accesskey')) {
54                         $scope.addHotkey(
55                             elm.attr('eg-accesskey'),
56                             elm.attr('href'),
57                             elm.attr('eg-accesskey-desc'),
58                             elm
59                         );
60                     }
61                     angular.forEach(elm.children(), find_accesskeys);
62                 }
63
64                 $scope.retrieveLastRecord = function() {
65                     var last_record = egCore.hatch.getLocalItem("eg.cat.last_record_retrieved");
66                     if (last_record) {
67                         $window.location.href = 
68                             '/eg2/staff/catalog/record/' + last_record;
69                     }
70                 }
71
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);
80                 }
81
82                 $scope.changeOperatorUndo = function() {
83                     egOpChange.changeOperatorUndo().then(function() {
84                         $scope.op_changed = false;
85                         $scope.username = egCore.auth.user().usrname();
86                     });
87                 }
88
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();
93                     });
94                 }
95
96                 $scope.currentToken = function () {
97                     return egCore.auth.token();
98                 }
99
100                 // Returns true if the browser is connected to Hatch
101                 $scope.hatchConnected = function() {
102                     return egCore.hatch.hatchAvailable;
103                 }
104
105                 // tied to logout link
106                 $scope.logout = function() {
107                     egCore.auth.logout();
108                     return true;
109                 };
110
111                 $scope.offlineDisabled = function() {
112                     return egLovefield.cannotConnect;
113                 }
114
115                 egCore.startup.go().then(
116                     function() {
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();
123
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',
129                                 'circ.curbside'
130                             ]).then(function(s) {
131                                 var val = s['ui.staff.max_recent_patrons'];
132                                 $scope.showRecentPatron = val > 0;
133                                 $scope.showRecentPatrons = val > 1;
134
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'];
140
141                                 if (s['ui.staff.angular_circ.enabled']) {
142                                     egCore.perm.hasPermHere('ACCESS_ANGULAR_CIRC')
143                                     .then(function(yes) { $scope.showAngularCirc = yes; });
144                                 }
145                             }).then(function() {
146                                 // need to defer initialization of hotkeys to this point
147                                 // as it depends on various settings.
148                                 $timeout(function(){find_accesskeys($element)});
149                             });
150                         } else {
151                             // fallback initialization of hotkeys
152                             $timeout(function(){find_accesskeys($element)});
153                         }
154                     }
155                 );
156             }
157         ]
158     }
159 });
160