1 angular.module('egCoreMod')
3 .directive('egNavbar', function() {
7 templateUrl : 'eg-navbar-template',
8 link : function(scope, element, attrs) {
10 // Find all eg-accesskey entries within the menu and attach
11 // hotkey handlers for each.
12 // jqlite doesn't support selectors, so we have to
13 // manually navigate to the elements we're interested in.
14 function inspect(elm) {
15 elm = angular.element(elm);
16 if (elm.attr('eg-accesskey')) {
18 elm.attr('eg-accesskey'),
20 elm.attr('eg-accesskey-desc'),
24 angular.forEach(elm.children(), inspect);
29 controller:['$scope','$window','$location','$timeout','hotkeys','egCore','$uibModal','ngToast',
30 function($scope , $window , $location , $timeout , hotkeys , egCore , $uibModal , ngToast) {
32 function navTo(path) {
33 // Strip the leading "./" if any.
34 path = path.replace(/^\.\//,'');
35 var reg = new RegExp($location.path());
36 $window.location.href = egCore.env.basePath + path;
39 // adds a keyboard shortcut
40 // http://chieffancypants.github.io/angular-hotkeys/
41 $scope.addHotkey = function(key, path, desc, elm) {
44 allowIn: ['INPUT','SELECT','TEXTAREA'],
46 callback: function(e) {
48 if (path) return navTo(path);
49 return $timeout(function(){$(elm).trigger('click')});
54 $scope.retrieveLastRecord = function() {
55 var last_record = egCore.hatch.getLocalItem("eg.cat.last_record_retrieved");
57 $window.location.href =
58 egCore.env.basePath + 'cat/catalog/record/' + last_record;
62 $scope.applyLocale = function(locale) {
63 // EGWeb.pm can change the locale for us w/ the right param
64 // Note: avoid using $location.search() to derive a new
65 // URL, since it creates an intermediate path change.
66 // Instead, use the ham-fisted approach of killing any
67 // search args and applying the args we want.
68 $window.location.href =
69 $window.location.href.replace(
71 '?set_eg_locale=' + encodeURIComponent(locale)
75 $scope.changeOperatorUndo = function() {
76 egCore.auth.opChangeUndo();
77 $scope.op_changed = false;
78 $scope.username = egCore.auth.user().usrname();
79 ngToast.create(egCore.strings.OP_CHANGE_SUCCESS);
82 $scope.changeOperator = function() {
84 templateUrl: './share/t_opchange',
86 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
87 $scope.args = {username : '', password : '', type : 'temp'};
89 $scope.ok = function() { $uibModalInstance.close($scope.args) }
90 $scope.cancel = function () { $uibModalInstance.dismiss() }
92 }).result.then(function (args) {
93 if (!args || !args.username || !args.password) return;
94 args.type = args.type || 'temp';
95 args.workstation = egCore.auth.workstation();
96 egCore.auth.opChange(args).then(
98 console.log('op change success');
99 $scope.op_changed = true;
100 $scope.username = egCore.auth.user().usrname();
101 ngToast.create(egCore.strings.OP_CHANGE_SUCCESS);
102 }, // note success with toast?
104 console.log('op change failure');
105 ngToast.warning(egCore.strings.OP_CHANGE_FAILURE);
106 } // note failure with toast?
111 $scope.currentToken = function () {
112 return egCore.auth.token();
115 // tied to logout link
116 $scope.logout = function() {
117 egCore.auth.logout();
121 egCore.startup.go().then(
123 if (egCore.auth.user()) {
124 $scope.op_changed = egCore.auth.OCtoken() ? true : false;
125 $scope.username = egCore.auth.user().usrname();
126 $scope.workstation = egCore.auth.workstation();