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-20 11:43:47 +02:00
|
|
|
OptionalMenuController.$inject = ['$window', 'I18nService', 'LogOutService', 'currentUser', '$timeout'];
|
2016-05-10 12:43:52 +02:00
|
|
|
|
2016-05-20 11:43:47 +02:00
|
|
|
function OptionalMenuController($window, I18nService, LogOutService, currentUser, $timeout) {
|
2016-05-09 19:48:05 +02:00
|
|
|
var vm = this;
|
2016-05-20 11:43:47 +02:00
|
|
|
|
2016-05-13 12:48:06 +02:00
|
|
|
vm.currentLanguage = I18nService().getCurrentLanguage();
|
|
|
|
vm.languageName = I18nService().getLanguageName(vm.currentLanguage);
|
2016-05-21 11:20:39 +02:00
|
|
|
|
2016-05-13 12:48:06 +02:00
|
|
|
console.log('current language:' + I18nService().getCurrentLanguage());
|
2016-05-21 11:20:39 +02:00
|
|
|
|
2016-05-21 05:26:19 +02:00
|
|
|
vm.user = currentUser.get();
|
2016-05-20 11:43:47 +02:00
|
|
|
vm.setLanguage = setLanguage;
|
2016-05-12 12:30:01 +02:00
|
|
|
vm.logOut = logOut;
|
2016-05-13 12:48:06 +02:00
|
|
|
|
2016-05-21 11:20:39 +02:00
|
|
|
function setLanguage(language) {
|
|
|
|
I18nService().setCurrentLanguage(language);
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = '/language?lang=' + language;
|
2016-05-13 12:48:06 +02:00
|
|
|
}
|
2016-05-12 12:30:01 +02:00
|
|
|
function logOut() {
|
|
|
|
LogOutService()
|
|
|
|
.success(logOutSuccess)
|
|
|
|
.error(logOutFailed);
|
|
|
|
}
|
|
|
|
function logOutSuccess(data, status) {
|
2016-05-20 11:43:47 +02:00
|
|
|
currentUser.unset();
|
2016-05-21 11:20:39 +02:00
|
|
|
I18nService().unset();
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href= '/';
|
2016-05-12 12:30:01 +02:00
|
|
|
}
|
|
|
|
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',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/optional_menu',
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|