diff --git a/guacamole/src/main/frontend/src/app/index/controllers/indexController.js b/guacamole/src/main/frontend/src/app/index/controllers/indexController.js index 722b27bd8..7fc18d061 100644 --- a/guacamole/src/main/frontend/src/app/index/controllers/indexController.js +++ b/guacamole/src/main/frontend/src/app/index/controllers/indexController.js @@ -228,6 +228,22 @@ angular.module('index').controller('indexController', ['$scope', '$injector', }, true); + /** + * Sets the current overall state of the client side of the + * application to the given value. Possible values are defined by + * {@link ApplicationState}. The title and class associated with the + * current page are automatically reset to the standard values applicable + * to the application as a whole (rather than any specific page). + * + * @param {!string} state + * The state to assign, as defined by {@link ApplicationState}. + */ + const setApplicationState = function setApplicationState(state) { + $scope.applicationState = state; + $scope.page.title = 'APP.NAME'; + $scope.page.bodyClassName = ''; + }; + /** * Navigates the user back to the root of the application (or reloads the * current route and controller if the user is already there), effectively @@ -250,9 +266,7 @@ angular.module('index').controller('indexController', ['$scope', '$injector', // Display login screen if a whole new set of credentials is needed $scope.$on('guacInvalidCredentials', function loginInvalid(event, parameters, error) { - $scope.applicationState = ApplicationState.AWAITING_CREDENTIALS; - $scope.page.title = 'APP.NAME'; - $scope.page.bodyClassName = ''; + setApplicationState(ApplicationState.AWAITING_CREDENTIALS); $scope.loginHelpText = null; $scope.acceptedCredentials = {}; @@ -263,9 +277,7 @@ angular.module('index').controller('indexController', ['$scope', '$injector', // Prompt for remaining credentials if provided credentials were not enough $scope.$on('guacInsufficientCredentials', function loginInsufficient(event, parameters, error) { - $scope.applicationState = ApplicationState.AWAITING_CREDENTIALS; - $scope.page.title = 'APP.NAME'; - $scope.page.bodyClassName = ''; + setApplicationState(ApplicationState.AWAITING_CREDENTIALS); $scope.loginHelpText = error.translatableMessage; $scope.acceptedCredentials = parameters; @@ -283,10 +295,7 @@ angular.module('index').controller('indexController', ['$scope', '$injector', || error.type === Error.Type.INVALID_CREDENTIALS) return; - $scope.applicationState = ApplicationState.AUTOMATIC_LOGIN_REJECTED; - $scope.page.title = 'APP.NAME'; - $scope.page.bodyClassName = ''; - + setApplicationState(ApplicationState.AUTOMATIC_LOGIN_REJECTED); $scope.reAuthenticating = false; $scope.fatalError = error; @@ -295,13 +304,8 @@ angular.module('index').controller('indexController', ['$scope', '$injector', // Replace absolutely all content with an error message if the page itself // cannot be displayed due to an error $scope.$on('guacFatalPageError', function fatalPageError(error) { - - $scope.applicationState = ApplicationState.FATAL_ERROR; - $scope.page.title = 'APP.NAME'; - $scope.page.bodyClassName = ''; - + setApplicationState(ApplicationState.FATAL_ERROR); $scope.fatalError = error; - }); // Replace the overall user interface with an informational message if the