2
0
forked from Wavyzz/dolibarr

NEW Popup for preview of image add a button "Original size"

This commit is contained in:
Laurent Destailleur
2017-08-22 13:14:10 +02:00
parent 927da89c89
commit 5cf684f5a2
3 changed files with 42 additions and 5 deletions

View File

@@ -983,6 +983,8 @@ function newpopup(url,title) {
function document_preview(file, type, title) function document_preview(file, type, title)
{ {
var ValidImageTypes = ["image/gif", "image/jpeg", "image/png"]; var ValidImageTypes = ["image/gif", "image/jpeg", "image/png"];
var showOriginalSizeButton = false;
console.log("document_preview A click was done. file="+file+", type="+type+", title="+title); console.log("document_preview A click was done. file="+file+", type="+type+", title="+title);
if ($.inArray(type, ValidImageTypes) < 0) { if ($.inArray(type, ValidImageTypes) < 0) {
@@ -991,7 +993,7 @@ function document_preview(file, type, title)
var height = $( window ).height()*0.90; var height = $( window ).height()*0.90;
var object_height='98%'; var object_height='98%';
show_preview(); show_preview('notimage');
} else { } else {
var object_width=0; var object_width=0;
@@ -1005,23 +1007,38 @@ function document_preview(file, type, title)
width = $( window ).width()*0.90; width = $( window ).width()*0.90;
if(object_width < width){ if(object_width < width){
console.log("Object width is small, we set width of popup according to image width.");
width = object_width + 30 width = object_width + 30
} }
height = $( window ).height()*0.85; height = $( window ).height()*0.85;
if(object_height < height){ if(object_height < height){
console.log("Object height is small, we set height of popup according to image height.");
height = object_height + 80 height = object_height + 80
} }
else
{
showOriginalSizeButton = true;
}
show_preview(); show_preview('image');
}; };
img.src = file; img.src = file;
} }
function show_preview(){ function show_preview(mode) {
/* console.log("file="+file+" type="+type+" width="+width+" height="+height); */ console.log("mode="+mode+" file="+file+" type="+type+" width="+width+" height="+height);
var newElem = '<object name="objectpreview" data="'+file+'" type="'+type+'" width="'+object_width+'" height="'+object_height+'" param="noparam"></object>'; var newElem = '<object name="objectpreview" data="'+file+'" type="'+type+'" width="'+object_width+'" height="'+object_height+'" param="noparam"></object>';
optionsbuttons = {}
if (mode == 'image' && showOriginalSizeButton)
{
optionsbuttons = {
"<?php echo dol_escape_js($langs->trans("OriginalSize")); ?>": function() { console.log("Click on original size"); jQuery(".ui-dialog-content.ui-widget-content > object").css({ "max-height": "none" }); },
"<?php echo dol_escape_js($langs->trans("Close")); ?>": function() { $( this ).dialog( "close" ); }
};
}
$("#dialogforpopup").html(newElem); $("#dialogforpopup").html(newElem);
$("#dialogforpopup").dialog({ $("#dialogforpopup").dialog({
closeOnEscape: true, closeOnEscape: true,
@@ -1029,8 +1046,14 @@ function document_preview(file, type, title)
width: width, width: width,
height: height, height: height,
modal: true, modal: true,
title: title title: title,
buttons: optionsbuttons
}); });
if (showOriginalSizeButton)
{
jQuery(".ui-dialog-content.ui-widget-content > object").css({ "max-height": "100%", "width": "auto", "margin-left": "auto", "margin-right": "auto", "display": "block" });
}
} }
} }

View File

@@ -460,6 +460,7 @@ Discount=Discount
Unknown=Unknown Unknown=Unknown
General=General General=General
Size=Size Size=Size
OriginalSize=Original size
Received=Received Received=Received
Paid=Paid Paid=Paid
Topic=Subject Topic=Subject

View File

@@ -3148,6 +3148,19 @@ div.titre {
font-size: <?php print $fontsize; ?>px !important; font-size: <?php print $fontsize; ?>px !important;
} }
/* ============================================================================== */
/* For content of image preview */
/* ============================================================================== */
/*
.ui-dialog-content.ui-widget-content > object {
max-height: none;
width: auto; margin-left: auto; margin-right: auto; display: block;
}
*/
/* ============================================================================== */ /* ============================================================================== */
/* Formulaire confirmation (When HTML is used) */ /* Formulaire confirmation (When HTML is used) */
/* ============================================================================== */ /* ============================================================================== */