Skip to content

Commit

Permalink
fix ecmfile tooltip (#30993)
Browse files Browse the repository at this point in the history
* Update ecmfiles.class.php

* Update ecm.lang

* Update ecmfiles.class.php

* add translations

* wip

* wip

* enhance tooltip

* fix

* fix

* fix

* fix ajaxtooltip

* fix picto

* fix picto

* fix sql

* tooltip

* tooltip

* test
  • Loading branch information
frederic34 authored Nov 7, 2024
1 parent 32640c4 commit 4f777f5
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 40 deletions.
1 change: 1 addition & 0 deletions dev/translation/ignore_translation_keys.lst
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ Free
FreeLegalTextOnReceptions
FrequencyPer_
FromPublicEmail
FullPathOrig
Function_getNextValue_InModuleNotWorking
Gantt
GeneratePDF
Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/propal/class/propal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3724,7 +3724,7 @@ public function getTooltipContentArray($params)
return ['optimize' => $langs->trans("Proposal")];
}
if ($user->hasRight('propal', 'lire')) {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Proposal").'</u>';
$datas['picto'] = img_picto('', $this->picto, '', 0, 0, 0, '', 'paddingrightonly').'<u>'.$langs->trans("Proposal").'</u>';
if (isset($this->status)) {
$datas['status'] = ' '.$this->getLibStatut(5);
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/commande/class/commande.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3788,7 +3788,7 @@ public function getTooltipContentArray($params)
}

if ($user->hasRight('commande', 'lire')) {
$datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Order").'</u>';
$datas['picto'] = img_picto('', $this->picto, '', 0, 0, 0, '', 'paddingrightonly').'<u>'.$langs->trans("Order").'</u>';
if (isset($this->statut)) {
$datas['status'] = ' '.$this->getLibStatut(5);
}
Expand Down
34 changes: 19 additions & 15 deletions htdocs/core/class/html.formfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,9 @@ public function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource,
$i = 0;
foreach ($file_list as $file) {
$i++;
require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php';
$ecmfile = new EcmFiles($this->db);
$ecmfile->fetch($file['rowid']);

// Define relative path for download link (depends on module)
$relativepath = (string) $file["name"]; // Cas general
Expand All @@ -996,21 +999,22 @@ public function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource,
} else {
$out .= '<span class="spanoverflow">';
}
$out .= '<a class="documentdownload paddingright" ';
if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
$out .= 'target="_blank" ';
}
$out .= 'href="'.$documenturl.'?modulepart='.$modulepart.'&file='.urlencode($relativepath).($param ? '&'.$param : '').'"';

$mime = dol_mimetype($relativepath, '', 0);
if (preg_match('/text/', $mime)) {
$out .= ' target="_blank" rel="noopener noreferrer"';
}
$out .= ' title="'.dol_escape_htmltag($file["name"]).'"';
$out .= '>';
$out .= img_mime($file["name"], $langs->trans("File").': '.$file["name"]);
$out .= dol_trunc($file["name"], 150);
$out .= '</a>';
// $out .= '<a class="documentdownload paddingright" ';
// if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
// $out .= 'target="_blank" ';
// }
// $out .= 'href="'.$documenturl.'?modulepart='.$modulepart.'&file='.urlencode($relativepath).($param ? '&'.$param : '').'"';

// $mime = dol_mimetype($relativepath, '', 0);
// if (preg_match('/text/', $mime)) {
// $out .= ' target="_blank" rel="noopener noreferrer"';
// }
// $out .= ' title="'.dol_escape_htmltag($file["name"]).'"';
// $out .= '>';
// $out .= img_mime($file["name"], $langs->trans("File").': '.$file["name"]);
// $out .= dol_trunc($file["name"], 150);
// $out .= '</a>';
$out .= $ecmfile->getNomUrl(1, $modulepart, 0, 0, ' documentdownload');
$out .= '</span>'."\n";
$out .= $imgpreview;
$out .= '</td>';
Expand Down
7 changes: 7 additions & 0 deletions htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -13230,6 +13230,13 @@ function getElementProperties($elementType)
$classname = 'Ccountry';
$table_element = 'c_country';
$subelement = '';
} elseif ($elementType == 'ecmfiles') {
$module = 'ecm';
$classpath = 'ecm/class';
$classfile = 'ecmfiles';
$classname = 'Ecmfiles';
$table_element = 'ecmfiles';
$subelement = '';
} elseif ($elementType == 'knowledgerecord') {
$module = '';
$classpath = 'knowledgemanagement/class';
Expand Down
15 changes: 6 additions & 9 deletions htdocs/ecm/class/ecmdirectory.class.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -485,7 +485,7 @@ public function getNomUrl($withpicto = 0, $option = '', $max = 0, $more = '', $n
$result = '';
//$newref=str_replace('_',' ',$this->ref);
$newref = $this->ref;
$label = $langs->trans("ShowECMSection").': '.$newref;
$label = img_picto('', $this->picto, '', 0, 0, 0, '', 'paddingrightonly') . $langs->trans("ShowECMSection") . ': ' . $newref;
$linkclose = '"'.($more ? ' '.$more : '').' title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';

$linkstart = '<a href="'.DOL_URL_ROOT.'/ecm/dir_card.php?section='.$this->id.$linkclose;
Expand All @@ -500,9 +500,6 @@ public function getNomUrl($withpicto = 0, $option = '', $max = 0, $more = '', $n
}
$linkend = '</a>';

//$picto=DOL_URL_ROOT.'/theme/common/treemenu/folder.gif';
$picto = 'dir';

$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);
Expand Down Expand Up @@ -616,7 +613,7 @@ public function getLibStatut($mode = 0)
public static function LibStatut($status, $mode = 0)
{
// phpcs:enable
global $langs;

return '';
}

Expand Down
78 changes: 64 additions & 14 deletions htdocs/ecm/class/ecmfiles.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2018 Francis Appels <francis.appels@yahoo.com>
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -903,57 +903,106 @@ public function updateAfterRename($olddir, $newdir)
$this->db->query($sql);
}

