From df411abe414edf82363c00a1346f45e02c7f7218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 7 Feb 2023 14:07:27 +0100 Subject: [PATCH] add ajax tooltip on task --- htdocs/core/ajax/ajaxtooltip.php | 3 +- htdocs/projet/class/task.class.php | 56 +++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/htdocs/core/ajax/ajaxtooltip.php b/htdocs/core/ajax/ajaxtooltip.php index a72b57c4ebe..7afbc88ae17 100644 --- a/htdocs/core/ajax/ajaxtooltip.php +++ b/htdocs/core/ajax/ajaxtooltip.php @@ -130,8 +130,7 @@ if ($objecttype == 'facture' || $objecttype == 'invoice') { $langs->load('projects'); $classpath = 'projet/class'; $module = 'projet'; -} elseif ($objecttype == 'task') { - $langs->load('projects'); +} elseif ($objecttype == 'project_task') { $classpath = 'projet/class'; $module = 'projet'; $myobject = 'task'; diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 597e680f8f0..1a4f96bacc6 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2008-2014 Laurent Destailleur * Copyright (C) 2010-2012 Regis Houssin * Copyright (C) 2014 Marcos García - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2023 Frédéric France * Copyright (C) 2020 Juanjo Menent * Copyright (C) 2022 Charlene Benke * @@ -696,6 +696,34 @@ class Task extends CommonObjectLine } + /** + * getTooltipContentArray + * + * @param array $params ex option, infologin + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $langs; + + $langs->load('projects'); + + $datas = []; + $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("Task").''; + if (!empty($this->ref)) { + $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; + } + if (!empty($this->label)) { + $datas['label'] = '
'.$langs->trans('LabelTask').': '.$this->label; + } + if ($this->date_start || $this->date_end) { + $datas['range'] = "
".get_date_range($this->date_start, $this->date_end, '', $langs, 0); + } + + return $datas; + } + /** * Return clicable name (with picto eventually) * @@ -717,16 +745,18 @@ class Task extends CommonObjectLine } $result = ''; - $label = img_picto('', $this->picto).' '.$langs->trans("Task").''; - if (!empty($this->ref)) { - $label .= '
'.$langs->trans('Ref').': '.$this->ref; - } - if (!empty($this->label)) { - $label .= '
'.$langs->trans('LabelTask').': '.$this->label; - } - if ($this->date_start || $this->date_end) { - $label .= "
".get_date_range($this->date_start, $this->date_end, '', $langs, 0); + $params = [ + 'id' => $this->id, + 'objecttype' => $this->element, + ]; + $classfortooltip = 'classfortooltip'; + $dataparams = ''; + if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { + $classfortooltip = 'classforajaxtooltip'; + $dataparams = ' data-params='.json_encode($params); + // $label = $langs->trans('Loading'); } + $label = implode($this->getTooltipContentArray($params)); $url = DOL_URL_ROOT.'/projet/tasks/'.$mode.'.php?id='.$this->id.($option == 'withproject' ? '&withproject=1' : ''); // Add param to save lastsearch_values or not @@ -744,8 +774,8 @@ class Task extends CommonObjectLine $label = $langs->trans("ShowTask"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip nowraponall"'; + $linkclose .= $dataparams.' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="'.$classfortooltip.' nowraponall"'; } else { $linkclose .= ' class="nowraponall"'; } @@ -758,7 +788,7 @@ class Task extends CommonObjectLine $result .= $linkstart; if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { $result .= $this->ref;