NEW Can set the default focus of each page.

NEW Can set if a field is mandatory on form level.
This commit is contained in:
Laurent Destailleur 2018-09-28 00:52:15 +02:00
parent a623d80830
commit 851fd4cc18
3 changed files with 73 additions and 11 deletions

View File

@ -235,13 +235,9 @@ if ($mode == 'sortorder')
{
print info_admin($langs->trans("WarningSettingSortOrder")).'<br>';
}
if ($mode == 'focus')
{
print info_admin($langs->trans("FeatureNotYetAvailable")).'<br>';
}
if ($mode == 'mandatory')
{
print info_admin($langs->trans("FeatureNotYetAvailable")).'<br>';
print info_admin($langs->trans("FeatureSupportedOnTextFieldsOnly")).'<br>';
}
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -303,11 +299,11 @@ print "\n";
print '<tr class="oddeven">';
// Page
print '<td>';
print '<input type="text" class="flat minwidth200 maxwidthonsmartphone" name="defaulturl" value="">';
print '<input type="text" class="flat minwidth200 maxwidthonsmartphone" name="defaulturl" value="'.dol_escape_htmltag(GETPOST('defaulturl','alphanohtml')).'">';
print '</td>'."\n";
// Field
print '<td>';
print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultkey" value="">';
print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultkey" value="'.dol_escape_htmltag(GETPOST('defaultkey','alphanohtml')).'">';
print '</td>';
// Value
if ($mode != 'focus' && $mode != 'mandatory')
@ -320,7 +316,7 @@ if ($mode != 'focus' && $mode != 'mandatory')
if (! empty($conf->multicompany->enabled) && !$user->entity)
{
print '<td>';
print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
print '<input type="text" class="flat" size="1" disabled name="entity" value="'.$conf->entity.'">'; // We see environment, but to change it we must switch on other entity
print '</td>';
}
else

View File

@ -7023,7 +7023,8 @@ function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode=
*/
function printCommonFooter($zone='private')
{
global $conf, $hookmanager;
global $conf, $hookmanager, $user;
global $action;
global $micro_start_time;
if ($zone == 'private') print "\n".'<!-- Common footer for private page -->'."\n";
@ -7056,7 +7057,71 @@ function printCommonFooter($zone='private')
print '});'."\n";
}
// Google Analytics (need Google module)
// Management of focus and mandatory for fields
if ($action == 'create' || $action == 'edit')
{
print '/* Code js to manage focus and mandatory form fields */'."\n";
$relativepathstring = $_SERVER["PHP_SELF"];
// Clean $relativepathstring
if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
$tmpqueryarraywehave=explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
foreach($user->default_values[$relativepathstring]['focus'] as $defkey => $defval)
{
$qualified = 0;
if ($defkey != '_noquery_')
{
$tmpqueryarraytohave=explode('&', $defkey);
$foundintru=0;
foreach($tmpqueryarraytohave as $tmpquerytohave)
{
if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
}
if (! $foundintru) $qualified=1;
//var_dump($defkey.'-'.$qualified);
}
else $qualified = 1;
if ($qualified)
{
foreach($defval as $paramkey => $paramval)
{
// Add property 'required' on input
print 'jQuery("input[name=\''.$paramkey.'\']").focus();'."\n";
}
}
}
foreach($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval)
{
$qualified = 0;
if ($defkey != '_noquery_')
{
$tmpqueryarraytohave=explode('&', $defkey);
$foundintru=0;
foreach($tmpqueryarraytohave as $tmpquerytohave)
{
if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
}
if (! $foundintru) $qualified=1;
//var_dump($defkey.'-'.$qualified);
}
else $qualified = 1;
if ($qualified)
{
foreach($defval as $paramkey => $paramval)
{
// Add property 'required' on input
print 'jQuery("input[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n";
print 'jQuery("select[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n"; // required on a select works only if key is "", this does not happen in Dolibarr
}
}
}
}
// Google Analytics
// TODO Add a hook here
if (! empty($conf->google->enabled) && ! empty($conf->global->MAIN_GOOGLE_AN_ID))
{
if (($conf->dol_use_jmobile != 4))

View File

@ -1810,10 +1810,11 @@ SocialNetworkSetup=Setup of module Social Networks
EnableFeatureFor=Enable features for <strong>%s</strong>
VATIsUsedIsOff=Note: The option to use sales Tax or VAT has been set to <strong>Off</strong> in the menu %s - %s, so Sale tax or Vat used will always be 0 for sales.
SwapSenderAndRecipientOnPDF=Swap sender and recipient address on PDF
FeatureSupportedOnTextFieldsOnly=Warning, feature supported on text fields only
##### Resource ####
ResourceSetup=Configuration du module Resource
UseSearchToSelectResource=Use a search form to choose a resource (rather than a drop-down list).
DisabledResourceLinkUser=Disable feature to link a resource to users
DisabledResourceLinkContact=Disable feature to link a resource to contacts
ConfirmUnactivation=Confirm module reset
OnMobileOnly=On small screen (smartphone) only
OnMobileOnly=On small screen (smartphone) only