/**
* getTooltipContentArray
* @param array<string,mixed> $params params to construct tooltip data
* @since v21
* @return array{picto?:string,ref?:string,gen_or_upload?:string}|array{optimize:string}
*/
public function getTooltipContentArray($params)
{
global $conf, $langs, $user;

$langs->load('ecm');
$datas = [];
$nofetch = !empty($params['nofetch']);

if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
return ['optimize' => $langs->trans("ShowFile")];
}
$datas['picto'] = img_picto('', $this->picto, '', 0, 0, 0, '', 'paddingrightonly') . '<u>' . $langs->trans("ShowFile") . '</u>';
if (!empty($this->ref)) {
$datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
}
if (!empty($this->gen_or_uploaded)) {
$datas['gen_or_upload'] .= '<br><b>'.$langs->trans('GenOrUpload').':</b> '.$this->gen_or_uploaded;
}

return $datas;
}

/**
* Return a link to the object card (with optionally the picto)
*
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
* @param string $option On what the link point to
* @param string $option On what the link point to (propal, etc) module name
* @param int $notooltip 1=Disable tooltip
* @param int $maxlen Max length of visible user name
* @param string $morecss Add more css on link
* @return string String with URL
*/
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
{
global $db, $conf, $langs;
global $dolibarr_main_authentication, $dolibarr_main_demo;
global $menumanager, $hookmanager;
global $conf, $hookmanager, $langs;

if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}

$result = '';

$label = '<u>'.$langs->trans("File").'</u>';
$label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
$params = [
'id' => $this->id,
'objecttype' => $this->element,
'option' => $option,
'nofetch' => 1,
];
$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.'/ecm/file_card.php?id='.$this->id;
if ($option) {
$url = DOL_URL_ROOT.'/document.php?modulepart='.$option.'&file='.urlencode(preg_replace('/[a-zA-Z]+\//', '', $this->filepath).'/'.$this->filename).'&entity='.$this->entity;
} else {
$url = DOL_URL_ROOT.'/ecm/file_card.php?id='.$this->id;
}

$linkclose = '';
if (empty($notooltip)) {
if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
$label = $langs->trans("ShowProject");
$label = $langs->trans("ShowFile");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
$linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
$linkclose .= $dataparams.' class="'.$classfortooltip.' '.($morecss ? ' '.$morecss : '').'"';
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}

$linkstart = '<a href="'.$url.'"';
if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
$linkstart .= 'target="_blank" ';
}
$linkstart .= $linkclose.'>';
$linkend = '</a>';

if ($withpicto) {
$result .= ($linkstart.img_object(($notooltip ? '' : $label), 'label', ($notooltip ? '' : 'class="classfortooltip"')).$linkend);
if (empty($this->filename)) {
$result .= ($linkstart.img_object(($notooltip ? '' : $label), 'label', ($notooltip ? '' : 'class="paddingright"')).$linkend);
} else {
$result .= ($linkstart.img_mime($this->filename, ($notooltip ? '' : $label), ($notooltip ? '' : 'class="paddingright"')).$linkend);
}
if ($withpicto != 2) {
$result .= ' ';
}
}
$result .= $linkstart.$this->ref.$linkend;
$result .= $linkstart.$this->filename.$linkend;

global $action;
$hookmanager->initHooks(array($this->element . 'dao'));
Expand All @@ -964,6 +1013,7 @@ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen
} else {
$result .= $hookmanager->resPrint;
}

return $result;
}

Expand Down
3 changes: 3 additions & 0 deletions htdocs/langs/en_US/ecm.lang
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ SucessConvertImgWebp=Images successfully duplicated
SucessConvertChosenImgWebp=Chosen image successfully duplicated
ECMDirName=Dir name
ECMParentDirectory=Parent directory
ShowFile=Show file
FullPathOrig=Full path origin
GenOrUpload=File origin

0 comments on commit 4f777f5

Please sign in to comment.