Implemented client side of realtime classic mode for window logic
authorMartin Taal <martin.taal@openbravo.com>
Wed, 26 Jan 2011 09:55:31 +0100
changeset 10137 92b18c4a18e1
parent 10136 9b35aa971d72
child 10138 cc312a677f35
Implemented client side of realtime classic mode for window logic
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/MenuManager.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/WindowDefinitionComponent.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java	Wed Jan 26 09:54:36 2011 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java	Wed Jan 26 09:55:31 2011 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010 Openbravo SLU
+ * All portions are Copyright (C) 2010-2011 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -24,6 +24,7 @@
 
 import javax.enterprise.context.ApplicationScoped;
 
+import org.openbravo.client.application.window.WindowDefinitionComponent;
 import org.openbravo.client.kernel.BaseComponentProvider;
 import org.openbravo.client.kernel.Component;
 import org.openbravo.client.kernel.ComponentProvider;
@@ -46,7 +47,12 @@
    */
   @Override
   public Component getComponent(String componentId, Map<String, Object> parameters) {
-    if (componentId.equals(ApplicationConstants.MAIN_LAYOUT_ID)) {
+    if (componentId.equals(WindowDefinitionComponent.WINDOW_DEF_COMPONENT)) {
+      final WindowDefinitionComponent component = getComponent(WindowDefinitionComponent.class);
+      component.setId(WindowDefinitionComponent.WINDOW_DEF_COMPONENT);
+      component.setParameters(parameters);
+      return component;
+    } else if (componentId.equals(ApplicationConstants.MAIN_LAYOUT_ID)) {
       final MainLayoutComponent component = getComponent(MainLayoutComponent.class);
       component.setId(ApplicationConstants.MAIN_LAYOUT_ID);
       component.setParameters(parameters);
@@ -95,6 +101,9 @@
         .add(createDynamicResource("org.openbravo.client.kernel/"
             + ApplicationConstants.COMPONENT_TYPE + "/"
             + ApplicationConstants.PROPERTIES_COMPONENT_ID));
+    globalResources.add(createDynamicResource("org.openbravo.client.kernel/"
+        + ApplicationConstants.COMPONENT_TYPE + "/"
+        + WindowDefinitionComponent.WINDOW_DEF_COMPONENT));
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.application/js/ob-classic-window.js", false));
     globalResources.add(createStaticResource(
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java	Wed Jan 26 09:54:36 2011 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java	Wed Jan 26 09:55:31 2011 +0100
@@ -31,6 +31,7 @@
 import org.openbravo.model.ad.access.User;
 import org.openbravo.model.ad.access.UserRoles;
 import org.openbravo.model.ad.ui.Field;
+import org.openbravo.model.ad.ui.Window;
 
 /**
  * Utility class for common operations
@@ -41,6 +42,11 @@
 
   private static Logger log = Logger.getLogger(ApplicationUtils.class);
 
+  static boolean showWindowInClassicMode(Window window) {
+    // TODO: implement me
+    return false;
+  }
+
   public static boolean isClientAdmin() {
     return OBContext.getOBContext().getRole().isClientAdmin();
   }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/MenuManager.java	Wed Jan 26 09:54:36 2011 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/MenuManager.java	Wed Jan 26 09:55:31 2011 +0100
@@ -439,6 +439,7 @@
     private MenuOption parentMenuOption;
     private List<MenuOption> children = new ArrayList<MenuOption>();
     private Boolean visible = null;
+    private boolean showInClassicMode = false;
 
     public boolean isSingleRecord() {
       return getTab() != null && getTab().getUIPattern().equals("SR");
@@ -618,6 +619,7 @@
 
     public void setTab(Tab tab) {
       this.tab = tab;
+      showInClassicMode = ApplicationUtils.showWindowInClassicMode(tab.getWindow());
     }
 
     public List<MenuParameter> getParameters() {
@@ -629,6 +631,10 @@
       }
       return parameters;
     }
+
+    public boolean isShowInClassicMode() {
+      return showInClassicMode;
+    }
   }
 
   private static class MenuComparator implements Comparator<MenuOption> {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/WindowDefinitionComponent.java	Wed Jan 26 09:55:31 2011 +0100
@@ -0,0 +1,76 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.application.window;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.client.application.ApplicationComponentProvider;
+import org.openbravo.client.application.MenuManager;
+import org.openbravo.client.application.MenuManager.MenuOption;
+import org.openbravo.client.kernel.BaseComponent;
+import org.openbravo.dal.core.OBContext;
+
+/**
+ * A component which generates javascript directly without a template
+ * 
+ * @author mtaal
+ */
+@RequestScoped
+public class WindowDefinitionComponent extends BaseComponent {
+  public static final String WINDOW_DEF_COMPONENT = "WindowDefinitionComponent";
+
+  @Inject
+  private MenuManager menuManager;
+
+  @Override
+  public String generate() {
+    try {
+      final JSONObject result = new JSONObject();
+      for (MenuOption menuOption : menuManager.getSelectableMenuOptions()) {
+        if (menuOption.getTab() != null) {
+          final JSONObject windowDef = new JSONObject();
+          result.put(menuOption.getTab().getWindow().getId(), windowDef);
+          if (menuOption.isShowInClassicMode()) {
+            windowDef.put("showInClassicMode", true);
+          }
+        }
+      }
+      return "OB.WindowDefinitions = " + result.toString() + ";";
+    } catch (Exception e) {
+      throw new OBException(e);
+    }
+  }
+
+  @Override
+  public Object getData() {
+    return this;
+  }
+
+  protected String getModulePackageName() {
+    return ApplicationComponentProvider.class.getPackage().getName();
+  }
+
+  @Override
+  public String getETag() {
+    return super.getETag() + "_" + OBContext.getOBContext().getRole().getId();
+  }
+}
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Wed Jan 26 09:54:36 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Wed Jan 26 09:55:31 2011 +0100
@@ -30,6 +30,9 @@
   if (OB.Utilities.hasUrlParameter('mode', 'classic')) {
     return true;
   }
+  if (OB.WindowDefinitions[windowId] && OB.WindowDefinitions[windowId].showInClassicMode) {
+    return true;
+  }
   var propValue = OB.PropertyStore.get('OBUIAPP_UseClassicMode', windowId);
   if (propValue === 'Y') {
     return true;