Show username on topbar menu
[dlux.git] / modules / common-topbar-resources / src / main / resources / topbar / topbar.controller.js
1 define(['common/topbar/topbar.module', 'common/topbar/topbar.directives', 'common/authentification/auth.services'], function(topbar) {
2
3     topbar.controller('TopbarCtrl', function() {
4         $('#toggleMenu').click(function(e) {
5             e.preventDefault();
6             $('#wrapper').toggleClass('toggled');
7         });
8     });
9
10     topbar.controller('topBarTasksCtrl', function($scope, taskFactory) {
11         $scope.tasks = taskFactory.getTaskData();
12     });
13
14     topbar.controller('topBarNotifsCtrl', function($scope, notifsFactory) {
15         $scope.notifs = notifsFactory.getNotifsData();
16         $scope.isValid = function(value) {
17             if (angular.isUndefined(value) || value === null) {
18                 return false;
19             } else {
20                 return true;
21             }
22         };
23     });
24
25     topbar.controller('topBarMessagesCtrl', function($scope, messageFactory) {
26         $scope.messages = messageFactory.getMessageData();
27         $scope.isValid = function(value) {
28             if (angular.isUndefined(value) || value === null) {
29                 return false;
30             } else {
31                 return true;
32             }
33         };
34     });
35
36     // the authorization module is not converted yet
37     topbar.controller('topBarUserMenuCtrl', function($scope, $cookieStore, Auth, $window) {
38         $scope.logOut = logout;
39
40         /**
41          * Provides logout from application and redirects to login page
42          * @return {[type]} [description]
43          */
44         function logout() {
45             Auth.logout(function() {
46                 $window.location.href = 'index.html#/login';
47             });
48         }
49
50         $scope.getUsername = function() {
51             return $window.localStorage.odlUser;
52         };
53     });
54 });