From a2c78bcec7eb84bc0eb5fd1505b2ebdcb37df0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 26 Apr 2023 22:33:26 +0200 Subject: [PATCH] add ajax tooltip for cronjobs --- htdocs/core/lib/functions.lib.php | 3 ++ htdocs/cron/class/cronjob.class.php | 84 +++++++++++++++++++---------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index bedb62c1162..e3dad8c0386 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -11288,6 +11288,9 @@ function getElementProperties($element_type) $classpath = 'comm/action/class'; $subelement = 'Actioncomm'; $module = 'agenda'; + } elseif ($element_type == 'cronjob') { + $classpath = 'cron/class'; + $module = 'cron'; } elseif ($element_type == 'adherent_type') { $classpath = 'adherents/class'; $classfile = 'adherent_type'; diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 010ea7b6f32..70ecfb0bf55 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -969,6 +969,49 @@ class Cronjob extends CommonObject } + /** + * getTooltipContentArray + * @param array $params params to construct tooltip data + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $langs; + + $langs->load('cron'); + $datas = []; + + $datas['picto'] = img_picto('', 'object_'.$this->picto).' '.$langs->trans("CronTask").''; + if (isset($this->status)) { + $datas['picto'] .= ' '.$this->getLibStatut(5); + } + $datas['ref'] = '
'.$langs->trans('Ref').': '.dol_escape_htmltag($this->ref); + $datas['label'] = '
'.$langs->trans('Title').': '.$langs->trans($this->label); + if ($this->label != $langs->trans($this->label)) { + $datas['label'] .= ' ('.$this->label.')'; + } + if (!empty($this->params)) { + $datas['params'] = '
'.$langs->trans('Parameters').': '.dol_escape_htmltag($this->params); + } + $datas['space'] = '
'; + + if (!empty($this->datestart)) { + $datas['crondtstart'] = '
'.$langs->trans('CronDtStart').': '.dol_print_date($this->datestart, 'dayhour', 'tzuserrel'); + } + if (!empty($this->dateend)) { + $datas['crondtend'] = '
'.$langs->trans('CronDtEnd').': '.dol_print_date($this->dateend, 'dayhour', 'tzuserrel'); + } + if (!empty($this->datelastrun)) { + $datas['cronlastlaunch'] = '
'.$langs->trans('CronDtLastLaunch').': '.dol_print_date($this->datelastrun, 'dayhour', 'tzuserrel'); + } + if (!empty($this->datenextrun)) { + $datas['crondtnextlaunch'] = '
'.$langs->trans('CronDtNextLaunch').': '.dol_print_date($this->datenextrun, 'dayhour', 'tzuserrel'); + } + + return $datas; + } + /** * Return a link to the object card (with optionaly the picto) * @@ -991,31 +1034,18 @@ class Cronjob extends CommonObject $result = ''; - $label = img_picto('', 'object_'.$this->picto).' '.$langs->trans("CronTask").''; - if (isset($this->status)) { - $label .= ' '.$this->getLibStatut(5); - } - $label .= '
'.$langs->trans('Ref').': '.dol_escape_htmltag($this->ref); - $label .= '
'.$langs->trans('Title').': '.$langs->trans($this->label); - if ($this->label != $langs->trans($this->label)) { - $label .= ' ('.$this->label.')'; - } - if (!empty($this->params)) { - $label .= '
'.$langs->trans('Parameters').': '.dol_escape_htmltag($this->params); - } - $label .= '
'; - - if (!empty($this->datestart)) { - $label .= '
'.$langs->trans('CronDtStart').': '.dol_print_date($this->datestart, 'dayhour', 'tzuserrel'); - } - if (!empty($this->dateend)) { - $label .= '
'.$langs->trans('CronDtEnd').': '.dol_print_date($this->dateend, 'dayhour', 'tzuserrel'); - } - if (!empty($this->datelastrun)) { - $label .= '
'.$langs->trans('CronDtLastLaunch').': '.dol_print_date($this->datelastrun, 'dayhour', 'tzuserrel'); - } - if (!empty($this->datenextrun)) { - $label .= '
'.$langs->trans('CronDtNextLaunch').': '.dol_print_date($this->datenextrun, 'dayhour', 'tzuserrel'); + $params = [ + 'id' => $this->id, + 'objecttype' => $this->element, + ]; + $classfortooltip = 'classfortooltip'; + $dataparams = ''; + if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { + $classfortooltip = 'classforajaxtooltip'; + $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; + $label = ''; + } else { + $label = implode($this->getTooltipContentArray($params)); } $url = DOL_URL_ROOT.'/cron/card.php?id='.$this->id; @@ -1038,7 +1068,7 @@ class Cronjob extends CommonObject $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"'; } else { $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); } @@ -1049,7 +1079,7 @@ class Cronjob extends CommonObject $result .= $linkstart; if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { $result .= $this->ref;