tellform/public/modules/core/controllers/header.client.controller.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-06-29 22:51:29 +00:00
'use strict';
2016-05-10 07:41:10 +00:00
angular.module('core').controller('HeaderController', ['$rootScope', '$scope', 'Menus', '$state', 'Auth', 'User', '$window',
2016-05-10 07:25:00 +00:00
function ($rootScope, $scope, Menus, $state, Auth, User, $window) {
$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
2015-07-07 01:21:43 +00:00
$rootScope.languages = $scope.languages = ['english', 'french', 'spanish'];
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');
},
2015-07-07 01:56:38 +00:00
function(reason) {
console.log('Logout Failed: ' + reason);
});
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
]);