diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index 0e57118f4bb60..bd7ee30c2779c 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -619,6 +619,9 @@ function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed
$out.= ' target="_blank">';
$out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]).' '.dol_trunc($file["name"],$maxfilenamelength);
$out.= ''."\n";
+
+ $out.= $this->showPreview($file,$modulepart,$relativepath);
+
$out.= '';
// Show file size
@@ -739,6 +742,8 @@ function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
$out.= img_mime($relativepath, $file["name"]);
$out.= ''."\n";
+ $out.= $this->showPreview($file,$modulepart,$relativepath);
+
$this->infofiles['nboffiles']++;
$this->infofiles['files'][]=$file['fullname'];
$ext=pathinfo($file["name"], PATHINFO_EXTENSION);
@@ -859,6 +864,9 @@ function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownlo
//print dol_trunc($file['name'],$maxlength,'middle');
print $file['name'];
print '';
+
+ print $this->showPreview($file,$modulepart,$filepath);
+
print "\n";
print '
'.dol_print_size($file['size'],1,1).' | ';
print ''.dol_print_date($file['date'],"dayhour","tzuser").' | ';
@@ -1320,5 +1328,30 @@ public function listOfLinks($object, $permtodelete=1, $action=null, $selected=nu
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
+ * @return string $out Output string with HTML
+ */
+ public function showPreview($file, $modulepart, $relativepath){
+ 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.= ' ';
+ $out.= img_picto($langs->trans('Preview'), 'detail').'';
+
+ return $out;
+ }
+ }
+
}
diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php
index 0baea91412f6e..d64b05ccd8c95 100644
--- a/htdocs/core/js/lib_head.js.php
+++ b/htdocs/core/js/lib_head.js.php
@@ -948,6 +948,65 @@ function copyToClipboard(text,text2)
return false;
}
+/*
+ * Function show document preview
+ * @params string file File path
+ * @params string type mime file
+ * @params string title
+ */
+function document_preview(file, type, title){
+
+ var ValidImageTypes = ["image/gif", "image/jpeg", "image/png"];
+
+ if ($.inArray(type, ValidImageTypes) < 0) {
+ var width='85%';
+ var object_width='100%';
+ var height = $( window ).height()*0.90;
+ var object_height='98%';
+
+ show_preview();
+
+ } else {
+ var object_width=0;
+ var object_height=0;
+
+ var img = new Image();
+
+ img.onload = function() {
+ object_width = this.width;
+ object_height = this.height;
+
+ width = $( window ).width()*0.90;
+ if(object_width < width){
+ width = object_width + 30
+ }
+ height = $( window ).height()*0.85;
+ if(object_height < height){
+ height = object_height + 80
+ }
+
+ show_preview();
+
+ };
+ img.src = file;
+
+ }
+ function show_preview(){
+
+ var newElem = '';
+
+ $("#dialogforpopup").html(newElem);
+ $("#dialogforpopup").dialog({
+ closeOnEscape: true,
+ resizable: true,
+ width: width,
+ height: height,
+ modal: true,
+ title: title
+ });
+ }
+}
+
/*
* Provide a function to get an URL GET parameter in javascript
*