IDEMPIERE-1117 Attachment -> Disable preview over certain size (#145)

* IDEMPIERE-1117 Attachment -> Disable preview over certain size

New SysConfig key ZK_MAX_ATTACHMENT_PREVIEW_SIZE

* IDEMPIERE-1117 move scripts to 7.1
This commit is contained in:
Carlos Ruiz 2020-07-14 15:51:17 +02:00 committed by GitHub
parent eaba03cd42
commit 2d70a1a169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 6 deletions

View File

@ -0,0 +1,15 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-1117 Attachment -> Disable preview over certain size
-- Jun 26, 2020, 11:05:28 PM CEST
INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200154,0,0,TO_DATE('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_MAX_ATTACHMENT_PREVIEW_SIZE','1048576','Max size in bytes for a file to be previewed in attachment window','D','C','c1eb659c-2e44-4717-8407-d9075f2436ed')
;
-- Jun 26, 2020, 11:07:11 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 ('I','<html>The file is too large for automatic viewing, click the Preview button to load it</html>',0,0,'Y',TO_DATE('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,200620,'FileTooBigForPreview','D','013da62e-8989-4682-9f1b-36f568d773d4')
;
SELECT register_migration_script('202006262307_IDEMPIERE-1117.sql') FROM dual
;

View File

@ -0,0 +1,12 @@
-- IDEMPIERE-1117 Attachment -> Disable preview over certain size
-- Jun 26, 2020, 11:05:28 PM CEST
INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200154,0,0,TO_TIMESTAMP('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_MAX_ATTACHMENT_PREVIEW_SIZE','1048576','Max size in bytes for a file to be previewed in attachment window','D','C','c1eb659c-2e44-4717-8407-d9075f2436ed')
;
-- Jun 26, 2020, 11:07:11 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 ('I','<html>The file is too large for automatic viewing, click the Preview button to load it</html>',0,0,'Y',TO_TIMESTAMP('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,200620,'FileTooBigForPreview','D','013da62e-8989-4682-9f1b-36f568d773d4')
;
SELECT register_migration_script('202006262307_IDEMPIERE-1117.sql') FROM dual
;

View File

@ -43,7 +43,7 @@ public class MSysConfig extends X_AD_SysConfig
/** /**
* *
*/ */
private static final long serialVersionUID = -1766118478735242840L; private static final long serialVersionUID = 4339975517612838655L;
public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION"; public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION";
public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS"; public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS";
@ -182,6 +182,7 @@ public class MSysConfig extends X_AD_SysConfig
public static final String ZK_LOGIN_ALLOW_REMEMBER_ME = "ZK_LOGIN_ALLOW_REMEMBER_ME"; public static final String ZK_LOGIN_ALLOW_REMEMBER_ME = "ZK_LOGIN_ALLOW_REMEMBER_ME";
public static final String ZK_LOGO_LARGE = "ZK_LOGO_LARGE"; public static final String ZK_LOGO_LARGE = "ZK_LOGO_LARGE";
public static final String ZK_LOGO_SMALL = "ZK_LOGO_SMALL"; public static final String ZK_LOGO_SMALL = "ZK_LOGO_SMALL";
public static final String ZK_MAX_ATTACHMENT_PREVIEW_SIZE = "ZK_MAX_ATTACHMENT_PREVIEW_SIZE";
public static final String ZK_MAX_UPLOAD_SIZE = "ZK_MAX_UPLOAD_SIZE"; public static final String ZK_MAX_UPLOAD_SIZE = "ZK_MAX_UPLOAD_SIZE";
public static final String ZK_MOBILE_PAGING_SIZE = "ZK_MOBILE_PAGING_SIZE"; public static final String ZK_MOBILE_PAGING_SIZE = "ZK_MOBILE_PAGING_SIZE";
public static final String ZK_PAGING_DETAIL_SIZE = "ZK_PAGING_DETAIL_SIZE"; public static final String ZK_PAGING_DETAIL_SIZE = "ZK_PAGING_DETAIL_SIZE";

View File

@ -44,8 +44,10 @@ import org.adempiere.webui.factory.ButtonFactory;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
import org.adempiere.webui.window.WTextEditorDialog;
import org.compiere.model.MAttachment; import org.compiere.model.MAttachment;
import org.compiere.model.MAttachmentEntry; import org.compiere.model.MAttachmentEntry;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -107,7 +109,7 @@ public class WAttachment extends Window implements EventListener<Event>
private Button bLoad = new Button(); private Button bLoad = new Button();
private Button bCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL, false, true); private Button bCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL, false, true);
private Button bOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK, false, true); private Button bOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK, false, true);
private Button bRefresh = ButtonFactory.createNamedButton(ConfirmPanel.A_REFRESH, false, true); private Button bPreview = new Button();
private Panel previewPanel = new Panel(); private Panel previewPanel = new Panel();
@ -121,6 +123,8 @@ public class WAttachment extends Window implements EventListener<Event>
private String orientation; private String orientation;
private int maxPreviewSize;
private static List<String> autoPreviewList; private static List<String> autoPreviewList;
static { static {
@ -163,6 +167,7 @@ public class WAttachment extends Window implements EventListener<Event>
int AD_Table_ID, int Record_ID, String trxName, EventListener<Event> eventListener) int AD_Table_ID, int Record_ID, String trxName, EventListener<Event> eventListener)
{ {
super(); super();
maxPreviewSize = MSysConfig.getIntValue(MSysConfig.ZK_MAX_ATTACHMENT_PREVIEW_SIZE, 1048576, Env.getAD_Client_ID(Env.getCtx()));
if (log.isLoggable(Level.CONFIG)) log.config("ID=" + AD_Attachment_ID + ", Table=" + AD_Table_ID + ", Record=" + Record_ID); if (log.isLoggable(Level.CONFIG)) log.config("ID=" + AD_Attachment_ID + ", Table=" + AD_Table_ID + ", Record=" + Record_ID);
@ -336,10 +341,16 @@ public class WAttachment extends Window implements EventListener<Event>
bDeleteAll.addEventListener(Events.ON_CLICK, this); bDeleteAll.addEventListener(Events.ON_CLICK, this);
bDeleteAll.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "DeleteAll"))); bDeleteAll.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "DeleteAll")));
bRefresh.addEventListener(Events.ON_CLICK, this); if (ThemeManager.isUseFontIconForImage())
bPreview.setIconSclass("z-icon-Find");
else
bPreview.setImage(ThemeManager.getThemeResource("images/Find24.png"));
bPreview.setSclass("img-btn");
bPreview.addEventListener(Events.ON_CLICK, this);
bPreview.setTooltiptext(Msg.getMsg(Env.getCtx(), "Preview"));
confirmPanel.appendChild(bDeleteAll); confirmPanel.appendChild(bDeleteAll);
confirmPanel.appendChild(bRefresh); confirmPanel.appendChild(bPreview);
ZKUpdateUtil.setHflex(confirmPanel, "1"); ZKUpdateUtil.setHflex(confirmPanel, "1");
Hbox hbox = new Hbox(); Hbox hbox = new Hbox();
hbox.setPack("end"); hbox.setPack("end");
@ -438,7 +449,17 @@ public class WAttachment extends Window implements EventListener<Event>
if (autoPreviewList.contains(mimeType)) if (autoPreviewList.contains(mimeType))
{ {
if (data.length <= maxPreviewSize) {
displayData(index, immediate); displayData(index, immediate);
} else {
clearPreview();
String msg = WTextEditorDialog.sanitize(Msg.getMsg(Env.getCtx(), "FileTooBigForPreview"));
Media media = new AMedia(null, null, "text/html", msg.getBytes());
preview.setContent(media);
preview.setVisible(true);
bPreview.setEnabled(true);
return false;
}
return true; return true;
} }
else else
@ -473,6 +494,7 @@ public class WAttachment extends Window implements EventListener<Event>
displaySelected(); displaySelected();
else else
Clients.response(new AuEcho(this, "displaySelected", null)); Clients.response(new AuEcho(this, "displaySelected", null));
bPreview.setEnabled(false);
} // displayData } // displayData
private void clearPreview() private void clearPreview()
@ -584,7 +606,7 @@ public class WAttachment extends Window implements EventListener<Event>
} else if (e.getTarget() == bSave) { } else if (e.getTarget() == bSave) {
// Open Attachment // Open Attachment
saveAttachmentToFile(); saveAttachmentToFile();
} else if (e.getTarget() == bRefresh) { } else if (e.getTarget() == bPreview) {
displayData(cbContent.getSelectedIndex(), true); displayData(cbContent.getSelectedIndex(), true);
} else if (e.getTarget() == bSaveAllAsZip) { } else if (e.getTarget() == bSaveAllAsZip) {
saveAllAsZip(); saveAllAsZip();