generic way for initial focus

This commit is contained in:
Roland Gruber 2017-11-24 19:22:11 +01:00
parent 985acfb5f2
commit a1bee10fd1
5 changed files with 22 additions and 42 deletions

View File

@ -80,19 +80,7 @@ $tabindex = 1;
<body class="admin"> <body class="admin">
<?php <?php
printJsIncludes('../..'); printJsIncludes('../..');
// set focus on password field
?> ?>
<script type="text/javascript" language="javascript">
<!--
window.onload = function() {
loginField = document.getElementsByName('passwd')[0];
loginField.focus();
}
jQuery(document).ready(function() {
jQuery('#submitButton').button();
});
//-->
</script>
<table border=0 width="100%" class="lamHeader ui-corner-all"> <table border=0 width="100%" class="lamHeader ui-corner-all">
<tr> <tr>
<td align="left" height="30"> <td align="left" height="30">
@ -131,6 +119,7 @@ $tabindex = 1;
$box->add(new htmlResponsiveSelect('filename', $profiles, $selectedProfile, _('Profile name')), 12); $box->add(new htmlResponsiveSelect('filename', $profiles, $selectedProfile, _('Profile name')), 12);
$passwordInput = new htmlResponsiveInputField(_('Password'), 'passwd', '', '200'); $passwordInput = new htmlResponsiveInputField(_('Password'), 'passwd', '', '200');
$passwordInput->setIsPassword(true); $passwordInput->setIsPassword(true);
$passwordInput->setCSSClasses(array('lam-initial-focus'));
$box->add($passwordInput, 12); $box->add($passwordInput, 12);
$box->addVerticalSpacer('1rem'); $box->addVerticalSpacer('1rem');
$button = new htmlButton('submit', _("Ok")); $button = new htmlButton('submit', _("Ok"));

View File

@ -9,7 +9,6 @@ use \htmlButton;
use \htmlGroup; use \htmlGroup;
use \htmlResponsiveInputCheckbox; use \htmlResponsiveInputCheckbox;
use \LAMConfig; use \LAMConfig;
use \htmlTableExtendedInputCheckbox;
use \htmlResponsiveRow; use \htmlResponsiveRow;
use \htmlResponsiveInputField; use \htmlResponsiveInputField;
/* /*

View File

@ -72,15 +72,6 @@ printHeaderContents(_("Login"), '../..');
</head> </head>
<body class="admin"> <body class="admin">
<?php <?php
// set focus on password field
echo "<script type=\"text/javascript\" language=\"javascript\">\n";
echo "<!--\n";
echo "window.onload = function() {\n";
echo "loginField = document.getElementsByName('passwd')[0];\n";
echo "loginField.focus();\n";
echo "}\n";
echo "//-->\n";
echo "</script>\n";
// include all JavaScript files // include all JavaScript files
$jsDirName = dirname(__FILE__) . '/../lib'; $jsDirName = dirname(__FILE__) . '/../lib';
$jsDir = dir($jsDirName); $jsDir = dir($jsDirName);
@ -142,6 +133,7 @@ printHeaderContents(_("Login"), '../..');
$passwordField = new htmlInputField('passwd'); $passwordField = new htmlInputField('passwd');
$passwordField->setFieldSize(15); $passwordField->setFieldSize(15);
$passwordField->setIsPassword(true); $passwordField->setIsPassword(true);
$passwordField->setCSSClasses(array('lam-initial-focus'));
$passwordGroup->addElement($passwordField); $passwordGroup->addElement($passwordField);
$passwordGroup->addElement(new htmlHelpLink('236')); $passwordGroup->addElement(new htmlHelpLink('236'));
$passwordDiv = new htmlDiv(null, $passwordGroup); $passwordDiv = new htmlDiv(null, $passwordGroup);

View File

@ -866,10 +866,18 @@ window.lam.tools.activateTab = function() {
jQuery('.lam-active-tab').addClass('ui-tabs-active ui-state-active user-bright'); jQuery('.lam-active-tab').addClass('ui-tabs-active ui-state-active user-bright');
}; };
/**
* Sets the focus on the initial field.
*/
window.lam.tools.setInitialFocus = function() {
jQuery('.lam-initial-focus').focus();
};
jQuery(document).ready(function() { jQuery(document).ready(function() {
window.lam.gui.equalHeight(); window.lam.gui.equalHeight();
window.lam.form.autoTrim(); window.lam.form.autoTrim();
window.lam.account.addDefaultProfileListener(); window.lam.account.addDefaultProfileListener();
window.lam.tools.addSavedSelectListener(); window.lam.tools.addSavedSelectListener();
window.lam.tools.activateTab(); window.lam.tools.activateTab();
window.lam.tools.setInitialFocus();
}); });

