From eee645bb0655bba2512618b139741ef02886ff30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 8 Feb 2023 23:01:04 +0100 Subject: [PATCH] add ajax tooltip on opensurvey --- htdocs/core/ajax/ajaxtooltip.php | 7 ++- .../class/opensurveysondage.class.php | 44 +++++++++++++++---- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/htdocs/core/ajax/ajaxtooltip.php b/htdocs/core/ajax/ajaxtooltip.php index d10b0f1a43e..60220a221ff 100644 --- a/htdocs/core/ajax/ajaxtooltip.php +++ b/htdocs/core/ajax/ajaxtooltip.php @@ -41,7 +41,8 @@ include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; top_httphead(); -$id = GETPOST('id', 'int'); +// opensurvey as aZ09 id +$id = GETPOST('id', 'aZ09'); $objecttype = GETPOST('objecttype', 'aZ09'); $html = ''; @@ -158,6 +159,10 @@ if ($objecttype == 'facture' || $objecttype == 'invoice') { $classpath = 'resource/class'; $module = 'resource'; $myobject = 'dolresource'; +} elseif ($objecttype == 'opensurvey_sondage') { + $classpath = 'opensurvey/class'; + $module = 'opensurvey'; + $myobject = 'opensurveysondage'; } // Generic case for $classfile and $classname diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index f5dadd90f2e..e928c2f3cd6 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -420,6 +420,27 @@ class Opensurveysondage extends CommonObject } } + /** + * getTooltipContentArray + * + * @param array $params ex option, infologin + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $conf, $langs; + + $langs->load('opensurvey'); + + $datas = []; + $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("ShowSurvey").''; + $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; + $datas['title'] = '
'.$langs->trans('Title').': '.$this->title; + + return $datas; + } + /** * Return a link to the object card (with optionaly the picto) * @@ -440,11 +461,18 @@ class Opensurveysondage extends CommonObject } $result = ''; - - $label = img_picto('', $this->picto).' '.$langs->trans("ShowSurvey").''; - $label .= '
'; - $label .= ''.$langs->trans('Ref').': '.$this->ref.'
'; - $label .= ''.$langs->trans('Title').': '.$this->title.'
'; + $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.'/opensurvey/card.php?id='.$this->id; @@ -463,8 +491,8 @@ class Opensurveysondage extends CommonObject $label = $langs->trans("ShowMyObject"); $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.'"' : ''); } @@ -475,7 +503,7 @@ class Opensurveysondage extends CommonObject $result .= $linkstart; if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { $result .= $this->ref;