From 019802ec33a75f61530dddc2fbd8adfda37585e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 7 Feb 2023 22:12:47 +0100 Subject: [PATCH] add ajax tooltip on project --- htdocs/projet/class/project.class.php | 88 ++++++++++++++++++--------- 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 6eb7384c11d..adc617e55c2 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1244,6 +1244,50 @@ class Project extends CommonObject return dolGetStatus($langs->transnoentitiesnoconv($this->statuts_long[$status]), $langs->transnoentitiesnoconv($this->statuts_short[$status]), '', $statusClass, $mode); } + /** + * getTooltipContentArray + * + * @param array $params ex option, infologin + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $conf, $langs; + + $langs->load('projects'); + $option = $params['option'] ?? ''; + $moreinpopup = $params['morinpopup'] ?? ''; + + $datas = []; + if ($option != 'nolink') { + $datas['picto'] = img_picto('', $this->picto, 'class="pictofixedwidth"').' '.$langs->trans("Project").''; + } + if (isset($this->status)) { + $datas['picto'] .= ' '.$this->getLibStatut(5); + } + $datas['ref'] = (isset($datas['picto']) ? '
' : '').''.$langs->trans('Ref').': '.$this->ref; // The space must be after the : to not being explode when showing the title in img_picto + $datas['label'] = '
'.$langs->trans('Label').': '.$this->title; // The space must be after the : to not being explode when showing the title in img_picto + if (isset($this->public)) { + $datas['visibility'] = '
'.$langs->trans("Visibility").": "; + $datas['visibility'] .= ($this->public ? img_picto($langs->trans('SharedProject'), 'world', 'class="pictofixedwidth"').$langs->trans("SharedProject") : img_picto($langs->trans('PrivateProject'), 'private', 'class="pictofixedwidth"').$langs->trans("PrivateProject")); + } + if (!empty($this->thirdparty_name)) { + $datas['thirdparty'] = '
'.$langs->trans('ThirdParty').': '.$this->thirdparty_name; // The space must be after the : to not being explode when showing the title in img_picto + } + if (!empty($this->date_start)) { + $datas['datestart'] = '
'.$langs->trans('DateStart').': '.dol_print_date($this->date_start, 'day'); // The space must be after the : to not being explode when showing the title in img_picto + } + if (!empty($this->date_end)) { + $datas['dateend'] = '
'.$langs->trans('DateEnd').': '.dol_print_date($this->date_end, 'day'); // The space must be after the : to not being explode when showing the title in img_picto + } + if ($moreinpopup) { + $datas['moreinpopup'] = '
'.$moreinpopup; + } + + return $datas; + } + /** * Return clickable name (with picto eventually) * @@ -1269,32 +1313,20 @@ class Project extends CommonObject if (!empty($conf->global->PROJECT_OPEN_ALWAYS_ON_TAB)) { $option = $conf->global->PROJECT_OPEN_ALWAYS_ON_TAB; } - - $label = ''; - if ($option != 'nolink') { - $label = img_picto('', $this->picto, 'class="pictofixedwidth"').' '.$langs->trans("Project").''; - } - if (isset($this->status)) { - $label .= ' '.$this->getLibStatut(5); - } - $label .= ($label ? '
' : '').''.$langs->trans('Ref').': '.$this->ref; // The space must be after the : to not being explode when showing the title in img_picto - $label .= ($label ? '
' : '').''.$langs->trans('Label').': '.$this->title; // The space must be after the : to not being explode when showing the title in img_picto - if (isset($this->public)) { - $label .= '
'.$langs->trans("Visibility").": "; - $label .= ($this->public ? img_picto($langs->trans('SharedProject'), 'world', 'class="pictofixedwidth"').$langs->trans("SharedProject") : img_picto($langs->trans('PrivateProject'), 'private', 'class="pictofixedwidth"').$langs->trans("PrivateProject")); - } - if (!empty($this->thirdparty_name)) { - $label .= ($label ? '
' : '').''.$langs->trans('ThirdParty').': '.$this->thirdparty_name; // The space must be after the : to not being explode when showing the title in img_picto - } - if (!empty($this->date_start)) { - $label .= ($label ? '
' : '').''.$langs->trans('DateStart').': '.dol_print_date($this->date_start, 'day'); // The space must be after the : to not being explode when showing the title in img_picto - } - if (!empty($this->date_end)) { - $label .= ($label ? '
' : '').''.$langs->trans('DateEnd').': '.dol_print_date($this->date_end, 'day'); // The space must be after the : to not being explode when showing the title in img_picto - } - if ($moreinpopup) { - $label .= '
'.$moreinpopup; + $params = [ + 'id' => $this->id, + 'objecttype' => $this->element, + 'moreinpopup' => $moreinpopup, + 'option' => $option, + ]; + $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 = ''; if ($option != 'nolink') { @@ -1325,8 +1357,8 @@ class Project extends CommonObject $label = $langs->trans("ShowProject"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + $linkclose .= $dataparams.' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"'; } else { $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); } @@ -1342,7 +1374,7 @@ class Project extends CommonObject $result .= $linkstart; if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="pictofixedwidth"' : '') : 'class="'.(($withpicto != 2) ? 'pictofixedwidth ' : '').'classfortooltip pictofixedwidth em088"'), 0, 0, $notooltip ? 0 : 1); + $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="pictofixedwidth"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'pictofixedwidth ' : '').$classfortooltip.' pictofixedwidth em088"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { $result .= $this->ref;