diff --git a/migration/i8.2/oracle/202106081633_IDEMPIERE-3980.sql b/migration/i8.2/oracle/202106081633_IDEMPIERE-3980.sql new file mode 100644 index 0000000000..7ccff59d9f --- /dev/null +++ b/migration/i8.2/oracle/202106081633_IDEMPIERE-3980.sql @@ -0,0 +1,11 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-3980 +-- Jun 8, 2021, 4:32:50 PM CEST +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('E','File not allowed for uploading, just image types jpg/png/gif/tiff/bmp/ico',0,0,'Y',TO_DATE('2021-06-08 16:32:49','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-06-08 16:32:49','YYYY-MM-DD HH24:MI:SS'),100,200711,'UploadImageTypeNotAllowed','D','7f3ed66b-6875-49e2-b45f-42ed9c7548e1') +; + +SELECT register_migration_script('202106081633_IDEMPIERE-3980.sql') FROM dual +; + diff --git a/migration/i8.2/postgresql/202106081633_IDEMPIERE-3980.sql b/migration/i8.2/postgresql/202106081633_IDEMPIERE-3980.sql new file mode 100644 index 0000000000..8319e73ca4 --- /dev/null +++ b/migration/i8.2/postgresql/202106081633_IDEMPIERE-3980.sql @@ -0,0 +1,8 @@ +-- IDEMPIERE-3980 +-- Jun 8, 2021, 4:32:50 PM CEST +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('E','File not allowed for uploading, just image types jpg/png/gif/tiff/bmp/ico',0,0,'Y',TO_TIMESTAMP('2021-06-08 16:32:49','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-06-08 16:32:49','YYYY-MM-DD HH24:MI:SS'),100,200711,'UploadImageTypeNotAllowed','D','7f3ed66b-6875-49e2-b45f-42ed9c7548e1') +; + +SELECT register_migration_script('202106081633_IDEMPIERE-3980.sql') FROM dual +; + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WImageDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WImageDialog.java index 17f5655500..825c847e2e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WImageDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WImageDialog.java @@ -17,8 +17,11 @@ package org.adempiere.webui.window; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; +import org.adempiere.exceptions.AdempiereException; import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.ClientInfo; import org.adempiere.webui.LayoutUtils; @@ -34,6 +37,7 @@ import org.compiere.model.MImage; import org.compiere.util.CLogger; import org.compiere.util.Env; +import org.compiere.util.MimeType; import org.compiere.util.Msg; import org.compiere.util.Util; import org.zkoss.image.AImage; @@ -47,7 +51,7 @@ import org.zkoss.zul.Center; import org.zkoss.zul.Div; import org.zkoss.zul.Hbox; -import org.zkoss.zul.Image; +import org.zkoss.zul.Iframe; import org.zkoss.zul.North; import org.zkoss.zul.Separator; import org.zkoss.zul.South; @@ -97,6 +101,9 @@ public WImageDialog (MImage mImage) AImage aImage = new AImage(m_mImage.getName(), m_mImage.getData()); image.setContent(aImage); + image.setClientAttribute("sandbox", ""); + image.setVisible(true); + image.invalidate(); } catch (Exception e) { log.log(Level.WARNING, "load image", e); } @@ -117,7 +124,7 @@ public WImageDialog (MImage mImage) private Panel parameterPanel = new Panel(); private Button fileButton = new Button(); private Button captureButton = new Button(); - private Image image = new Image(); + private Iframe image = new Iframe(); private ConfirmPanel confirmPanel = new ConfirmPanel(true,false,true,false,false,false); private boolean cancel = false; private Textbox fileNameTextbox = new Textbox(); @@ -125,7 +132,19 @@ public WImageDialog (MImage mImage) private Div captureDiv; private String defaultNameForCaptureImage = "CapturedImage"; private Button cancelCaptureButton; - + + private static List autoPreviewList; + + static { + autoPreviewList = new ArrayList(); + autoPreviewList.add("image/jpeg"); + autoPreviewList.add("image/png"); + autoPreviewList.add("image/gif"); + autoPreviewList.add("image/tiff"); + autoPreviewList.add("image/bmp"); + autoPreviewList.add("image/x-icon"); + } + /** * Static Init * @throws Exception @@ -243,6 +262,9 @@ else if (e.getTarget().getId().equals(ConfirmPanel.A_RESET)) { AImage img = null; image.setContent(img); + image.setClientAttribute("sandbox", ""); + image.setVisible(true); + image.invalidate(); fileNameTextbox.setValue(null); } else if (e.getTarget() == captureButton) @@ -270,6 +292,9 @@ else if (e.getName().equals("onCaptureImage")) byte[] imageData = Base64.decodeBase64(dataUrl.substring(contentStartIndex).getBytes()); AImage img = new AImage(defaultNameForCaptureImage, imageData); image.setContent(img); + image.setClientAttribute("sandbox", ""); + image.setVisible(true); + image.invalidate(); if (m_mImage == null) m_mImage = new MImage (Env.getCtx(), 0, null); @@ -328,14 +353,25 @@ private void processUploadMedia(Media imageFile) { return; String fileName = imageFile.getName(); - + String mimeType = MimeType.getMimeType(fileName); + if (! autoPreviewList.contains(mimeType)) + throw new AdempiereException(Msg.getMsg(Env.getCtx(), "UploadImageTypeNotAllowed")); + // See if we can load & display it try { InputStream is = imageFile.getStreamData(); AImage aImage = new AImage(fileName, is); - - image.setContent(aImage); + + if (autoPreviewList.contains(mimeType)) { + image.setContent(aImage); + image.setClientAttribute("sandbox", ""); + image.setVisible(true); + image.invalidate(); + } else { + image.setSrc(null); + image.setVisible(false); + } is.close(); }