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')
23 angular.forEach(elm.children(), inspect);
28 controller:['$scope','$window','$location','hotkeys','egCore',
29 function($scope , $window , $location , hotkeys , egCore) {
31 function navTo(path) {
32 // $location.path() does not want a leading ".",
33 // which <a>'s will have.
34 // Note: avoid using $location.path() to derive the new
35 // URL, since it creates an intermediate path change.
36 path = path.replace(/^\./,'');
37 var reg = new RegExp($location.path());
38 $window.location.href =
39 $window.location.href.replace(reg, path);
42 // adds a keyboard shortcut
43 // http://chieffancypants.github.io/angular-hotkeys/
44 $scope.addHotkey = function(key, path, desc) {
45 hotkeys.add(key, desc, function() { navTo(path) });
48 $scope.applyLocale = function(locale) {
49 // EGWeb.pm can change the locale for us w/ the right param
50 // Note: avoid using $location.search() to derive a new
51 // URL, since it creates an intermediate path change.
52 // Instead, use the ham-fisted approach of killing any
53 // search args and applying the args we want.
54 $window.location.href =
55 $window.location.href.replace(
57 '?set_eg_locale=' + encodeURIComponent(locale)
61 // tied to logout link
62 $scope.logout = function() {
67 egCore.startup.go().then(
69 if (egCore.auth.user()) {
70 $scope.username = egCore.auth.user().usrname();
71 $scope.workstation = egCore.auth.workstation();