IDEMPIERE-970 Role with the can Export option deselected would actually be able to export / jasper

This commit is contained in:
Carlos Augusto Sanchez 2013-05-29 18:45:20 -05:00
parent dbeebf529f
commit 3a0d154c52
4 changed files with 66 additions and 11 deletions

View File

@ -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
;

View File

@ -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
;

View File

@ -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

View File

@ -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<Event>, 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<Event>, 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);
@ -73,10 +82,34 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
toolbar.setHeight("26px");
previewType.setMold("select");
previewType.appendItem("PDF", "PDF");
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);
@ -141,11 +174,14 @@ public class ZkJRViewer extends Window implements EventListener<Event>, 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<Event>, 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<Event>, 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<Event>, 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))