details:   /erp/devel/pi/rev/0b2987c81e08
changeset: 9975:0b2987c81e08
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Jan 20 10:44:30 2011 +0100
summary:   [process] Display logic: currently only working in form view

details:   /erp/devel/pi/rev/93a706df814f
changeset: 9976:93a706df814f
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Jan 20 11:31:06 2011 +0100
summary:   [process] Prevent NPE if key column has not field

details:   /erp/devel/pi/rev/ea713e75b0e8
changeset: 9977:ea713e75b0e8
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Jan 20 11:31:26 2011 +0100
summary:   [process] Read only logic: currently only working in form view

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
 |  14 +-
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
        |  71 +++++++--
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
       |  17 ++-
 3 files changed, 80 insertions(+), 22 deletions(-)

diffs (201 lines):

diff -r 84093893978a -r ea713e75b0e8 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
        Thu Jan 20 10:27:26 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
        Thu Jan 20 11:31:26 2011 +0100
@@ -63,7 +63,19 @@
        labelValue: {<#list field.labelValues as value>
            '${value.value?js_string}': '${value.label?js_string}'<#if 
value_has_next>,</#if>
        </#list>
-         }
+         },
+       <#if field.showIf != "">
+       displayIf: function(item, value, form, values) {
+          var context = form.view.getContextInfo(false, true);
+          return context && (${field.showIf});
+       },
+       </#if>
+       <#if field.readOnlyIf != "">
+       readOnlyIf: function(item, value, form, values) {
+          var context = form.view.getContextInfo(false, true);
+          return context && (${field.readOnlyIf});
+       },
+       </#if>
       }<#if field_has_next>,</#if>
     </#list>],
     
diff -r 84093893978a -r ea713e75b0e8 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
       Thu Jan 20 10:27:26 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
       Thu Jan 20 11:31:26 2011 +0100
@@ -26,6 +26,7 @@
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
 import org.openbravo.client.application.ApplicationUtils;
+import org.openbravo.client.application.DynamicExpressionParser;
 import 
org.openbravo.client.application.window.OBViewFormComponent.FormFieldComparator;
 import org.openbravo.client.kernel.BaseTemplateComponent;
 import org.openbravo.client.kernel.KernelUtils;
@@ -62,6 +63,8 @@
   private List<IconButton> iconButtons = null;
   private Field keyField;
 
+  private Column keyColumn;
+
   protected Template getComponentTemplate() {
     return OBDal.getInstance().get(Template.class, TEMPLATE_ID);
   }
@@ -225,32 +228,35 @@
     }
 
     // Additional key column, set in session with db column name
-    if (keyField != null) {
-      FieldProperty fp = new FieldProperty(keyField);
-      fp.columnName = keyField.getColumn().getDBColumnName();
+    if (getKeyColumn() != null) {
+      FieldProperty fp = new FieldProperty(keyColumn);
+      fp.columnName = keyColumn.getDBColumnName();
       fp.session = true;
       fields.add(fp);
     }
 
-    // Standard hidden fields shown in all 2.50 windows
-    FieldProperty fp = new FieldProperty(keyField);
-    fp.columnName = keyField.getColumn().getDBColumnName();
-    fields.add(fp);
-
     return fields;
   }
 
-  private Field getKeyField() {
-    if (keyField != null) {
-      return keyField;
+  private Column getKeyColumn() {
+    if (keyColumn != null) {
+      return keyColumn;
     }
 
-    for (Field field : tab.getADFieldList()) {
-      if (field.getColumn().isKeyColumn()) {
-        keyField = field;
+    if (keyField != null) {
+      keyColumn = keyField.getColumn();
+    }
+
+    if (keyColumn == null) {
+      for (Column col : tab.getTable().getADColumnList()) {
+        if (col.isKeyColumn()) {
+          keyColumn = col;
+          break;
+        }
       }
     }
-    return keyField;
+
+    return keyColumn;
   }
 
   public String getTableId() {
@@ -258,11 +264,11 @@
   }
 
   public String getKeyColumnId() {
-    return getKeyField().getColumn().getDBColumnName();
+    return getKeyColumn().getDBColumnName();
   }
 
   public String getKeyName() {
-    return "inp" + 
Sqlc.TransformaNombreColumna(getKeyField().getColumn().getDBColumnName());
+    return "inp" + 
Sqlc.TransformaNombreColumna(getKeyColumn().getDBColumnName());
   }
 
   public String getWindowId() {
@@ -282,14 +288,17 @@
       dbColumnName = "";
     }
 
-    public FieldProperty(Field field) {
-      Column col = field.getColumn();
+    public FieldProperty(Column col) {
       columnName = "inp" + Sqlc.TransformaNombreColumna(col.getDBColumnName());
       dbColumnName = col.getDBColumnName();
       propertyName = 
KernelUtils.getInstance().getPropertyFromColumn(col).getName();
       session = col.isStoredInSession();
     }
 
+    public FieldProperty(Field field) {
+      this(field.getColumn());
+    }
+
     public String getColumnName() {
       return columnName;
     }
@@ -318,6 +327,8 @@
     private String propertyName;
     private List<Value> labelValues;
     private boolean autosave;
+    private String showIf = "";
+    private String readOnlyIf = "";
 
     public ButtonField(Field fld) {
       id = fld.getId();
@@ -367,6 +378,20 @@
           labelValues.add(new Value(valueList));
         }
       }
+
+      // Display Logic
+      if (fld.getDisplayLogic() != null) {
+        final DynamicExpressionParser parser = new 
DynamicExpressionParser(fld.getDisplayLogic(),
+            tab);
+        showIf = parser.getJSExpression();
+      }
+
+      // Read only logic
+      if (fld.getColumn().getReadOnlyLogic() != null) {
+        final DynamicExpressionParser parser = new 
DynamicExpressionParser(fld.getColumn()
+            .getReadOnlyLogic(), tab);
+        readOnlyIf = parser.getJSExpression();
+      }
     }
 
     public boolean isAutosave() {
@@ -415,6 +440,14 @@
       this.id = id;
     }
 
+    public String getShowIf() {
+      return showIf;
+    }
+
+    public String getReadOnlyIf() {
+      return readOnlyIf;
+    }
+
     public class Value {
       private String value;
       private String labelValue;
diff -r 84093893978a -r ea713e75b0e8 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
      Thu Jan 20 10:27:26 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
      Thu Jan 20 11:31:26 2011 +0100
@@ -118,8 +118,21 @@
       return;
     }
     
-    //TODO: implement display/read only logic
-    this.show();
+    this.visible = !this.displayIf || this.displayIf(null, null, 
this.view.viewForm);
+    
+    // Even visible is correctly set, it is necessary to execute show() or 
hide()
+    if (this.visible){
+      this.show();
+    } else {
+      this.hide();
+    }
+    
+    var readonly = this.readOnlyIf && this.readOnlyIf(null, null, 
this.view.viewForm);
+    if (readonly) {
+      this.disable();
+    } else {
+      this.enable();
+    }
     
     var label = this.labelValue[record[this.property]];
     if (!label){

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to