ohmyform/public/modules/core/controllers/header.client.controller.js
wodka 1caf34c230 Merge remote-tracking branch 'origin/fixUXBugs' into features/missing
# Conflicts:
#	.gitignore
#	app/views/form.server.view.pug
#	package-lock.json
#	package.json
#	public/form_modules/forms/base/config/i18n/french.js
#	public/modules/core/config/core.client.routes.js
#	public/modules/core/config/i18n/french.js
#	public/modules/core/controllers/header.client.controller.js
#	public/modules/forms/admin/css/admin-form.css
#	public/modules/users/controllers/authentication.client.controller.js
#	public/modules/users/services/auth.client.service.js
#	scripts/create_admin.js
#	server.js
2019-07-11 23:32:25 +02:00

72 lines
2.0 KiB
JavaScript
Executable File

'use strict';
angular.module('core').controller('HeaderController', ['$rootScope', '$scope', 'Menus', '$state', 'Auth', 'User', '$window', '$translate',
function ($rootScope, $scope, Menus, $state, Auth, User, $window, $translate) {
$rootScope.signupDisabled = $window.signupDisabled;
Auth.ensureHasCurrentUser().then(function(currUser){
$scope.user = $rootScope.user = currUser;
$scope.authentication = $rootScope.authentication = Auth;
//Set global app language
$rootScope.language = $scope.user.language;
$translate.use($scope.user.language);
$scope.isCollapsed = false;
$rootScope.hideNav = false;
$scope.menu = Menus.getMenu('topbar');
$rootScope.languages = ['en', 'fr', 'es', 'it', 'de'];
$rootScope.langCodeToWord = {
'en': 'English',
'fr': 'Français',
'es': 'Español',
'it': 'Italiàno',
'de': 'Deutsch'
};
$rootScope.wordToLangCode = {
'English': 'en',
'Français': 'fr',
'Español': 'es',
'Italiàno': 'it',
'Deutsch': 'de'
};
$scope.signout = function() {
var promise = User.logout();
promise.then(function() {
Auth.logout();
$scope.user = $rootScope.user = null;
$state.go('signin', { reload: true });
},
function(reason) {
console.error('Logout Failed: ' + reason);
});
};
$scope.toggleCollapsibleMenu = function() {
$scope.isCollapsed = !$scope.isCollapsed;
};
// Collapsing the menu after navigation
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
$scope.isCollapsed = false;
$rootScope.hideNav = false;
if ( angular.isDefined( toState.data ) ) {
if ( angular.isDefined( toState.data.hideNav ) ) {
$rootScope.hideNav = toState.data.hideNav;
}
}
});
}, function(){
$state.go('signup');
})
}
]);