From 6e9b9cb8d635043d913f0608eb75a41b33764818 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 21 Dec 2015 13:03:08 +0100 Subject: [PATCH 1/4] JS: Add autofocus behavior refs #10671 --- public/js/icinga/behavior/autofocus.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 public/js/icinga/behavior/autofocus.js diff --git a/public/js/icinga/behavior/autofocus.js b/public/js/icinga/behavior/autofocus.js new file mode 100644 index 000000000..23236f072 --- /dev/null +++ b/public/js/icinga/behavior/autofocus.js @@ -0,0 +1,24 @@ +/*! Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ + +(function(Icinga, $) { + + 'use strict'; + + Icinga.Behaviors = Icinga.Behaviors || {}; + + var Autofocus = function (icinga) { + Icinga.EventListener.call(this, icinga); + this.on('rendered', this.onRendered, this); + }; + + Autofocus.prototype = new Icinga.EventListener(); + + Autofocus.prototype.onRendered = function(e) { + if (document.activeElement === document.body) { + $(e.target).find('.autofocus').focus(); + } + }; + + Icinga.Behaviors.Autofocus = Autofocus; + +})(Icinga, jQuery); From ca1f4120805c95e4ef04e3f70b9836fd1861c90b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 21 Dec 2015 13:03:28 +0100 Subject: [PATCH 2/4] JS: Include autofocus behavior refs #10671 --- library/Icinga/Web/JavaScript.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/Icinga/Web/JavaScript.php b/library/Icinga/Web/JavaScript.php index 241c6aa44..c0942c616 100644 --- a/library/Icinga/Web/JavaScript.php +++ b/library/Icinga/Web/JavaScript.php @@ -23,6 +23,7 @@ class JavaScript 'js/icinga/module.js', 'js/icinga/timezone.js', 'js/icinga/behavior/application-state.js', + 'js/icinga/behavior/autofocus.js', 'js/icinga/behavior/tooltip.js', 'js/icinga/behavior/sparkline.js', 'js/icinga/behavior/tristate.js', From 1b196e61a6a90ab2c550a5c5d0463f44e38cc1dc Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 21 Dec 2015 13:03:58 +0100 Subject: [PATCH 3/4] Ignore application-state requests on setup --- public/js/icinga/behavior/application-state.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/js/icinga/behavior/application-state.js b/public/js/icinga/behavior/application-state.js index 73c62e416..d8196124d 100644 --- a/public/js/icinga/behavior/application-state.js +++ b/public/js/icinga/behavior/application-state.js @@ -16,7 +16,11 @@ ApplicationState.prototype = new Icinga.EventListener(); ApplicationState.prototype.onRendered = function(e) { - if (! $('#application-state').length && ! $('#login').length && ! $('#guest-error').length) { + if (! $('#application-state').length + && ! $('#login').length + && ! $('#guest-error').length + && ! $('#setup').length + ) { var _this = e.data.self; $('#layout').append( From f843ef2a47909b687426a5ef14684240b0e0fee7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 21 Dec 2015 13:05:57 +0100 Subject: [PATCH 4/4] Autofocus the setup token input refs #10671 --- modules/setup/application/forms/WelcomePage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/setup/application/forms/WelcomePage.php b/modules/setup/application/forms/WelcomePage.php index bc4c40b9f..71442cee9 100644 --- a/modules/setup/application/forms/WelcomePage.php +++ b/modules/setup/application/forms/WelcomePage.php @@ -31,6 +31,7 @@ class WelcomePage extends Form 'text', 'token', array( + 'class' => 'autofocus', 'required' => true, 'label' => $this->translate('Setup Token'), 'description' => $this->translate(