IDEMPIERE-5222 Add Attach button to report viewer (similar to Archive but with Attachment) (#1230)

This commit is contained in:
Carlos Ruiz 2022-03-08 05:22:30 +01:00 committed by GitHub
parent dfb366f363
commit d3e74faa32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 173 additions and 4 deletions

View File

@ -0,0 +1,18 @@
-- IDEMPIERE-5222 Add Attach button to report viewer (similar to Archive but with Attachment)
SELECT register_migration_script('202203072105_IDEMPIERE-5222.sql') FROM dual;
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Mar 7, 2022, 9:05:46 PM CET
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','Document Attached',0,0,'Y',TO_TIMESTAMP('2022-03-07 21:05:46','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-03-07 21:05:46','YYYY-MM-DD HH24:MI:SS'),100,200738,'DocumentAttached','D','40056a6d-100f-4c1f-9748-1d0ccdda901a')
;
-- Mar 7, 2022, 9:05:59 PM CET
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','Attach Error',0,0,'Y',TO_TIMESTAMP('2022-03-07 21:05:59','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-03-07 21:05:59','YYYY-MM-DD HH24:MI:SS'),100,200739,'AttachError','D','55248ed3-7703-41f3-821a-753fbcc1c06b')
;
-- Mar 7, 2022, 9:06:54 PM CET
INSERT INTO AD_ToolBarButton (AD_Client_ID,AD_Org_ID,Created,CreatedBy,ComponentName,IsActive,AD_ToolBarButton_ID,Name,Updated,UpdatedBy,IsCustomization,KeyStroke_KeyCode,KeyStroke_Modifiers,AD_ToolBarButton_UU,Action,IsAdvancedButton,IsAddSeparator,EntityType,IsShowMore) VALUES (0,0,TO_TIMESTAMP('2022-03-07 21:06:54','YYYY-MM-DD HH24:MI:SS'),100,'Attachment','Y',200117,'Report - Attach',TO_TIMESTAMP('2022-03-07 21:06:54','YYYY-MM-DD HH24:MI:SS'),100,'N',0,0,'4e060cb2-f2a7-496c-b882-604814506b5b','R','N','N','D','N')
;

View File

@ -0,0 +1,15 @@
-- IDEMPIERE-5222 Add Attach button to report viewer (similar to Archive but with Attachment)
SELECT register_migration_script('202203072105_IDEMPIERE-5222.sql') FROM dual;
-- Mar 7, 2022, 9:05:46 PM CET
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','Document Attached',0,0,'Y',TO_TIMESTAMP('2022-03-07 21:05:46','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-03-07 21:05:46','YYYY-MM-DD HH24:MI:SS'),100,200738,'DocumentAttached','D','40056a6d-100f-4c1f-9748-1d0ccdda901a')
;
-- Mar 7, 2022, 9:05:59 PM CET
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','Attach Error',0,0,'Y',TO_TIMESTAMP('2022-03-07 21:05:59','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-03-07 21:05:59','YYYY-MM-DD HH24:MI:SS'),100,200739,'AttachError','D','55248ed3-7703-41f3-821a-753fbcc1c06b')
;
-- Mar 7, 2022, 9:06:54 PM CET
INSERT INTO AD_ToolBarButton (AD_Client_ID,AD_Org_ID,Created,CreatedBy,ComponentName,IsActive,AD_ToolBarButton_ID,Name,Updated,UpdatedBy,IsCustomization,KeyStroke_KeyCode,KeyStroke_Modifiers,AD_ToolBarButton_UU,"action",IsAdvancedButton,IsAddSeparator,EntityType,IsShowMore) VALUES (0,0,TO_TIMESTAMP('2022-03-07 21:06:54','YYYY-MM-DD HH24:MI:SS'),100,'Attachment','Y',200117,'Report - Attach',TO_TIMESTAMP('2022-03-07 21:06:54','YYYY-MM-DD HH24:MI:SS'),100,'N',0,0,'4e060cb2-f2a7-496c-b882-604814506b5b','R','N','N','D','N')
;

View File

@ -8,6 +8,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.logging.Level;
@ -30,11 +31,16 @@ import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.model.MArchive;
import org.compiere.model.MAttachment;
import org.compiere.model.MAuthorizationAccount;
import org.compiere.model.MRole;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.MToolBarButtonRestrict;
import org.compiere.model.MUser;
import org.compiere.model.PO;
import org.compiere.model.PrintInfo;
import org.compiere.model.X_AD_ToolBarButton;
import org.compiere.tools.FileUtil;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
@ -59,6 +65,7 @@ import org.zkoss.zul.North;
import org.zkoss.zul.Separator;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Toolbar;
import org.zkoss.zul.Toolbarbutton;
import org.zkoss.zul.impl.Utils;
import org.zkoss.zul.impl.XulElement;
@ -86,7 +93,7 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
/**
*
*/
private static final long serialVersionUID = -812700088629098149L;
private static final long serialVersionUID = -7204858572267608018L;
private JasperPrint jasperPrint;
private java.util.List<JasperPrint> jasperPrintList;
@ -106,7 +113,9 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
private KeyEvent prevKeyEvent;
private String m_title; // local title - embedded windows clear the title
Toolbar toolbar = new Toolbar();
protected ToolBarButton bArchive = new ToolBarButton();
protected ToolBarButton bAttachment = new ToolBarButton();
protected ToolBarButton bExport = new ToolBarButton();
protected ToolBarButton bCloudUpload = new ToolBarButton();
private PrintInfo m_printInfo;
@ -192,7 +201,6 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
this.appendChild(layout);
this.setStyle("width: 100%; height: 100%; position: absolute");
Toolbar toolbar = new Toolbar();
ZKUpdateUtil.setHeight(toolbar, "32px");
previewType.setMold("select");
@ -260,6 +268,20 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
toolbar.appendChild(bArchive);
bArchive.addEventListener(Events.ON_CLICK, this);
int tableId = m_printInfo.getAD_Table_ID();
int recordId = m_printInfo.getRecord_ID();
if (tableId > 0 && recordId > 0) {
toolbar.appendChild(new Separator("vertical"));
bAttachment.setName("Attachment");
if (ThemeManager.isUseFontIconForImage())
bAttachment.setIconSclass("z-icon-Attachment");
else
bAttachment.setImage(ThemeManager.getThemeResource("images/Attachment24.png"));
bAttachment.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Attachment")));
toolbar.appendChild(bAttachment);
bAttachment.addEventListener(Events.ON_CLICK, this);
}
if ( isCanExport )
{
bExport.setName("Export");
@ -300,6 +322,10 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
ZKUpdateUtil.setHeight(iframe, "100%");
ZKUpdateUtil.setWidth(iframe, "100%");
int AD_Window_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "_WinInfo_AD_Window_ID", true);
int AD_Process_ID = m_printInfo.getAD_Process_ID();
updateToolbarAccess(AD_Window_ID, AD_Process_ID);
try {
renderReport();
} catch (Exception e) {
@ -311,6 +337,42 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
this.setBorder("normal");
}
private boolean ToolBarMenuRestictionLoaded = false;
public void updateToolbarAccess(int AD_Window_ID, int AD_Process_ID) {
if (ToolBarMenuRestictionLoaded)
return;
Properties m_ctx = Env.getCtx();
int ToolBarButton_ID = 0;
int[] restrictionList = AD_Window_ID > 0
? MToolBarButtonRestrict.getOfWindow(m_ctx, MRole.getDefault().getAD_Role_ID(), AD_Window_ID, true, null)
: MToolBarButtonRestrict.getOfReport(m_ctx, MRole.getDefault().getAD_Role_ID(), AD_Process_ID, null);
if (log.isLoggable(Level.INFO))
log.info("restrictionList="+restrictionList.toString());
for (int i = 0; i < restrictionList.length; i++)
{
ToolBarButton_ID= restrictionList[i];
X_AD_ToolBarButton tbt = new X_AD_ToolBarButton(m_ctx, ToolBarButton_ID, null);
if (!"R".equals(tbt.getAction()))
continue;
String restrictName = tbt.getComponentName();
if (log.isLoggable(Level.CONFIG)) log.config("tbt="+tbt.getAD_ToolBarButton_ID() + " / " + restrictName);
for (Component p = this.toolbar.getFirstChild(); p != null; p = p.getNextSibling()) {
if (p instanceof Toolbarbutton) {
if ( restrictName.equals(((ToolBarButton)p).getName()) ) {
this.toolbar.removeChild(p);
break;
}
}
}
} // All restrictions
ToolBarMenuRestictionLoaded = true;
}//updateToolbarAccess
private void initMediaSuppliers() {
mediaSuppliers.put(toMediaType(PDF_MIME_TYPE, PDF_FILE_EXT), () -> {
try {
@ -525,6 +587,8 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
cmd_sendMail();
else if (e.getTarget() == bArchive)
cmd_archive();
else if (e.getTarget() == bAttachment)
cmd_attachment();
else if (e.getTarget() == bExport)
cmd_export();
else if (e.getTarget() == bCloudUpload)
@ -810,6 +874,29 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
}
} // cmd_archive
/**
* Create archive for jasper report
*/
protected void cmd_attachment()
{
int tableId = m_printInfo.getAD_Table_ID();
int recordId = m_printInfo.getRecord_ID();
if (tableId == 0 || recordId == 0)
return;
boolean success = false;
MTable table = MTable.get(tableId);
PO po = table.getPO(recordId, null);
MAttachment attachment = po.createAttachment();
String fileName = m_title.replace(" ", "_")+ "_" + m_printInfo.getName() + "." + media.getFormat();
byte[] data = media.isBinary() ? media.getByteData() : media.getStringData().getBytes();
attachment.addEntry(fileName, data);
success = attachment.save();
if (success)
FDialog.info(m_WindowNo, this, "Attached", fileName);
else
FDialog.error(m_WindowNo, this, "AttachError");
} // cmd_archive
/**
* convert File data into Byte Data
* @param tempFile

View File

@ -67,6 +67,7 @@ import org.adempiere.webui.util.ServerPushTemplate;
import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.model.GridField;
import org.compiere.model.MArchive;
import org.compiere.model.MAttachment;
import org.compiere.model.MAuthorizationAccount;
import org.compiere.model.MClient;
import org.compiere.model.MLanguage;
@ -76,6 +77,7 @@ import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.MToolBarButtonRestrict;
import org.compiere.model.MUser;
import org.compiere.model.PO;
import org.compiere.model.SystemIDs;
import org.compiere.model.X_AD_ToolBarButton;
import org.compiere.print.ArchiveEngine;
@ -180,6 +182,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
private Toolbar toolBar = new Toolbar();
private ToolBarButton bSendMail = new ToolBarButton();
private ToolBarButton bArchive = new ToolBarButton();
private ToolBarButton bAttachment = new ToolBarButton();
private ToolBarButton bCustomize = new ToolBarButton();
private ToolBarButton bFind = new ToolBarButton();
private ToolBarButton bExport = new ToolBarButton();
@ -631,6 +634,27 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
if (ThemeManager.isUseFontIconForImage())
LayoutUtils.addSclass("medium-toolbarbutton", bArchive);
int tableId = m_reportEngine.getPrintInfo().getAD_Table_ID();
int recordId = m_reportEngine.getPrintInfo().getRecord_ID();
if (tableId > 0 && recordId > 0) {
bAttachment.setName("Attachment");
if (ThemeManager.isUseFontIconForImage())
bAttachment.setIconSclass("z-icon-Attachment");
else
bAttachment.setImage(ThemeManager.getThemeResource("images/Attachment24.png"));
bAttachment.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Attachment")));
if (toolbarPopup != null)
{
toolbarPopupLayout.appendChild(bAttachment);
bAttachment.setLabel(bAttachment.getTooltiptext());
}
else
toolBar.appendChild(bAttachment);
bAttachment.addEventListener(Events.ON_CLICK, this);
if (ThemeManager.isUseFontIconForImage())
LayoutUtils.addSclass("medium-toolbarbutton", bAttachment);
}
if ( m_isCanExport )
{
bExport.setName("Export");
@ -1242,6 +1266,8 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
cmd_sendMail();
else if (e.getTarget() == bArchive)
cmd_archive();
else if (e.getTarget() == bAttachment)
cmd_attachment();
else if (e.getTarget() == bCustomize)
cmd_customize();
else if (e.getTarget() == bWizard)
@ -1339,6 +1365,29 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
FDialog.error(m_WindowNo, this, "ArchiveError");
} // cmd_archive
/**
* Add Report to Attachment directly
*/
private void cmd_attachment()
{
int tableId = m_reportEngine.getPrintInfo().getAD_Table_ID();
int recordId = m_reportEngine.getPrintInfo().getRecord_ID();
if (tableId == 0 || recordId == 0)
return;
boolean success = false;
MTable table = MTable.get(tableId);
PO po = table.getPO(recordId, null);
MAttachment attachment = po.createAttachment();
byte[] data = media.isBinary() ? media.getByteData() : media.getStringData().getBytes();
String fileName = m_reportEngine.getName().replace(" ", "_") + "_" + m_reportEngine.getPrintInfo().getName() + "." + media.getFormat();
attachment.addEntry(fileName, data);
success = attachment.save();
if (success)
FDialog.info(m_WindowNo, this, "DocumentAttached", fileName);
else
FDialog.error(m_WindowNo, this, "AttachError");
} // cmd_attachment
/**
* Export
*/
@ -1623,7 +1672,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
} // All restrictions
ToolBarMenuRestictionLoaded = true;
}//updateToolBarAndMenuWithRestriction
}//updateToolbarAccess
private void showBusyDialog() {
progressWindow = new BusyDialog();