2
0
forked from Wavyzz/dolibarr

NEW Reduce nb of picto on ref into list, merging preview and download

This commit is contained in:
Laurent Destailleur
2016-08-05 12:18:51 +02:00
parent 57a542d52d
commit e168888c59
13 changed files with 170 additions and 91 deletions

View File

@@ -634,10 +634,11 @@ if ($result)
$objectstatic->ref=$obj->ref;
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
// Picto + Ref
print '<td class="nobordernopadding nowrap">';
print $objectstatic->getNomUrl(1);
print '</td>';
// Warning
print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
if ($obj->fk_statut == 1 && $db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
if (! empty($obj->note_private))
@@ -647,8 +648,7 @@ if ($result)
print '</span>';
}
print '</td>';
// Ref
// Other picto tool
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
$filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->propal->dir_output . '/' . dol_sanitizeFileName($obj->ref);

View File

@@ -5074,18 +5074,13 @@ class Form
</dl>
<script type="text/javascript">
jQuery(document).ready(function () {
$(".dropdown dt a").on(\'click\', function () {
$(".dropdown dd ul").slideToggle(\'fast\');
console.log($( this ).parent().parent().find(\'dd ul\'));
$( this ).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
// $(".dropdown dd ul").slideToggle(\'fast\');
});
$(".dropdown dd ul li a").on(\'click\', function () {
$(".dropdown dd ul").hide();
});
function getSelectedValue(id) {
return $("#" + id).find("dt a span.value").html();
}
$(document).bind(\'click\', function (e) {
var $clicked = $(e.target);
if (!$clicked.parents().hasClass("dropdown")) $(".dropdown dd ul").hide();
@@ -5104,7 +5099,7 @@ class Form
// Now, we submit page
$(this).parents(\'form:first\').submit();
});
});
</script>
';
@@ -5665,13 +5660,23 @@ class Form
{
if ($file && file_exists($dir."/".$file))
{
if ($addlinktofullsize) $ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
if ($addlinktofullsize)
{
$urladvanced=getAdvancedPreviewUrl($modulepart, $originalfile);
if ($urladvanced) $ret.='<a href="'.$urladvanced.'">';
else $ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
}
$ret.='<img alt="Photo" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="'.$cssclass.'" '.($width?' width="'.$width.'"':'').($height?' height="'.$height.'"':'').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">';
if ($addlinktofullsize) $ret.='</a>';
}
else if ($altfile && file_exists($dir."/".$altfile))
{
if ($addlinktofullsize) $ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
if ($addlinktofullsize)
{
$urladvanced=getAdvancedPreviewUrl($modulepart, $originalfile);
if ($urladvanced) $ret.='<a href="'.$urladvanced.'">';
else $ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
}
$ret.='<img alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="'.$cssclass.'" '.($width?' width="'.$width.'"':'').($height?' height="'.$height.'"':'').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($altfile).'&cache='.$cache.'">';
if ($addlinktofullsize) $ret.='</a>';
}

View File

@@ -586,12 +586,14 @@ class FormFile
{
$file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview\.png)$','date',SORT_DESC);
$out.= '<!-- html.formfile::showdocuments -->'."\n";
// Show title of array if not already shown
if ((! empty($file_list) || preg_match('/^massfilesarea/', $modulepart)) && ! $headershown)
{
$headershown=1;
$out.= '<div class="titre">'.$titletoshow.'</div>';
$out.= '<table class="border" summary="listofdocumentstable" width="100%">';
$out.= '<div class="titre">'.$titletoshow.'</div>'."\n";
$out.= '<table class="border" summary="listofdocumentstable" width="100%">'."\n";
}
// Loop on each file found
@@ -621,7 +623,6 @@ class FormFile
$out.= '</a>'."\n";
$out.= $this->showPreview($file,$modulepart,$relativepath);
$out.= '</td>';
// Show file size
@@ -706,21 +707,28 @@ class FormFile
*/
function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
{
global $conf, $langs;
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$out='';
$this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array());
$file_list=dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir),'/').'[^\-]+', '\.meta$|\.png$'); // Get list of files starting with name fo ref (but not followed by "-" to discard uploaded files)
$file_list=dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir),'/').'[^\-]+', '\.meta$|\.png$'); // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files)
// For ajax treatment
$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
$out.= '<!-- html.formfile::getDocumentsLink -->'."\n";
if (! empty($file_list))
{
$out='<dl class="dropdown">
<dt><a href="#">'.img_picto('', 'listlight').'</a></dt>
<dd><div class="multichoicedoc"><ul class="ulselectedfields" style="display: none;">';
$tmpout='';
// Loop on each file found
foreach($file_list as $file)
{
$i++;
if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter.
// Define relative path for download link (depends on module)
@@ -734,22 +742,31 @@ class FormFile
$relativepath = $file["name"];
}
// Show file name with link to download
$out.= '<a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
$mime=dol_mimetype($relativepath,'',0);
if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
$out.= '>';
$out.= img_mime($relativepath, $file["name"]);
$out.= '</a>'."\n";
$out.= $this->showPreview($file,$modulepart,$relativepath);
$this->infofiles['nboffiles']++;
$this->infofiles['files'][]=$file['fullname'];
$ext=pathinfo($file["name"], PATHINFO_EXTENSION);
if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
else $this->infofiles['extensions'][$ext]++;
$urladvanced = getAdvancedPreviewUrl($modulepart, $relativepath);
if ($urladvanced) $tmpout.= '<li><a href="'.$urladvanced.'">'.img_picto('','detail').' '.$langs->trans("Preview").' '.$ext.'</a></li>';
$tmpout.= '<li><a data-ajax="false" class="pictopreview" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
$mime=dol_mimetype($relativepath,'',0);
if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
$tmpout.= '>';
$tmpout.=img_mime($relativepath, $file["name"]).' ';
$tmpout.= $langs->trans("Download ".$ext);
$tmpout.= '</a></li>'."\n";
}
$out.=$tmpout;
$out.='</ul></div></dd>
</dl>';
}
else
{
// TODO Add link to regenerate doc ?
//$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
}
return $out;
@@ -845,6 +862,7 @@ class FormFile
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td class="tdoverflow">';
//print "XX".$file['name']; //$file['name'] must be utf8
print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
if ($forcedownload) print '&attachment=1';
@@ -882,7 +900,9 @@ class FormFile
//print $file['path'].'/'.$minifile.'<br>';
if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.'.$fileinfo['extension']); // For old thumbs
//print $file['path'].'/'.$minifile.'<br>';
print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" class="aphoto" target="_blank">';
$urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
if (empty($urlforhref)) $urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">';
print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($relativepath.$minifile).'" title="">';
print '</a>';
}
@@ -1328,30 +1348,31 @@ class FormFile
return $nboflinks;
}
/**
* Show detail icon with link for preview
*
* @param array $file File
* @param string $modulepart propal, facture, facture_fourn, ...
* @param string $relativepath Relative path of docs
* @param string $ruleforpicto Rule for picto: 0=Preview picto, 1=Use picto of mime type of file)
* @return string $out Output string with HTML
*/
public function showPreview($file, $modulepart, $relativepath){
public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0)
{
global $langs, $conf;
if (empty($conf->use_javascript_ajax)) return '';
$out='';
$mime_preview = array('jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css');
$num_mime = array_search(dol_mimetype($file['name'], '', 1), $mime_preview);
if( $num_mime!== false){
$out.= ' <a href="javascript:document_preview(\''.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&amp;attachment=0&amp;file='.urlencode($relativepath).'\',\''.dol_mimetype($file['name']).'\', \''.$file['name'].'\')">';
$out.= img_picto($langs->trans('Preview'), 'detail').'</a>';
$urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath);
if ($urladvancedpreview)
{
$out.= '<a data-ajax="false" class="pictopreview" href="'.$urladvancedpreview.'">';
if (empty($ruleforpicto)) $out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
$out.= '</a>';
}
return $out;
}
}
}

