JS: Maintain autosubmit focus

This commit is contained in:
Eric Lippmann 2016-01-18 13:28:36 +01:00
parent ebab4e8473
commit e1eb505986
3 changed files with 29 additions and 4 deletions

View File

@ -3,10 +3,13 @@
namespace Icinga\Forms\Authentication; namespace Icinga\Forms\Authentication;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Authentication\Auth; use Icinga\Authentication\Auth;
use Icinga\Authentication\User\ExternalBackend; use Icinga\Authentication\User\ExternalBackend;
use Icinga\User; use Icinga\User;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\StyleSheet;
use Icinga\Web\Url; use Icinga\Web\Url;
/** /**
@ -53,6 +56,24 @@ class LoginForm extends Form
'class' => isset($formData['username']) ? 'autofocus' : '' 'class' => isset($formData['username']) ? 'autofocus' : ''
) )
); );
if (! (bool) Config::app()->get('themes', 'disabled', false)) {
$themes = Icinga::app()->getThemes();
if (count($themes) > 1) {
$defaultTheme = Config::app()->get('themes', 'default', StyleSheet::DEFAULT_THEME);
if (isset($themes[$defaultTheme])) {
$themes[$defaultTheme] .= ' (' . $this->translate('default') . ')';
}
$this->addElement(
'select',
'theme',
array(
'label' => $this->translate('Theme', 'Form element label'),
'multiOptions' => $themes,
//'value' => null
)
);
}
}
$this->addElement( $this->addElement(
'hidden', 'hidden',
'redirect', 'redirect',

View File

@ -386,7 +386,9 @@
} }
} }
icinga.loader.loadUrl(url, $target, data, method).progressTimer = progressTimer; var req = icinga.loader.loadUrl(url, $target, data, method);
req.forceFocus = autosubmit ? $(event.currentTarget) : null;
req.progressTimer = progressTimer;
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();

View File

@ -554,7 +554,7 @@
} }
// .html() removes outer div we added above // .html() removes outer div we added above
this.renderContentToContainer($resp.html(), req.$target, req.action, req.autorefresh); this.renderContentToContainer($resp.html(), req.$target, req.action, req.autorefresh, req.forceFocus);
if (oldNotifications) { if (oldNotifications) {
oldNotifications.appendTo($('#notifications')); oldNotifications.appendTo($('#notifications'));
} }
@ -721,14 +721,16 @@
/** /**
* Smoothly render given HTML to given container * Smoothly render given HTML to given container
*/ */
renderContentToContainer: function (content, $container, action, autorefresh) { renderContentToContainer: function (content, $container, action, autorefresh, forceFocus) {
// Container update happens here // Container update happens here
var scrollPos = false; var scrollPos = false;
var self = this; var self = this;
var containerId = $container.attr('id'); var containerId = $container.attr('id');
var activeElementPath = false; var activeElementPath = false;
if (document.activeElement if (forceFocus && forceFocus.length) {
activeElementPath = this.icinga.utils.getCSSPath($(forceFocus));
} else if (document.activeElement
&& document.activeElement !== document.body && document.activeElement !== document.body
&& $.contains($container[0], document.activeElement) && $.contains($container[0], document.activeElement)
) { ) {