]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/services/navbar.js
bae819094459b25013865103e60c1948c6f51dc2
[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',
10             function($scope , $window , $location , $timeout , hotkeys , $rootScope ,
11                      egCore , $uibModal , ngToast , egOpChange , $element) {
12
13                 $scope.rs = $rootScope;
14
15                 $scope.reprintLast = function (e) {
16                     egCore.print.reprintLast();
17                     return e.preventDefault();
18                 }
19
20                 function navTo(path) {
21                     path = path.replace(/^\.\//,'');
22                     $window.location.href = egCore.env.basePath + path;
23                 }       
24
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) {
29                         hotkeys.add({
30                             combo: k,
31                             allowIn: ['INPUT','SELECT','TEXTAREA'],
32                             description: desc,
33                             callback: function(e) {
34                                 e.preventDefault();
35                                 if (path) return navTo(path,route);
36                                 return $timeout(function(){$(elm).trigger('click')});
37                             }
38                         });
39                     });
40                 };
41
42                 function inspect(elm) {
43                     elm = angular.element(elm);
44                     if (elm.attr('eg-accesskey')) {
45                         $scope.addHotkey(
46                             elm.attr('eg-accesskey'),
47                             elm.attr('href'),
48                             elm.attr('eg-accesskey-desc'),
49                             elm
50                         );
51                     }
52                     angular.forEach(elm.children(), inspect);
53                 }
54                 $timeout(function(){inspect($element)});
55
56                 $scope.retrieveLastRecord = function() {
57                     var last_record = egCore.hatch.getLocalItem("eg.cat.last_record_retrieved");
58                     if (last_record) {
59                         $window.location.href =
60                             egCore.env.basePath + 'cat/catalog/record/' + last_record;
61                     }
62                 }
63
64                 $scope.applyLocale = function(locale) {
65                     // EGWeb.pm can change the locale for us w/ the right param
66                     // Note: avoid using $location.search() to derive a new
67                     // URL, since it creates an intermediate path change.
68                     // Instead, use the ham-fisted approach of killing any
69                     // search args and applying the args we want.
70                     $window.location.href = 
71                         $window.location.href.replace(
72                             /(\?|\&).*/,
73                             '?set_eg_locale=' + encodeURIComponent(locale)
74                         );
75                 }
76
77                 $scope.changeOperatorUndo = function() {
78                     egOpChange.changeOperatorUndo().then(function() {
79                         $scope.op_changed = false;
80                         $scope.username = egCore.auth.user().usrname();
81                     });
82                 }
83
84                 $scope.changeOperator = function() {
85                     egOpChange.changeOperator().then(function() {
86                         $scope.op_changed = egCore.auth.OCtoken() ? true : false;
87                         $scope.username = egCore.auth.user().usrname();
88                     });
89                 }
90
91                 $scope.currentToken = function () {
92                     return egCore.auth.token();
93                 }
94
95                 // Returns true if the browser is connected to Hatch
96                 $scope.hatchConnected = function() {
97                     return egCore.hatch.hatchAvailable;
98                 }
99
100                 // tied to logout link
101                 $scope.logout = function() {
102                     egCore.auth.logout();
103                     return true;
104                 };
105
106                 egCore.startup.go().then(
107                     function() {
108                         if (egCore.auth.user()) {
109                             $scope.op_changed = egCore.auth.OCtoken() ? true : false;
110                             $scope.username = egCore.auth.user().usrname();
111                             $scope.workstation = egCore.auth.workstation();
112
113                             egCore.org.settings('ui.staff.max_recent_patrons')
114                             .then(function(s) {
115                                 var val = s['ui.staff.max_recent_patrons'];
116                                 $scope.showRecentPatron = val > 0;
117                                 $scope.showRecentPatrons = val > 1;
118                             });
119                         }
120                     }
121                 );
122             }
123         ]
124     }
125 });
126