View File

@ -194,7 +194,7 @@ function display_LoginPage(LAMConfig $config_object, LAMCfgMain $cfgMain, $licen
printHeaderContents('LDAP Account Manager', '..'); printHeaderContents('LDAP Account Manager', '..');
?> ?>
</head> </head>
<body class="admin" onload="focusLogin()"> <body class="admin">
<?php <?php
// include all JavaScript files // include all JavaScript files
printJsIncludes('..'); printJsIncludes('..');
@ -214,24 +214,6 @@ function display_LoginPage(LAMConfig $config_object, LAMCfgMain $cfgMain, $licen
if (isLAMProVersion() && $licenseValidator->isEvaluationLicense()) { if (isLAMProVersion() && $licenseValidator->isEvaluationLicense()) {
StatusMessage('INFO', _('Evaluation Licence')); StatusMessage('INFO', _('Evaluation Licence'));
} }
// set focus on password field
if (!empty($config_object)) {
echo "<script type=\"text/javascript\" language=\"javascript\">\n";
echo "<!--\n";
echo "function focusLogin() {\n";
if (($config_object->getLoginMethod() == LAMConfig::LOGIN_LIST) || isset($_COOKIE['lam_login_name'])) {
echo "myElement = document.getElementsByName('passwd')[0];\n";
echo "myElement.focus();\n";
}
else {
echo "myElement = document.getElementsByName('username')[0];\n";
echo "myElement.focus();\n";
}
echo "}\n";
echo "//-->\n";
echo "</script>\n";
}
?> ?>
<table border=0 width="100%" class="lamHeader ui-corner-all"> <table border=0 width="100%" class="lamHeader ui-corner-all">
@ -351,6 +333,9 @@ function display_LoginPage(LAMConfig $config_object, LAMCfgMain $cfgMain, $licen
$userSelect = new htmlSelect('username', $adminList, $selectedAdmin); $userSelect = new htmlSelect('username', $adminList, $selectedAdmin);
$userSelect->setHasDescriptiveElements(true); $userSelect->setHasDescriptiveElements(true);
$userSelect->setTransformSingleSelect(false); $userSelect->setTransformSingleSelect(false);
if (empty($_COOKIE['lam_login_name'])) {
$userSelect->setCSSClasses(array('lam-initial-focus'));
}
$row->addField(new htmlDiv(null, $userSelect)); $row->addField(new htmlDiv(null, $userSelect));
} }
else { else {
@ -364,7 +349,11 @@ function display_LoginPage(LAMConfig $config_object, LAMCfgMain $cfgMain, $licen
if (isset($_COOKIE["lam_login_name"])) { if (isset($_COOKIE["lam_login_name"])) {
$user = $_COOKIE["lam_login_name"]; $user = $_COOKIE["lam_login_name"];
} }
$userInput = new htmlDiv(null, new htmlInputField('username', $user)); $userNameInput = new htmlInputField('username', $user);
if (empty($_COOKIE['lam_login_name'])) {
$userNameInput->setCSSClasses(array('lam-initial-focus'));
}
$userInput = new htmlDiv(null, $userNameInput);
$row->addField($userInput); $row->addField($userInput);
} }
} }
@ -378,6 +367,9 @@ function display_LoginPage(LAMConfig $config_object, LAMCfgMain $cfgMain, $licen
else { else {
$passwordInput = new htmlInputField('passwd'); $passwordInput = new htmlInputField('passwd');
$passwordInput->setIsPassword(true); $passwordInput->setIsPassword(true);
if (($config_object->getLoginMethod() == LAMConfig::LOGIN_SEARCH) && !empty($_COOKIE['lam_login_name'])) {
$passwordInput->setCSSClasses(array('lam-initial-focus'));
}
$row->addField($passwordInput); $row->addField($passwordInput);
} }
// language // language