Fixed issue 26198:Display logics based on preferences are not working properly
authorGuillermo Gil <guillermo.gil@openbravo.com>
Wed, 16 Apr 2014 13:12:00 +0200
changeset 22926 8698d60bb9cf
parent 22925 1e34d41332ca
child 22927 426835c75f78
Fixed issue 26198:Display logics based on preferences are not working properly
>
> SessionAttributesNames are now brought in the view and its values are set dinamically
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl	Wed Apr 16 12:18:32 2014 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl	Wed Apr 16 13:12:00 2014 +0200
@@ -12,7 +12,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-2013 Openbravo SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -40,8 +40,8 @@
                 },
     </#if>
 
-     <#if tabComponent.preferenceAttributes != "" >
-        sessionAttributes: ${tabComponent.preferenceAttributes},
+     <#if tabComponent.preferenceAttributesNames != "" >
+        sessionAttributesNames: [${tabComponent.preferenceAttributesNames}],
     </#if>
 
     <#if tabComponent.defaultEditMode>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Wed Apr 16 12:18:32 2014 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Wed Apr 16 13:12:00 2014 +0200
@@ -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-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU 
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -647,6 +647,23 @@
     return preferenceAttributes;
   }
 
+  // Returns the preference's names as a string
+  public String getPreferenceAttributesNames() {
+    boolean first = true;
+    String preferenceAttributes = "";
+    if (!preferenceAttributesMap.isEmpty()) {
+      for (String attr : preferenceAttributesMap.keySet()) {
+        if (!first) {
+          preferenceAttributes = preferenceAttributes.concat(",");
+        } else {
+          first = false;
+        }
+        preferenceAttributes = preferenceAttributes.concat("'" + attr + "'");
+      }
+    }
+    return preferenceAttributes;
+  }
+
   // Return the list of fields of these tab that are part of the display logic of its subtabs
   public List<String> getDisplayLogicFields() {
     boolean getOnlyFirstLevelSubTabs = false;
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Wed Apr 16 12:18:32 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Wed Apr 16 13:12:00 2014 +0200
@@ -233,8 +233,11 @@
     // If the tab comes with session attributes (preference attributes used in the display
     // logic of the tab, see issue https://issues.openbravo.com/view.php?id=5202), assign them
     // to the form, so they will be retrieved when getContextInfo() is called for the form
-    if (this.sessionAttributes) {
-      this.viewForm.sessionAttributes = this.sessionAttributes;
+    if (this.sessionAttributesNames) {
+      this.viewForm.sessionAttributes = {};
+      for (i = 0; i < this.sessionAttributesNames.length; i++) {
+        this.viewForm.sessionAttributes[this.sessionAttributesNames[i]] = OB.PropertyStore.get(this.sessionAttributesNames[i], this.standardWindow.windowId);
+      }
     }
 
     if (this.actionToolbarButtons) {
@@ -1489,9 +1492,9 @@
     if (this.viewForm && this.viewForm.auxInputs) {
       auxInputs = this.viewForm.auxInputs;
     }
-    for (p in childView.sessionAttributes) {
-      if (childView.sessionAttributes.hasOwnProperty(p) && !auxInputs.hasOwnProperty(p)) {
-        contextInfo[p] = childView.sessionAttributes[p];
+    for (p in childView.viewForm.sessionAttributes) {
+      if (childView.viewForm.sessionAttributes.hasOwnProperty(p) && !auxInputs.hasOwnProperty(p)) {
+        contextInfo[p] = childView.viewForm.sessionAttributes[p];
       }
     }
   },