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

57 lines
1.6 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-06-22 13:56:21 +02:00
I18nService().setCurrentLanguage(vm.currentLanguage);
console.log('current language:' + vm.languageName);
vm.supportLanguages = I18nService().getSupportLanguages();
vm.user = currentUser.get();
vm.setLanguage = setLanguage;
vm.logOut = logOut;
2016-06-22 13:56:21 +02:00
function setLanguage(language) {
I18nService().setCurrentLanguage(language);
2016-06-28 17:42:05 +02:00
var hash = $window.location.hash;
$window.location.href = '/language?lang=' + language + '&hash=' + encodeURIComponent(hash);
2016-05-13 12:48:06 +02:00
}
function logOut() {
LogOutService()
.success(logOutSuccess)
.error(logOutFailed);
}
function logOutSuccess(data, status) {
currentUser.unset();
$window.location.href= '/';
}
function logOutFailed(data, status) {
console.log('Failed to log out:' + data);
}
}
function optionalMenu() {
var directive = {
'restrict': 'E',
'templateUrl': '/optional_menu',
'scope': true,
'controller': OptionalMenuController,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
}
})();