This commit is contained in:
Laurent Destailleur (aka Eldy) 2025-02-10 12:42:41 +01:00
parent e57e185ef1
commit 461a576669
5 changed files with 52 additions and 20 deletions

View file

@ -2438,8 +2438,22 @@ class ExtraFields
* @param string $key Key of attribute
* @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data
* @return string Formatted value
* @deprecated Use getCSSClass()
*/
public function getAlignFlag($key, $extrafieldsobjectkey = '')
{
return $this->getCSSClass($key, $extrafieldsobjectkey);
}
/**
* Return the CSS to use for this extrafield into list
*
* @param string $key Key of attribute
* @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data
* @param string $mode 'csslist' (used on td into table list), 'css' (used on create/update), 'cssview' (used on view)
* @return string Formatted value
*/
public function getCSSClass($key, $extrafieldsobjectkey = '', $mode = 'csslist')
{
$type = 'varchar';
if (!empty($extrafieldsobjectkey)) {
@ -2448,19 +2462,27 @@ class ExtraFields
$cssstring = '';
if (in_array($type, array('date', 'datetime', 'datetimegmt',))) {
$cssstring = "center";
} elseif (in_array($type, array('int', 'price', 'double', 'duration'))) {
$cssstring = "right";
} elseif (in_array($type, array('boolean', 'radio', 'checkbox', 'ip', 'icon'))) {
$cssstring = "center";
if ($mode == 'csslist') {
if (in_array($type, array('date', 'datetime', 'datetimegmt',))) {
$cssstring = "center";
} elseif (in_array($type, array('int', 'price', 'double', 'duration'))) {
$cssstring = "right";
} elseif (in_array($type, array('boolean', 'radio', 'checkbox', 'ip', 'icon'))) {
$cssstring = "center";
}
if (!empty($this->attributes[$extrafieldsobjectkey][$mode][$key])) {
$cssstring .= ($cssstring ? ' ' : '').$this->attributes[$extrafieldsobjectkey][$mode][$key];
} else {
if (in_array($type, array('ip'))) {
$cssstring .= ($cssstring ? ' ' : '').'tdoverflowmax150';
}
}
}
if (!empty($this->attributes[$extrafieldsobjectkey]['csslist'][$key])) {
$cssstring .= ($cssstring ? ' ' : '').$this->attributes[$extrafieldsobjectkey]['csslist'][$key];
} else {
if (in_array($type, array('ip'))) {
$cssstring .= ($cssstring ? ' ' : '').'tdoverflowmax150';
if ($mode == 'css' || $mode == 'cssview') {
if (!empty($this->attributes[$extrafieldsobjectkey][$mode][$key])) {
$cssstring = ($cssstring ? ' ' : '').$this->attributes[$extrafieldsobjectkey][$mode][$key];
}
}

View file

@ -45,7 +45,8 @@ if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafield
continue;
}
$cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey);
$cssclasstd = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'csslist');
$cssclassview = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'cssview');
$tmpkey = 'options_'.$key;
@ -64,7 +65,7 @@ if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafield
}
// If field is a computed field, we make computation to get value
if ($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]) {
$objectoffield = $object; //For compatibility with the computed formula
$objectoffield = $object; // For compatibility with the computed formula
$value = dol_eval((string) $extrafields->attributes[$extrafieldsobjectkey]['computed'][$key], 1, 1, '2');
if (is_numeric(price2num($value)) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
$obj->$tmpkey = price2num($value);
@ -74,11 +75,13 @@ if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafield
$valuetoshow = $extrafields->showOutputField($key, $value, '', $extrafieldsobjectkey, null, $object);
$title = dol_string_nohtmltag($valuetoshow);
print '<td'.($cssclass ? ' class="'.$cssclass.'"' : ''); // TODO Add 'css' and 'cssview' and 'csslist' for extrafields and use here 'csslist'
print '<td'.($cssclasstd ? ' class="'.$cssclasstd.'"' : '');
print ' data-key="'.$extrafieldsobjectkey.'.'.$key.'"';
print($title ? ' title="'.dol_escape_htmltag($title).'"' : '');
print '>';
print $cssclassview ? '<span class="'.$cssclassview.'">' : '';
print $valuetoshow;
print $cssclassview ? '</span>' : '';
print '</td>';
if (!$i) {

View file

@ -50,9 +50,11 @@ if (!empty($extrafieldsobjectkey)) { // $extrafieldsobject is the $object->table
if ($extrafields->attributes[$extrafieldsobjectkey]['type'][$key] == 'separate') {
continue;
}
$cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey);
$cssclasstd = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'csslist');
$typeofextrafield = $extrafields->attributes[$extrafieldsobjectkey]['type'][$key];
print '<td class="liste_titre'.($cssclass ? ' '.$cssclass : '').'">';
print '<td class="liste_titre'.($cssclasstd ? ' '.$cssclasstd : '').'">';
$tmpkey = preg_replace('/'.$search_options_pattern.'/', '', $key);
if (in_array($typeofextrafield, array('varchar', 'mail', 'ip', 'url', 'int', 'double')) && empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key])) {
$searchclass = '';

View file

@ -1,5 +1,4 @@
<?php
/* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
*
@ -22,6 +21,11 @@
* @var Conf $conf
* @var CommonObject $object
* @var ?Translate $langs
*
* @var ?string $extrafieldsobjectkey
* @var ?int $disablesortlink
* @var string $sortfield
* @var string $sortorder
*/
// Protection to avoid direct call of template
@ -53,7 +57,8 @@ if (!empty($extrafieldsobjectkey)) { // $extrafieldsobject is the $object->table
continue;
}
$cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey);
$cssclasstd = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'csslist');
$sortonfield = $extrafieldsobjectprefix.$key;
if (!empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key])) {
$sortonfield = '';
@ -66,7 +71,7 @@ if (!empty($extrafieldsobjectkey)) { // $extrafieldsobject is the $object->table
$tooltip = empty($extrafields->attributes[$extrafieldsobjectkey]['help'][$key]) ? '' : $extrafields->attributes[$extrafieldsobjectkey]['help'][$key];
// Show cell
print getTitleFieldOfList($extrafields->attributes[$extrafieldsobjectkey]['label'][$key], 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, 'data-titlekey="'.$key.'"', $sortfield, $sortorder, $cssclass.' ', $disablesortlink, $tooltip)."\n";
print getTitleFieldOfList($extrafields->attributes[$extrafieldsobjectkey]['label'][$key], 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, 'data-titlekey="'.$key.'"', $sortfield, $sortorder, $cssclassview.' ', $disablesortlink, $tooltip)."\n";
if (isset($totalarray) && isset($totalarray['nbfield'])) {
$totalarray['nbfield']++;
}

View file

@ -700,7 +700,7 @@ if ($action == "view_ticketlist") {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
if (!empty($arrayfields["ef.".$key]['checked'])) {
print '<td';
$cssstring = $extrafields->getAlignFlag($key, $object->table_element);
$cssstring = $extrafields->getCSSClass($key, $object->table_element, 'csslist');
if ($cssstring) {
print ' class="'.$cssstring.'"';
}