From 716f1d006664d15ca8ab889944bb82bc7339a82e Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 30 Aug 2013 17:03:11 -0500 Subject: [PATCH] IDEMPIERE-1315 Hide/Disable ActiveWorkflow and Personal Lock buttons --- .../src/org/compiere/model/GridFieldVO.java | 2 +- .../src/org/compiere/model/GridTabVO.java | 2 +- .../src/org/compiere/model/MRole.java | 21 ++++++++++- .../webui/adwindow/ADWindowToolbar.java | 36 ++++++++++++++----- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/GridFieldVO.java b/org.adempiere.base/src/org/compiere/model/GridFieldVO.java index fd909f9773..bf8b388285 100644 --- a/org.adempiere.base/src/org/compiere/model/GridFieldVO.java +++ b/org.adempiere.base/src/org/compiere/model/GridFieldVO.java @@ -56,7 +56,7 @@ public class GridFieldVO implements Serializable public static String getSQL (Properties ctx) { // IsActive is part of View - MRole role = MRole.getDefault(ctx, true); + MRole role = MRole.getDefault(ctx, false); String advancedFilter=" AND IsAdvancedField='N' "; StringBuilder sql; if (!Env.isBaseLanguage(ctx, "AD_Tab")){ diff --git a/org.adempiere.base/src/org/compiere/model/GridTabVO.java b/org.adempiere.base/src/org/compiere/model/GridTabVO.java index e0af3bf447..3c418cb7df 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTabVO.java +++ b/org.adempiere.base/src/org/compiere/model/GridTabVO.java @@ -370,7 +370,7 @@ public class GridTabVO implements Evaluatee, Serializable + " AND ce.AD_Field_ID IS NULL " + " AND ce.ASP_Status = 'H')"; // Hide // View only returns IsActive='Y' - MRole role = MRole.getDefault(ctx, true); + MRole role = MRole.getDefault(ctx, false); String advancedFilter=" AND IsAdvancedTab='N' "; StringBuilder sql; if (!Env.isBaseLanguage(ctx, "AD_Window")) { diff --git a/org.adempiere.base/src/org/compiere/model/MRole.java b/org.adempiere.base/src/org/compiere/model/MRole.java index 63af3a9913..93a8ee1f4d 100644 --- a/org.adempiere.base/src/org/compiere/model/MRole.java +++ b/org.adempiere.base/src/org/compiere/model/MRole.java @@ -61,7 +61,7 @@ public final class MRole extends X_AD_Role /** * */ - private static final long serialVersionUID = -1135628544466487086L; + private static final long serialVersionUID = 3608297024439006903L; /** * Get Default (Client) Role @@ -3148,4 +3148,23 @@ public final class MRole extends X_AD_Role return retValue; } + private Boolean m_canAccess_Info_Product = null; + + public boolean canAccess_Info_Product() { + if (m_canAccess_Info_Product == null) { + String sql = "" + + "SELECT COUNT(*) " + + "FROM AD_InfoWindow iw " + + " JOIN AD_InfoWindow_Access iwa " + + " ON ( iwa.AD_InfoWindow_ID = iw.AD_InfoWindow_ID ) " + + "WHERE AD_Table_ID = ? " + + " AND iw.IsActive = 'Y' " + + " AND iwa.IsActive = 'Y' " + + " AND iwa.AD_Role_ID = ?"; + int cnt = DB.getSQLValueEx(null, sql, I_M_Product.Table_ID, getAD_Role_ID()); + m_canAccess_Info_Product = new Boolean(cnt > 0); + } + return m_canAccess_Info_Product.booleanValue(); + } + } // MRole diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java index 765ddd3ec0..4ce1d8fc46 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java @@ -39,6 +39,7 @@ import org.compiere.model.GridTab; import org.compiere.model.MRole; import org.compiere.model.MToolBarButton; import org.compiere.util.CLogger; +import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Util; @@ -68,9 +69,9 @@ import org.zkoss.zul.Toolbarbutton; public class ADWindowToolbar extends FToolbar implements EventListener { /** - * + * */ - private static final long serialVersionUID = 3390505814516682801L; + private static final long serialVersionUID = -367141745573893540L; public static final String BTNPREFIX = "Btn"; @@ -118,7 +119,7 @@ public class ADWindowToolbar extends FToolbar implements EventListener // Elaine 2008/12/04 /** Show Personal Lock */ public boolean isPersonalLock = MRole.getDefault().isPersonalLock(); - private boolean isAllowProductInfo = MRole.getDefault().isAllow_Info_Product(); + private boolean isAllowProductInfo = MRole.getDefault().canAccess_Info_Product(); private int windowNo = 0; @@ -176,13 +177,19 @@ public class ADWindowToolbar extends FToolbar implements EventListener btnArchive = createButton("Archive", "Archive", "Archive"); btnPrint = createButton("Print", "Print", "Print"); btnPrint.setTooltiptext(btnPrint.getTooltiptext()+ " Alt+P"); - btnLock = createButton("Lock", "Lock", "Lock"); // Elaine 2008/12/04 - btnLock.setVisible(isPersonalLock); + if (isPersonalLock) { + btnLock = createButton("Lock", "Lock", "Lock"); // Elaine 2008/12/04 + btnLock.setDisabled(!isPersonalLock); // Elaine 2008/12/04 + btnLock.setVisible(isPersonalLock); + } btnZoomAcross = createButton("ZoomAcross", "ZoomAcross", "ZoomAcross"); btnActiveWorkflows = createButton("ActiveWorkflows", "WorkFlow", "WorkFlow"); btnRequests = createButton("Requests", "Request", "Request"); - btnProductInfo = createButton("ProductInfo", "Product", "InfoProduct"); - btnProductInfo.setVisible(isAllowProductInfo); + if (isAllowProductInfo) { + btnProductInfo = createButton("ProductInfo", "Product", "InfoProduct"); + btnProductInfo.setDisabled(!isAllowProductInfo); // Elaine 2008/07/22 + btnProductInfo.setVisible(isAllowProductInfo); + } btnCustomize= createButton("Customize", "Customize", "Customize"); btnCustomize.setDisabled(false); @@ -199,9 +206,7 @@ public class ADWindowToolbar extends FToolbar implements EventListener btnActiveWorkflows.setDisabled(false); // Elaine 2008/07/17 btnRequests.setDisabled(false); // Elaine 2008/07/22 - btnProductInfo.setDisabled(!isAllowProductInfo); // Elaine 2008/07/22 btnArchive.setDisabled(false); // Elaine 2008/07/28 - btnLock.setDisabled(!isPersonalLock); // Elaine 2008/12/04 if (MRole.getDefault().isCanExport()) { @@ -594,9 +599,22 @@ public class ADWindowToolbar extends FToolbar implements EventListener } // All restrictions dynamicDisplay(); + // If no workflow set for the table => disable btnWorkflow + if (!btnActiveWorkflows.isDisabled()) { + GridTab gridTab = adwindow.getADWindowContent().getActiveGridTab(); + if (gridTab != null) + btnActiveWorkflows.setDisabled(!hasWorkflow(gridTab)); + } ToolBarMenuRestictionLoaded = true; } + /** btnActiveWorkflow should be disabled when table has not workflow defined */ + boolean hasWorkflow(GridTab gridTab) + { + String sql = "SELECT COUNT(*) FROM AD_Workflow WHERE IsActive='Y' AND AD_Table_ID=? AND AD_Client_ID IN (0,?)"; + return (DB.getSQLValueEx(null, sql, gridTab.getAD_Table_ID(), Env.getAD_Client_ID(Env.getCtx())) > 0); + } + private void loadCustomButton(int AD_Window_ID) { MToolBarButton[] mToolbarButtons = MToolBarButton.getOfWindow(AD_Window_ID, null); if (mToolbarButtons != null && mToolbarButtons.length > 0) {