ajax tooltip on thirdparty

This commit is contained in:
Frédéric FRANCE 2023-02-01 21:57:45 +01:00
parent 11e3dbb2fb
commit 99c0d42b77

View File

@ -2597,6 +2597,140 @@ class Societe extends CommonObject
}
}
/**
* getTooltipContentArray
* @param array $params params to construct tooltip data
* @since v18
* @return array
*/
public function getTooltipContentArray($params)
{
global $conf, $langs, $user;
$langs->loadLangs(['companies, commercial']);
$datas = [];
$option = $params['option'] ?? '';
$name = $this->name;
if (!empty($this->name_alias) && empty($noaliasinname)) {
$name .= ' ('.$this->name_alias.')';
}
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
return ['optimize' => $langs->trans("ShowCompany")];
}
$label = '';
$label2 = '';
if (!empty($this->logo) && class_exists('Form')) {
$photo = '<div class="photointooltip floatright">';
$photo .= Form::showphoto('societe', $this, 0, 40, 0, 'photoref', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$photo .= '</div>';
$datas['photo'] = $photo;
} elseif (!empty($this->logo_squarred) && class_exists('Form')) {
/*$label.= '<div class="photointooltip">';
$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label.= '</div><div style="clear: both;"></div>';*/
}
$datas['divopen'] = '<div class="centpercent">';
if ($option == 'customer' || $option == 'compta' || $option == 'category') {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Customer").'</u>';
} elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Prospect").'</u>';
} elseif ($option == 'supplier' || $option == 'category_supplier') {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Supplier").'</u>';
} elseif ($option == 'agenda') {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>';
} elseif ($option == 'project') {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>';
} elseif ($option == 'margin') {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>';
} elseif ($option == 'contact') {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>';
} elseif ($option == 'ban') {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>';
}
// By default
if (empty($datas['picto'] )) {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>';
}
if (isset($this->status)) {
$datas['status'] = ' '.$this->getLibStatut(5);
}
if (isset($this->client) && isset($this->fournisseur)) {
$datas['type'] = ' &nbsp; ' . $this->getTypeUrl(1);
}
$datas['name'] = '<br><b>'.$langs->trans('Name').':</b> '.dol_escape_htmltag($this->name);
if (!empty($this->name_alias)) {
$datas['namealias'] = ' ('.dol_escape_htmltag($this->name_alias).')';
}
if ($this->email) {
$datas['email'] = '<br>'.img_picto('', 'email', 'class="pictofixedwidth"').$this->email;
}
if (!empty($this->phone) || !empty($this->fax)) {
$phonelist = array();
if ($this->phone) {
$phonelist[] = dol_print_phone($this->phone, $this->country_code, $this->id, 0, '', '&nbsp', 'phone');
}
if ($this->fax) {
$phonelist[] = dol_print_phone($this->fax, $this->country_code, $this->id, 0, '', '&nbsp', 'fax');
}
$datas['phonelist'] = '<br>'.implode('&nbsp;', $phonelist);
}
if (!empty($this->address)) {
$datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs); // Address + country
} elseif (!empty($this->country_code)) {
$datas['address'] = '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code;
}
if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) {
$datas['vatintra'] = '<br><b>'.$langs->trans('VATIntra').':</b> '.dol_escape_htmltag($this->tva_intra);
}
if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false && $langs->trans('ProfId1'.$this->country_code) != '-') {
$datas['profid1'] = '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false && $langs->trans('ProfId2'.$this->country_code) != '-') {
$datas['profid2'] = '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false && $langs->trans('ProfId3'.$this->country_code) != '-') {
$datas['profid3'] = '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false && $langs->trans('ProfId4'.$this->country_code) != '-') {
$datas['profid4'] = '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false && $langs->trans('ProfId5'.$this->country_code) != '-') {
$datas['profid5'] = '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false && $langs->trans('ProfId6'.$this->country_code) != '-') {
$datas['profid6'] = '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6;
}
}
if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
$datas['customercode'] = '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client;
}
if (!empty($this->code_fournisseur) && $this->fournisseur) {
$datas['suppliercode'] = '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur;
}
if (isModEnabled('accounting') && ($this->client == 1 || $this->client == 3)) {
$datas['accountancycustomercode'] = '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
}
if (isModEnabled('accounting') && $this->fournisseur) {
$datas['accountancysuppliercode'] = '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur;
}
$datas['divclose'] = '</div>';
return $datas;
}
/**
* Return a link on thirdparty (with picto)
@ -2787,8 +2921,18 @@ class Societe extends CommonObject
$label = $langs->trans("ShowCompany");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip refurl valignmiddle"';
if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
$params = [
'id' => $this->id,
'objecttype' => $this->element,
'option' => $option,
];
$linkclose .= ' data-params='.json_encode($params).' id="societe-' . uniqid() . '" title="' . $langs->trans('Loading') . '"';
$linkclose .= ' class="classforajaxtooltip refurl valignmiddle"';
} else {
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip refurl valignmiddle"';
}
$target_value = array('_self', '_blank', '_parent', '_top');
if (in_array($target, $target_value)) {
$linkclose .= ' target="'.dol_escape_htmltag($target).'"';