From 52d2fe166152e426e17a1aeca5f17c74a4cf4123 Mon Sep 17 00:00:00 2001 From: m-khan-glyptodon Date: Mon, 3 Dec 2018 09:28:49 -0800 Subject: [PATCH] GUACAMOLE-302: Additions are made to the login directive so that the appropriate field that needs to be focussed is determined. --- .../main/webapp/app/login/directives/login.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/guacamole/src/main/webapp/app/login/directives/login.js b/guacamole/src/main/webapp/app/login/directives/login.js index aad7020b9..6fc3441b0 100644 --- a/guacamole/src/main/webapp/app/login/directives/login.js +++ b/guacamole/src/main/webapp/app/login/directives/login.js @@ -102,6 +102,13 @@ angular.module('login').directive('guacLogin', [function guacLogin() { */ $scope.submitted = false; + /** + * The field that is most relevant to the user. + * + * @type Field + */ + $scope.relevantField = null; + /** * Returns whether a previous login attempt is continuing. * @@ -144,6 +151,8 @@ angular.module('login').directive('guacLogin', [function guacLogin() { $scope.enteredValues[field.name] = ''; }); + console.log(mostRelevantField()); + }); /** @@ -194,12 +203,35 @@ angular.module('login').directive('guacLogin', [function guacLogin() { delete $scope.enteredValues[field.name]; }); + + console.log(mostRelevantField()); } })); }; + /** + * Returns the field most relevant field to the user given the current + * state of the login process. This will normally be the first empty + * field. + * + * @return {Field} + * The field most relevant, null if there is no single most relevant + * field. + */ + var mostRelevantField = function findMostRelevantField() { + + for (var i = 0; i < $scope.remainingFields.length; i++) { + var field = $scope.remainingFields[i]; + if (!$scope.enteredValues[field.name]) + return field; + } + + return null; + + }; + // Reset state after authentication and routing have succeeded $rootScope.$on('$routeChangeSuccess', function routeChanged() { $scope.enteredValues = {};