2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-16 00:38:22 +00:00
|
|
|
angular.module('core').controller('HeaderController', ['$rootScope', '$scope', 'Menus', '$state', 'Auth', 'User', '$window', '$translate', '$locale',
|
|
|
|
function ($rootScope, $scope, Menus, $state, Auth, User, $window, $translate, $locale) {
|
|
|
|
|
2016-05-10 07:25:00 +00:00
|
|
|
$rootScope.signupDisabled = $window.signupDisabled;
|
|
|
|
|
2015-07-01 23:14:39 +00:00
|
|
|
$scope.user = $rootScope.user = Auth.ensureHasCurrentUser(User);
|
|
|
|
$scope.authentication = $rootScope.authentication = Auth;
|
2015-07-28 22:29:07 +00:00
|
|
|
|
2016-06-16 00:38:22 +00:00
|
|
|
$rootScope.languages = $scope.languages = ['en', 'fr', 'es', 'it', 'de'];
|
|
|
|
|
|
|
|
console.log($locale.id);
|
|
|
|
//Set global app language
|
|
|
|
if($scope.authentication.isAuthenticated()){
|
|
|
|
$rootScope.language = $scope.user.language;
|
|
|
|
}else {
|
|
|
|
$rootScope.language = $locale.id.substring(0,2);
|
|
|
|
}
|
|
|
|
$translate.use($rootScope.language);
|
2015-07-01 23:14:39 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
$scope.isCollapsed = false;
|
2015-07-28 22:29:07 +00:00
|
|
|
$rootScope.hideNav = false;
|
2015-06-29 22:51:29 +00:00
|
|
|
$scope.menu = Menus.getMenu('topbar');
|
|
|
|
|
2015-07-01 23:14:39 +00:00
|
|
|
$scope.signout = function() {
|
2015-07-07 01:56:38 +00:00
|
|
|
var promise = User.logout();
|
|
|
|
promise.then(function() {
|
|
|
|
Auth.logout();
|
2015-07-28 22:29:07 +00:00
|
|
|
Auth.ensureHasCurrentUser(User);
|
|
|
|
$scope.user = $rootScope.user = null;
|
2016-04-28 01:40:51 +00:00
|
|
|
$state.go('listForms');
|
2016-08-25 23:33:10 +00:00
|
|
|
|
|
|
|
//Refresh view
|
|
|
|
$state.reload();
|
2016-04-28 01:40:51 +00:00
|
|
|
},
|
2015-07-07 01:56:38 +00:00
|
|
|
function(reason) {
|
2016-08-25 23:33:10 +00:00
|
|
|
console.error('Logout Failed: ' + reason);
|
2015-07-07 01:56:38 +00:00
|
|
|
});
|
2015-07-01 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleCollapsibleMenu = function() {
|
|
|
|
$scope.isCollapsed = !$scope.isCollapsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Collapsing the menu after navigation
|
|
|
|
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
|
|
|
|
$scope.isCollapsed = false;
|
2015-07-28 22:29:07 +00:00
|
|
|
$rootScope.hideNav = false;
|
2015-07-01 23:14:39 +00:00
|
|
|
if ( angular.isDefined( toState.data ) ) {
|
|
|
|
|
|
|
|
if ( angular.isDefined( toState.data.hideNav ) ) {
|
2015-07-28 22:29:07 +00:00
|
|
|
$rootScope.hideNav = toState.data.hideNav;
|
2015-07-01 23:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
2016-04-28 01:40:51 +00:00
|
|
|
]);
|