Skip to content

Commit

Permalink
NEW Can set the default focus of each page.
Browse files Browse the repository at this point in the history
NEW Can set if a field is mandatory on form level.
  • Loading branch information
eldy committed Sep 27, 2018
1 parent a623d80 commit 851fd4c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
12 changes: 4 additions & 8 deletions htdocs/admin/defaultvalues.php
Expand Up @@ -235,13 +235,9 @@
{
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'].'">';
Expand Down Expand Up @@ -303,11 +299,11 @@
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')
Expand All @@ -320,7 +316,7 @@
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
Expand Down
69 changes: 67 additions & 2 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -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";
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion htdocs/langs/en_US/admin.lang
Expand Up @@ -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

0 comments on commit 851fd4c

Please sign in to comment.