Fix support of 'help' field property. Fix bad td closing.

This commit is contained in:
Laurent Destailleur 2018-06-13 13:36:40 +02:00
parent f4bef82bfa
commit 50aa674ebc
4 changed files with 30 additions and 15 deletions

View File

@ -6019,7 +6019,9 @@ abstract class CommonObject
*/
function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0)
{
global $_POST, $conf, $langs, $action;
global $db, $conf, $langs, $action, $form;
if (! is_object($form)) $form=new Form($db);
$out = '';
@ -6128,12 +6130,12 @@ abstract class CommonObject
$labeltoshow = $langs->trans($label);
if ($extrafields->attributes[$this->table_element]['required'][$key])
{
$labeltoshow = '<span'.($mode != 'view' ? ' class="fieldrequired"':'').'>'.$labeltoshow.'</span>';
}
$out .= '<td>'.$labeltoshow.'</td>';
$out .= '<td class="titlefield';
if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired';
$out .= '">';
if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]);
else $out .= $labeltoshow;
$out .= '</td>';
$html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : '';
$out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>';

View File

@ -27,6 +27,7 @@ if (empty($conf) || ! is_object($conf))
print "Error, template page can't be called as URL";
exit;
}
if (! is_object($form)) $form=new Form($db);
?>
<!-- BEGIN PHP TEMPLATE commonfields_edit.tpl.php -->
@ -45,8 +46,10 @@ foreach($object->fields as $key => $val)
print ' class="titlefieldcreate';
if ($val['notnull'] > 0) print ' fieldrequired';
if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
print '"';
print '>'.$langs->trans($val['label']).'</td>';
print '">';
if (! empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $val['help']);
else print $langs->trans($val['label']);
print '</td>';
print '<td>';
if (in_array($val['type'], array('int', 'integer'))) $value = GETPOSTISSET($key)?GETPOST($key, 'int'):$object->$key;
elseif ($val['type'] == 'text' || $val['type'] == 'html') $value = GETPOSTISSET($key)?GETPOST($key,'none'):$object->$key;

View File

@ -29,6 +29,7 @@ if (empty($conf) || ! is_object($conf))
print "Error, template page can't be called as URL";
exit;
}
if (! is_object($form)) $form=new Form($db);
?>
<!-- BEGIN PHP TEMPLATE commonfields_view.tpl.php -->
@ -50,8 +51,10 @@ foreach($object->fields as $key => $val)
print ' class="titlefield';
if ($val['notnull'] > 0) print ' fieldrequired';
if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
print '"';
print '>'.$langs->trans($val['label']).'</td>';
print '">';
if (! empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $val['help']);
else print $langs->trans($val['label']);
print '</td>';
print '<td>';
print $object->showOutputField($val, $key, $value, '', '', '', 0);
//print dol_escape_htmltag($object->$key, 1, 1);
@ -87,8 +90,10 @@ foreach($object->fields as $key => $val)
print ' class="titlefield';
if ($val['notnull'] > 0) print ' fieldrequired';
if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
print '"';
print '>'.$langs->trans($val['label']).'</td>';
print '">';
if (! empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $val['help']);
else print $langs->trans($val['label']);
print '</td>';
print '<td>';
print $object->showOutputField($val, $key, $value, '', '', '', 0);
//print dol_escape_htmltag($object->$key, 1, 1);

View File

@ -31,6 +31,7 @@ if (empty($object) || ! is_object($object))
print "Error, template page can't be called as URL";
exit;
}
if (! is_object($form)) $form=new Form($db);
?>
<!-- BEGIN PHP TEMPLATE extrafields_view.tpl.php -->
@ -93,9 +94,13 @@ if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]
print '<table width="100%" class="nobordernopadding">';
print '<tr>';
print '<td';
print ' class="titlefield';
//var_dump($action);exit;
if ((! empty($action) && ($action == 'create' || $action == 'edit')) && ! empty($extrafields->attributes[$object->table_element]['required'][$key])) print ' class="fieldrequired"';
print '>' . $langs->trans($label) . '</td>';
if ((! empty($action) && ($action == 'create' || $action == 'edit')) && ! empty($extrafields->attributes[$object->table_element]['required'][$key])) print ' fieldrequired';
print '">';
if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) print $form->textwithpicto($langs->trans($label), $extrafields->attributes[$object->table_element]['help'][$key]);
else print $langs->trans($label);
print '</td>';
//TODO Improve element and rights detection
//var_dump($user->rights);