NEW Add different picto for each type of extrafields (date, string, ...)

This commit is contained in:
Laurent Destailleur
2023-09-19 13:24:03 +02:00
parent cb62571d31
commit c07abcc67c
5 changed files with 85 additions and 17 deletions

View File

@@ -69,7 +69,7 @@ class ExtraFields
public $errno; public $errno;
/** /**
* @var array array of type to label * @var array Array of type to label
*/ */
public static $type2label = array( public static $type2label = array(
'varchar'=>'String1Line', 'varchar'=>'String1Line',
@@ -97,7 +97,6 @@ class ExtraFields
'separate' => 'ExtrafieldSeparator', 'separate' => 'ExtrafieldSeparator',
); );
/** /**
* Constructor * Constructor
* *

View File

@@ -4123,6 +4123,49 @@ function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF
} }
} }
/**
* Return the picto for a data type
*
* @param string $key Key
* @return string Pïcto for the key
*/
function getPictoForType($key)
{
// Set array with type -> picto
$type2picto = array(
'varchar'=>'font',
'text'=>'font',
'html'=>'code',
'int'=>'sort-numeric-down',
'double'=>'sort-numeric-down',
'int'=>'sort-numeric-down',
'price'=>'currency',
'pricecy'=>'multicurrency',
'password' => 'key',
'boolean'=>'check-square',
'date'=>'calendar',
'datetime'=>'calendar',
'phone'=> 'phone',
'mail'=> 'email',
'url'=> 'url',
'ip'=> 'country',
'select' => 'list',
'sellist' => 'list',
'radio' => 'check-circle',
'checkbox' => 'check-square',
'chkbxlst' => 'check-square',
'link' => 'link',
'separate'=> 'minus'
);
if (!empty($type2picto[$key])) {
return img_picto('', $type2picto[$key], 'class="pictofixedwidth"');
}
return img_picto('', 'generic', 'class="pictofixedwidth"');
}
/** /**
* Show picto whatever it's its name (generic function) * Show picto whatever it's its name (generic function)
* *
@@ -4219,30 +4262,30 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $
'accountancy', 'accounting_account', 'account', 'accountline', 'action', 'add', 'address', 'angle-double-down', 'angle-double-up', 'asset', 'accountancy', 'accounting_account', 'account', 'accountline', 'action', 'add', 'address', 'angle-double-down', 'angle-double-up', 'asset',
'bank_account', 'barcode', 'bank', 'bell', 'bill', 'billa', 'billr', 'billd', 'birthday-cake', 'bookmark', 'bom', 'briefcase-medical', 'bug', 'building', 'bank_account', 'barcode', 'bank', 'bell', 'bill', 'billa', 'billr', 'billd', 'birthday-cake', 'bookmark', 'bom', 'briefcase-medical', 'bug', 'building',
'card', 'calendarlist', 'calendar', 'calendarmonth', 'calendarweek', 'calendarday', 'calendarperuser', 'calendarpertype', 'card', 'calendarlist', 'calendar', 'calendarmonth', 'calendarweek', 'calendarday', 'calendarperuser', 'calendarpertype',
'cash-register', 'category', 'chart', 'check', 'clock', 'clone', 'close_title', 'cog', 'collab', 'company', 'contact', 'country', 'contract', 'conversation', 'cron', 'cross', 'cubes', 'cash-register', 'category', 'chart', 'check', 'clock', 'clone', 'close_title', 'code', 'cog', 'collab', 'company', 'contact', 'country', 'contract', 'conversation', 'cron', 'cross', 'cubes',
'currency', 'multicurrency', 'check-circle', 'check-square', 'currency', 'multicurrency',
'chevron-left', 'chevron-right', 'chevron-down', 'chevron-top', 'commercial', 'companies',
'delete', 'dolly', 'dollyrevert', 'donation', 'download', 'dynamicprice', 'delete', 'dolly', 'dollyrevert', 'donation', 'download', 'dynamicprice',
'edit', 'ellipsis-h', 'email', 'entity', 'envelope', 'eraser', 'establishment', 'expensereport', 'external-link-alt', 'external-link-square-alt', 'eye', 'edit', 'ellipsis-h', 'email', 'entity', 'envelope', 'eraser', 'establishment', 'expensereport', 'external-link-alt', 'external-link-square-alt', 'eye',
'filter', 'file-code', 'file-export', 'file-import', 'file-upload', 'autofill', 'folder', 'folder-open', 'folder-plus', 'filter', 'file-code', 'file-export', 'file-import', 'file-upload', 'autofill', 'folder', 'folder-open', 'folder-plus', 'font',
'gears', 'generate', 'generic', 'globe', 'globe-americas', 'graph', 'grip', 'grip_title', 'group', 'gears', 'generate', 'generic', 'globe', 'globe-americas', 'graph', 'grip', 'grip_title', 'group',
'hands-helping', 'help', 'holiday', 'hands-helping', 'help', 'holiday',
'id-card', 'images', 'incoterm', 'info', 'intervention', 'inventory', 'intracommreport', 'jobprofile', 'id-card', 'images', 'incoterm', 'info', 'intervention', 'inventory', 'intracommreport', 'jobprofile',
'knowledgemanagement', 'key', 'knowledgemanagement',
'label', 'language', 'line', 'link', 'list', 'list-alt', 'listlight', 'loan', 'lock', 'lot', 'long-arrow-alt-right', 'label', 'language', 'line', 'link', 'list', 'list-alt', 'listlight', 'loan', 'lock', 'lot', 'long-arrow-alt-right',
'margin', 'map-marker-alt', 'member', 'meeting', 'money-bill-alt', 'movement', 'mrp', 'note', 'next', 'margin', 'map-marker-alt', 'member', 'meeting', 'minus', 'money-bill-alt', 'movement', 'mrp', 'note', 'next',
'off', 'on', 'order', 'off', 'on', 'order',
'paiment', 'paragraph', 'play', 'pdf', 'phone', 'phoning', 'phoning_mobile', 'phoning_fax', 'playdisabled', 'previous', 'poll', 'pos', 'printer', 'product', 'propal', 'proposal', 'puce', 'paiment', 'paragraph', 'play', 'pdf', 'phone', 'phoning', 'phoning_mobile', 'phoning_fax', 'playdisabled', 'previous', 'poll', 'pos', 'printer', 'product', 'propal', 'proposal', 'puce',
'stock', 'resize', 'service', 'stats', 'trip', 'stock', 'resize', 'service', 'stats', 'trip',
'security', 'setup', 'share-alt', 'sign-out', 'split', 'stripe', 'stripe-s', 'switch_off', 'switch_on', 'switch_on_warning', 'switch_on_red', 'tools', 'unlink', 'uparrow', 'user', 'user-tie', 'vcard', 'wrench', 'security', 'setup', 'share-alt', 'sign-out', 'split', 'stripe', 'stripe-s', 'switch_off', 'switch_on', 'switch_on_warning', 'switch_on_red', 'tools', 'unlink', 'uparrow', 'user', 'user-tie', 'vcard', 'wrench',
'github', 'google', 'jabber', 'microsoft', 'skype', 'twitter', 'facebook', 'linkedin', 'instagram', 'snapchat', 'youtube', 'google-plus-g', 'whatsapp', 'github', 'google', 'jabber', 'microsoft', 'skype', 'twitter', 'facebook', 'linkedin', 'instagram', 'snapchat', 'youtube', 'google-plus-g', 'whatsapp',
'chevron-left', 'chevron-right', 'chevron-down', 'chevron-top', 'commercial', 'companies',
'generic', 'home', 'hrm', 'members', 'products', 'invoicing', 'generic', 'home', 'hrm', 'members', 'products', 'invoicing',
'partnership', 'payment', 'payment_vat', 'pencil-ruler', 'pictoconfirm', 'preview', 'project', 'projectpub', 'projecttask', 'question', 'refresh', 'region', 'partnership', 'payment', 'payment_vat', 'pencil-ruler', 'pictoconfirm', 'preview', 'project', 'projectpub', 'projecttask', 'question', 'refresh', 'region',
'salary', 'shipment', 'state', 'supplier_invoice', 'supplier_invoicea', 'supplier_invoicer', 'supplier_invoiced', 'salary', 'shipment', 'state', 'supplier_invoice', 'supplier_invoicea', 'supplier_invoicer', 'supplier_invoiced',
'technic', 'ticket', 'technic', 'ticket',
'error', 'warning', 'error', 'warning',
'recent', 'reception', 'recruitmentcandidature', 'recruitmentjobposition', 'replacement', 'resource', 'recurring','rss', 'recent', 'reception', 'recruitmentcandidature', 'recruitmentjobposition', 'replacement', 'resource', 'recurring','rss',
'shapes', 'skill', 'square', 'stop-circle', 'supplier', 'supplier_proposal', 'supplier_order', 'supplier_invoice', 'shapes', 'skill', 'square', 'sort-numeric-down', 'stop-circle', 'supplier', 'supplier_proposal', 'supplier_order', 'supplier_invoice',
'timespent', 'title_setup', 'title_accountancy', 'title_bank', 'title_hrm', 'title_agenda', 'timespent', 'title_setup', 'title_accountancy', 'title_bank', 'title_hrm', 'title_agenda',
'uncheck', 'url', 'user-cog', 'user-injured', 'user-md', 'vat', 'website', 'workstation', 'webhook', 'world', 'private', 'uncheck', 'url', 'user-cog', 'user-injured', 'user-md', 'vat', 'website', 'workstation', 'webhook', 'world', 'private',
'conferenceorbooth', 'eventorganization', 'conferenceorbooth', 'eventorganization',
@@ -4282,7 +4325,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $
'switch_off'=>'toggle-off', 'switch_on'=>'toggle-on', 'switch_on_warning'=>'toggle-on', 'switch_on_red'=>'toggle-on', 'check'=>'check', 'bookmark'=>'star', 'switch_off'=>'toggle-off', 'switch_on'=>'toggle-on', 'switch_on_warning'=>'toggle-on', 'switch_on_red'=>'toggle-on', 'check'=>'check', 'bookmark'=>'star',
'bank'=>'university', 'close_title'=>'times', 'delete'=>'trash', 'filter'=>'filter', 'bank'=>'university', 'close_title'=>'times', 'delete'=>'trash', 'filter'=>'filter',
'list-alt'=>'list-alt', 'calendarlist'=>'bars', 'calendar'=>'calendar-alt', 'calendarmonth'=>'calendar-alt', 'calendarweek'=>'calendar-week', 'calendarday'=>'calendar-day', 'calendarperuser'=>'table', 'list-alt'=>'list-alt', 'calendarlist'=>'bars', 'calendar'=>'calendar-alt', 'calendarmonth'=>'calendar-alt', 'calendarweek'=>'calendar-week', 'calendarday'=>'calendar-day', 'calendarperuser'=>'table',
'intervention'=>'ambulance', 'invoice'=>'file-invoice-dollar', 'currency'=>'dollar-sign', 'multicurrency'=>'dollar-sign', 'order'=>'file-invoice', 'intervention'=>'ambulance', 'invoice'=>'file-invoice-dollar', 'order'=>'file-invoice',
'error'=>'exclamation-triangle', 'warning'=>'exclamation-triangle', 'error'=>'exclamation-triangle', 'warning'=>'exclamation-triangle',
'other'=>'square', 'other'=>'square',
'playdisabled'=>'play', 'pdf'=>'file-pdf', 'poll'=>'check-double', 'pos'=>'cash-register', 'preview'=>'binoculars', 'project'=>'project-diagram', 'projectpub'=>'project-diagram', 'projecttask'=>'tasks', 'propal'=>'file-signature', 'proposal'=>'file-signature', 'playdisabled'=>'play', 'pdf'=>'file-pdf', 'poll'=>'check-double', 'pos'=>'cash-register', 'preview'=>'binoculars', 'project'=>'project-diagram', 'projectpub'=>'project-diagram', 'projecttask'=>'tasks', 'propal'=>'file-signature', 'proposal'=>'file-signature',
@@ -4300,6 +4343,13 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $
'website'=>'globe-americas', 'workstation'=>'pallet', 'webhook'=>'bullseye', 'world'=>'globe', 'private'=>'user-lock', 'website'=>'globe-americas', 'workstation'=>'pallet', 'webhook'=>'bullseye', 'world'=>'globe', 'private'=>'user-lock',
'conferenceorbooth'=>'chalkboard-teacher', 'eventorganization'=>'project-diagram' 'conferenceorbooth'=>'chalkboard-teacher', 'eventorganization'=>'project-diagram'
); );
if ($conf->currency == 'EUR') {
$arrayconvpictotofa['currency'] = 'euro-sign';
$arrayconvpictotofa['multicurrency'] = 'dollar-sign';
} else {
$arrayconvpictotofa['currency'] = 'dollar-sign';
$arrayconvpictotofa['multicurrency'] = 'euro-sign';
}
if ($pictowithouttext == 'off') { if ($pictowithouttext == 'off') {
$fakey = 'fa-square'; $fakey = 'fa-square';
$fasize = '1.3em'; $fasize = '1.3em';

View File

@@ -157,7 +157,22 @@ $listofexamplesforlink = 'Societe:societe/class/societe.class.php<br>Contact:con
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><input type="text" name="attrname" id="attrname" size="10" value="<?php echo GETPOST('attrname', 'alpha'); ?>" pattern="\w+"> <span class="opacitymedium">(<?php echo $langs->trans("AlphaNumOnlyLowerCharsAndNoSpace"); ?>)</span></td></tr> <tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><input type="text" name="attrname" id="attrname" size="10" value="<?php echo GETPOST('attrname', 'alpha'); ?>" pattern="\w+"> <span class="opacitymedium">(<?php echo $langs->trans("AlphaNumOnlyLowerCharsAndNoSpace"); ?>)</span></td></tr>
<!-- Type --> <!-- Type -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur"> <tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
<?php print $form->selectarray('type', $type2label, GETPOST('type', 'alpha'), 0, 0, 0, '', 0, 0, 0, '', '', 1); ?> <?php
print '<select id="type" class="flat type" name="type">';
foreach ($type2label as $key => $val) {
$selected = '';
if ($key == GETPOST('type', 'alpha')) {
$selected = ' selected="selected"';
}
// Set $valhtml with the picto for the type
$valhtml = ($key ? getPictoForType($key) : '').$val;
print '<option value="'.$key.'"'.$selected.' data-html="'.dol_escape_htmltag($valhtml).'">'.($val ? $val : '&nbsp;').'</option>';
}
print '</select>';
print ajax_combobox('type');
?>
</td></tr> </td></tr>
<!-- Size --> <!-- Size -->
<tr class="extra_size"><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td class="valeur"><input id="size" type="text" name="size" size="5" value="<?php echo (GETPOST('size', 'alpha') ?GETPOST('size', 'alpha') : ''); ?>"></td></tr> <tr class="extra_size"><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td class="valeur"><input id="size" type="text" name="size" size="5" value="<?php echo (GETPOST('size', 'alpha') ?GETPOST('size', 'alpha') : ''); ?>"></td></tr>

View File

@@ -216,23 +216,26 @@ if ($size <= 255 && in_array($type, array('text', 'html'))) {
}*/ }*/
if (in_array($type, array_keys($typewecanchangeinto))) { if (in_array($type, array_keys($typewecanchangeinto))) {
$newarray = array();
print '<select id="type" class="flat type" name="type">'; print '<select id="type" class="flat type" name="type">';
foreach ($type2label as $key => $val) { foreach ($type2label as $key => $val) {
$selected = ''; $selected = '';
if ($key == (GETPOST('type', 'alpha') ? GETPOST('type', 'alpha') : $type)) { if ($key == (GETPOST('type', 'alpha') ? GETPOST('type', 'alpha') : $type)) {
$selected = ' selected="selected"'; $selected = ' selected="selected"';
} }
// Set $valhtml with the picto for the type
$valhtml = ($key ? getPictoForType($key) : '').$val;
if (in_array($key, $typewecanchangeinto[$type])) { if (in_array($key, $typewecanchangeinto[$type])) {
print '<option value="'.$key.'"'.$selected.'>'.$val.'</option>'; print '<option value="'.$key.'"'.$selected.' data-html="'.dol_escape_htmltag($valhtml).'">'.$val.'</option>';
} else { } else {
print '<option value="'.$key.'" disabled="disabled"'.$selected.'>'.$val.'</option>'; print '<option value="'.$key.'" disabled="disabled"'.$selected.' data-html="'.dol_escape_htmltag($valhtml).'">'.$val.'</option>';
} }
} }
print '</select>'; print '</select>';
print ajax_combobox('type'); print ajax_combobox('type');
} else { } else {
print $type2label[$type]; print getPictoForType($type).$type2label[$type];
print '<input type="hidden" name="type" id="type" value="'.$type.'">'; print '<input type="hidden" name="type" id="type" value="'.$type.'">';
} }
?> ?>

View File

@@ -109,6 +109,7 @@ if (isset($extrafields->attributes[$elementtype]['type']) && is_array($extrafiel
// Type // Type
$typetoshow = $type2label[$extrafields->attributes[$elementtype]['type'][$key]]; $typetoshow = $type2label[$extrafields->attributes[$elementtype]['type'][$key]];
print '<td title="'.dol_escape_htmltag($typetoshow).'" class="tdoverflowmax100">'; print '<td title="'.dol_escape_htmltag($typetoshow).'" class="tdoverflowmax100">';
print getPictoForType($extrafields->attributes[$elementtype]['type'][$key]);
print dol_escape_htmltag($typetoshow); print dol_escape_htmltag($typetoshow);
print "</td>\n"; print "</td>\n";
// Size // Size