From 3a0d154c52ca84ab7c80ffe61efbfb90eb11b7a2 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Sanchez Date: Wed, 29 May 2013 18:45:20 -0500 Subject: [PATCH] IDEMPIERE-970 Role with the can Export option deselected would actually be able to export / jasper --- .../oracle/20130529121300_IDEMPIERE-970.sql | 8 +++ .../20130529121300_IDEMPIERE-970.sql | 9 +++ .../src/org/compiere/model/MSysConfig.java | 2 + .../adempiere/webui/window/ZkJRViewer.java | 58 +++++++++++++++---- 4 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 migration/i1.0b-release/oracle/20130529121300_IDEMPIERE-970.sql create mode 100644 migration/i1.0b-release/postgresql/20130529121300_IDEMPIERE-970.sql diff --git a/migration/i1.0b-release/oracle/20130529121300_IDEMPIERE-970.sql b/migration/i1.0b-release/oracle/20130529121300_IDEMPIERE-970.sql new file mode 100644 index 0000000000..3349593a0e --- /dev/null +++ b/migration/i1.0b-release/oracle/20130529121300_IDEMPIERE-970.sql @@ -0,0 +1,8 @@ +-- May 29, 2013 12:13:00 PM COT +-- IDEMPIERE-970 Role with the "can Export" option deselected would actually be able to export +INSERT INTO AD_SysConfig (AD_SysConfig_ID,ConfigurationLevel,Value,Description,AD_SysConfig_UU,Created,Updated,AD_Org_ID,CreatedBy,IsActive,UpdatedBy,Name,AD_Client_ID,EntityType) VALUES (200030,'S','HTML','Sets default jasper output type','7dbe0a07-d566-419e-9f81-003cf0be6b52',TO_DATE('2013-05-29 12:13:00','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2013-05-29 12:13:00','YYYY-MM-DD HH24:MI:SS'),0,100,'Y',100,'ZK_REPORT_JASPER_OUTPUT_TYPE',0,'D') +; + +SELECT register_migration_script('20130529121300_IDEMPIERE-970.sql') FROM dual +; + diff --git a/migration/i1.0b-release/postgresql/20130529121300_IDEMPIERE-970.sql b/migration/i1.0b-release/postgresql/20130529121300_IDEMPIERE-970.sql new file mode 100644 index 0000000000..083eafc4a2 --- /dev/null +++ b/migration/i1.0b-release/postgresql/20130529121300_IDEMPIERE-970.sql @@ -0,0 +1,9 @@ +-- May 29, 2013 12:13:00 PM COT +-- IDEMPIERE-970 Role with the "can Export" option deselected would actually be able to export +INSERT INTO AD_SysConfig (AD_SysConfig_ID,ConfigurationLevel,Value,Description,AD_SysConfig_UU,Created,Updated,AD_Org_ID,CreatedBy,IsActive,UpdatedBy,Name,AD_Client_ID,EntityType) VALUES (200030,'S','HTML','Sets default jasper output type','7dbe0a07-d566-419e-9f81-003cf0be6b52',TO_TIMESTAMP('2013-05-29 12:13:00','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2013-05-29 12:13:00','YYYY-MM-DD HH24:MI:SS'),0,100,'Y',100,'ZK_REPORT_JASPER_OUTPUT_TYPE',0,'D') +; + +SELECT register_migration_script('20130529121300_IDEMPIERE-970.sql') FROM dual +; + + diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index 7e9ba4d630..bc03d67fd5 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -117,6 +117,8 @@ public class MSysConfig extends X_AD_SysConfig public static final String DOCACTIONBUTTON_SHOWACTIONNAME = "DOCACTIONBUTTON_SHOWACTIONNAME"; public static final String ZK_MAX_UPLOAD_SIZE = "ZK_MAX_UPLOAD_SIZE"; public static final String CALENDAR_ALTERNATE_TIMEZONE = "CALENDAR_ALTERNATE_TIMEZONE"; + public static final String ZK_REPORT_JASPER_OUTPUT_TYPE="ZK_REPORT_JASPER_OUTPUT_TYPE"; + /** * Standard Constructor diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java index df7e52ebfe..eba050ec80 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java @@ -18,13 +18,18 @@ import net.sf.jasperreports.engine.export.JRXlsExporter; import net.sf.jasperreports.engine.export.JRXlsExporterParameter; import net.sf.jasperreports.engine.util.LocalJasperReportsContext; +import ognl.DefaultTypeConverter; + import org.adempiere.exceptions.AdempiereException; import org.adempiere.webui.component.Listbox; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Window; import org.adempiere.webui.panel.ITabOnCloseHandler; import org.adempiere.webui.session.SessionManager; +import org.compiere.model.MRole; +import org.compiere.model.MSysConfig; import org.compiere.util.CLogger; +import org.compiere.util.Env; import org.zkoss.util.media.AMedia; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; @@ -49,6 +54,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl private Listbox previewType = new Listbox(); private Iframe iframe; private AMedia media; + private String defaultType; /** Logger */ private static CLogger log = CLogger.getCLogger(ZkJRViewer.class); @@ -64,6 +70,9 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl } private void init() { + final boolean isCanExport=MRole.getDefault().isCanExport(); + defaultType=MSysConfig.getValue(MSysConfig.ZK_REPORT_JASPER_OUTPUT_TYPE);//It gets default Jasper output type + Borderlayout layout = new Borderlayout(); layout.setStyle("position: absolute; height: 99%; width: 99%"); this.appendChild(layout); @@ -71,12 +80,36 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl Toolbar toolbar = new Toolbar(); toolbar.setHeight("26px"); - + previewType.setMold("select"); - previewType.appendItem("PDF", "PDF"); - previewType.appendItem("HTML", "HTML"); - previewType.appendItem("Excel", "XLS"); - previewType.appendItem("CSV", "CSV"); + if( isCanExport ){ + previewType.appendItem("HTML", "HTML"); + previewType.appendItem("PDF", "PDF"); + previewType.appendItem("Excel", "XLS"); + previewType.appendItem("CSV", "CSV"); + if( "HTML".equals(defaultType) ){ + previewType.setSelectedIndex(0); + } else if( "PDF".equals(defaultType) ){ + previewType.setSelectedIndex(1); + } else if( "XLS".equals(defaultType) ){ + previewType.setSelectedIndex(2); + } else if( "CSV".equals(defaultType) ){ + previewType.setSelectedIndex(3); + } else { + previewType.setSelectedIndex(1); + log.info("Format not Valid: "+defaultType); + } + }else{ + previewType.appendItem("HTML", "HTML"); + previewType.appendItem("PDF", "PDF"); + if( "XLS".equals(defaultType) || "CSV".equals(defaultType) ){ + defaultType="PDF"; + }else if("HTML".equals(defaultType) || "PDF".equals(defaultType)){} + else log.info("Format not Valid: "+defaultType); + + previewType.setSelectedIndex(1); + } + toolbar.appendChild(previewType); previewType.addEventListener(Events.ON_SELECT, this); @@ -112,7 +145,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl prefix.append(ch); } else { prefix.append("_"); - } + } } return prefix.toString(); } @@ -129,7 +162,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl private void cmd_render() { try { - renderReport(); + renderReport(); } catch (Exception e) { throw new AdempiereException("Failed to render report", e); } @@ -141,11 +174,14 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl } private void renderReport() throws Exception { + String reportType; ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(JasperReport.class.getClassLoader()); Listitem selected = previewType.getSelectedItem(); - if (selected == null || "PDF".equals(selected.getValue())) { + reportType=selected.getValue(); + if ( "PDF".equals( reportType ) ) + { String path = System.getProperty("java.io.tmpdir"); String prefix = makePrefix(jasperPrint.getName()); if (log.isLoggable(Level.FINE)) @@ -162,7 +198,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl media = new AMedia(getTitle(), "pdf", "application/pdf", file, true); - } else if ("HTML".equals(previewType.getSelectedItem().getValue())) { + } else if ("HTML".equals(reportType)) { String path = System.getProperty("java.io.tmpdir"); String prefix = makePrefix(jasperPrint.getName()); if (log.isLoggable(Level.FINE)) @@ -181,7 +217,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+"/images/report/"); exporter.exportReport(); media = new AMedia(getTitle(), "html", "text/html", file, false); - } else if ("XLS".equals(previewType.getSelectedItem().getValue())) { + } else if ("XLS".equals(reportType)) { String path = System.getProperty("java.io.tmpdir"); String prefix = makePrefix(jasperPrint.getName()); if (log.isLoggable(Level.FINE)) @@ -199,7 +235,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl exporterXLS.exportReport(); media = new AMedia(getTitle(), "xls", "application/vnd.ms-excel", file, true); - }else if ("CSV".equals(previewType.getSelectedItem().getValue())) { + }else if ("CSV".equals(reportType)) { String path = System.getProperty("java.io.tmpdir"); String prefix = makePrefix(jasperPrint.getName()); if (log.isLoggable(Level.FINE))