2016-05-09 19:48:05 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.optional.menu')
|
|
|
|
.directive('optionalMenu', optionalMenu);
|
2016-05-10 12:43:52 +02:00
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
OptionalMenuController.$inject = ['$scope', '$window', '$cookies', 'I18nService', 'LogOutService'];
|
2016-05-10 12:43:52 +02:00
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function OptionalMenuController($scope, $window, $cookies, I18nService, LogOutService) {
|
2016-05-09 19:48:05 +02:00
|
|
|
var vm = this;
|
2016-05-13 12:48:06 +02:00
|
|
|
vm.currentLanguage = I18nService().getCurrentLanguage();
|
|
|
|
vm.setLanguage = setLanguage;
|
|
|
|
vm.languageName = I18nService().getLanguageName(vm.currentLanguage);
|
|
|
|
console.log('current language:' + I18nService().getCurrentLanguage());
|
|
|
|
|
2016-05-12 12:30:01 +02:00
|
|
|
vm.logOut = logOut;
|
2016-05-13 12:48:06 +02:00
|
|
|
|
|
|
|
function setLanguage(name) {
|
|
|
|
I18nService().setCurrentLanguage(name);
|
|
|
|
}
|
|
|
|
|
2016-05-12 12:30:01 +02:00
|
|
|
function logOut() {
|
|
|
|
LogOutService()
|
|
|
|
.success(logOutSuccess)
|
|
|
|
.error(logOutFailed);
|
|
|
|
}
|
|
|
|
function logOutSuccess(data, status) {
|
|
|
|
$window.location.href= '/ng';
|
|
|
|
}
|
|
|
|
function logOutFailed(data, status) {
|
|
|
|
console.log('Failed to log out:' + data);
|
|
|
|
}
|
2016-05-09 19:48:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function optionalMenu() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
|
|
|
'templateUrl': '/static/ng/resources/js/components/optional-menu/optional-menu.directive.html',
|
|
|
|
'link': link,
|
2016-05-10 12:43:52 +02:00
|
|
|
'scope': true,
|
2016-05-09 19:48:05 +02:00
|
|
|
'controller': OptionalMenuController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
|
|
|
};
|
|
|
|
return directive;
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
2016-05-10 12:43:52 +02:00
|
|
|
ctrl.isLoggedIn = false;
|
|
|
|
scope.$on('currentUser', function(e, val) {
|
|
|
|
if(val != null) {
|
|
|
|
ctrl.isLoggedIn = true;
|
|
|
|
ctrl.username = val.username;
|
2016-05-09 19:48:05 +02:00
|
|
|
}
|
2016-05-10 12:43:52 +02:00
|
|
|
scope.$apply();
|
2016-05-09 19:48:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|