navbar.directive.js
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(function() {
'use strict';
angular
.module('noosferoApp')
.directive('acmeNavbar', acmeNavbar);
/** @ngInject */
function acmeNavbar() {
var directive = {
restrict: 'E',
templateUrl: 'app/components/navbar/navbar.html',
scope: {},
controller: NavbarController,
controllerAs: 'vm',
bindToController: true
};
return directive;
/** @ngInject */
function NavbarController(moment, $modal, AuthService, Session, $scope, $state, AUTH_EVENTS) {
var vm = this;
vm.currentUser = Session.getCurrentUser();
vm.modalInstance = null;
vm.openLogin = function() {
vm.modalInstance = $modal.open({
templateUrl: 'app/components/auth/login.html',
controller: 'AuthController',
controllerAs: 'vm',
bindToController: true
});
};
vm.logout = function() {
AuthService.logout();
$state.go($state.current, {}, {reload: true}); //TODO move to auth
};
$scope.$on(AUTH_EVENTS.loginSuccess, function() {
if(vm.modalInstance) {
vm.modalInstance.close();
vm.modalInstance = null;
}
$state.go($state.current, {}, {reload: true}); //TODO move to auth
});
$scope.$on(AUTH_EVENTS.logoutSuccess, function() {
vm.currentUser = Session.getCurrentUser();
});
vm.activate = function() {
if(!vm.currentUser) vm.openLogin();
}
vm.activate();
}
}
})();