2016-07-07 18:03:32 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
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-06-22 13:56:21 +02:00
|
|
|
I18nService().setCurrentLanguage(vm.currentLanguage);
|
|
|
|
|
2016-06-20 10:05:14 +02:00
|
|
|
console.log('current language:' + vm.languageName);
|
|
|
|
|
|
|
|
vm.supportLanguages = I18nService().getSupportLanguages();
|
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-06-22 13:56:21 +02:00
|
|
|
|
2016-05-21 11:20:39 +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
|
|
|
}
|
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-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-07-05 07:03:18 +02:00
|
|
|
'templateUrl': '/optional_menu?timestamp=' + new Date().getTime(),
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|