harbor/static/ng/resources/js/components/optional-menu/optional-menu.directive.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
angular
.module('harbor.optional.menu')
.directive('optionalMenu', optionalMenu);
OptionalMenuController.$inject = ['$window', 'I18nService', 'LogOutService', 'currentUser', '$timeout'];
function OptionalMenuController($window, I18nService, LogOutService, currentUser, $timeout) {
var vm = this;
2016-05-13 12:48:06 +02:00
vm.currentLanguage = I18nService().getCurrentLanguage();
vm.languageName = I18nService().getLanguageName(vm.currentLanguage);
2016-05-13 12:48:06 +02:00
console.log('current language:' + I18nService().getCurrentLanguage());
vm.user = currentUser.get();
vm.setLanguage = setLanguage;
vm.logOut = logOut;
2016-05-13 12:48:06 +02:00
function setLanguage(language) {
I18nService().setCurrentLanguage(language);
$window.location.href = '/ng/language?lang=' + language;
2016-05-13 12:48:06 +02:00
}
function logOut() {
LogOutService()
.success(logOutSuccess)
.error(logOutFailed);
}
function logOutSuccess(data, status) {
currentUser.unset();
I18nService().unset();
$window.location.href= '/ng';
}
function logOutFailed(data, status) {
console.log('Failed to log out:' + data);
}
}
function optionalMenu() {
var directive = {
'restrict': 'E',
'templateUrl': '/ng/optional_menu',
'scope': true,
'controller': OptionalMenuController,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
}
})();