View File

@@ -950,13 +950,16 @@ function copyToClipboard(text,text2)
/*
* Function show document preview
*
* @params string file File path
* @params string type mime file
* @params string title
*/
function document_preview(file, type, title){
function document_preview(file, type, title)
{
console.log("document_preview A click was done");
var ValidImageTypes = ["image/gif", "image/jpeg", "image/png"];
console.log("document_preview A click was done. file="+file+", type="+type);
if ($.inArray(type, ValidImageTypes) < 0) {
var width='85%';

View File

@@ -5647,3 +5647,26 @@ function getImageFileNameForSize($file, $extName, $extImgTarget='')
return ($dirName?$dirName.'/':'').$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
}
/**
* Return URL we can use for advanced preview links
*
* @param string $modulepart propal, facture, facture_fourn, ...
* @param string $relativepath Relative path of docs
* @return string Output string with HTML
*/
function getAdvancedPreviewUrl($modulepart, $relativepath)
{
global $conf;
if (empty($conf->use_javascript_ajax)) return '';
$mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css');
//$mime_preview[]='vnd.oasis.opendocument.presentation';
//$mime_preview[]='archive';
$num_mime = array_search(dol_mimetype($relativepath, '', 1), $mime_preview);
if ($num_mime !== false) return 'javascript:document_preview(\''.dol_escape_js(DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&amp;attachment=0&amp;file='.$relativepath).'\', \''.dol_mimetype($relativepath).'\', \''.dol_escape_js('ttt').'\')';
else return '';
}

View File

@@ -502,7 +502,7 @@ if ($resql)
if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
if (! empty($arrayfields['cf.fk_author']['checked'])) print_liste_field_titre($arrayfields['cf.fk_author']['label'],$_SERVER["PHP_SELF"],"u.login","",$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['cf.date_commande']['checked'])) print_liste_field_titre($arrayfields['cf.date_commande']['label'],$_SERVER["PHP_SELF"],"cf.date_commande","",$param,'align="center"',$sortfield,$sortorder);
if (! empty($arrayfields['cf.date_delivery']['checked'])) print_liste_field_titre($arrayfields['cf.date_delivery']['label'],$_SERVER["PHP_SELF"],'cf.date_livraison','',$param, 'align="right"',$sortfield,$sortorder);
if (! empty($arrayfields['cf.date_delivery']['checked'])) print_liste_field_titre($arrayfields['cf.date_delivery']['label'],$_SERVER["PHP_SELF"],'cf.date_livraison','',$param, 'align="center"',$sortfield,$sortorder);
if (! empty($arrayfields['cf.total_ht']['checked'])) print_liste_field_titre($arrayfields['cf.total_ht']['label'],$_SERVER["PHP_SELF"],"cf.total_ht","",$param,'align="right"',$sortfield,$sortorder);
if (! empty($arrayfields['cf.total_vat']['checked'])) print_liste_field_titre($arrayfields['cf.total_vat']['label'],$_SERVER["PHP_SELF"],"cf.tva","",$param,'align="right"',$sortfield,$sortorder);
if (! empty($arrayfields['cf.total_ttc']['checked'])) print_liste_field_titre($arrayfields['cf.total_ttc']['label'],$_SERVER["PHP_SELF"],"cf.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
@@ -712,11 +712,23 @@ if ($resql)
// Ref
if (! empty($arrayfields['cf.ref']['checked']))
{
print '<td class="nowrap">';
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
// Picto + Ref
print '<td class="nobordernopadding nowrap">';
print $objectstatic->getNomUrl(1);
print '</td>';
// Warning
//print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
//print '</td>';
// Other picto tool
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
$filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->fournisseur->dir_output.'/commande' . '/' . dol_sanitizeFileName($obj->ref);
print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
print '</td></tr></table>';
print '</td>'."\n";
if (! $i) $totalarray['nbfield']++;
}

View File

@@ -736,15 +736,23 @@ if ($resql)
{
print '<td class="nowrap">';
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
// Picto + Ref
print '<td class="nobordernopadding nowrap">';
print $facturestatic->getNomUrl(1);
print '</td>';
// Warning
//print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
//print '</td>';
// Other picto tool
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
$filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref);
$subdir = get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref);
print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
print '</td></tr></table>';
print "</td>\n";
if (! $i) $totalarray['nbfield']++;
}

View File

@@ -1968,7 +1968,7 @@ if ($action == '' || $action == 'view')
$var=true;
$somethingshown=$formfile->show_documents($modulepart,$object->id,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang);
$somethingshown=$formfile->show_documents($modulepart,$object->ref,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';

View File

@@ -3710,11 +3710,18 @@ class Product extends CommonObject
else if ($nbbyrow < 0) $return .= '<div class="inline-block">';
$return.= "\n";
if (empty($nolink)) $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
$relativefile=preg_replace('/^\//', '', $pdir.$photo);
if (empty($nolink))
{
$urladvanced=getAdvancedPreviewUrl('product', $relativefile);
if ($urladvanced) $return.='<a href="'.$urladvanced.'">';
else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
}
// Show image (width height=$maxHeight)
// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
$alt=$langs->transnoentitiesnoconv('File').': '.$pdir.$photo;
$alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
$alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

View File

@@ -869,8 +869,8 @@ div.nopadding {
padding-left: 2px;
padding-right: 2px;
}
.pictowarning {
padding-left: 3px;
.pictowarning, .pictopreview {
padding-<?php echo $left; ?>: 3px;
}
.colorthumb {
padding-left: 1px !important;

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

View File

@@ -912,8 +912,8 @@ table.noborder tr.liste_titre td {
padding-left: 2px;
padding-right: 2px;
}
.pictowarning {
padding-left: 3px;
.pictowarning, .pictopreview {
padding-<?php echo $left; ?>: 3px;
}
.colorthumb {
padding-left: 1px !important;