details:   /erp/devel/pi/rev/c1ca508f8ed3
changeset: 10504:c1ca508f8ed3
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Feb 10 04:51:17 2011 +0100
summary:   Added display/readonly logic to grid, handle updatable/readonly, 
solve many FIC calls by selector item

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
     |   1 +
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl
      |  17 ++
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFormComponent.java
    |  20 ++-
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java
    |  72 ++++++++++
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
                 |   4 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
                 |   1 +
 
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
     |   5 +-
 
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
 |   5 +
 8 files changed, 120 insertions(+), 5 deletions(-)

diffs (288 lines):

diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
      Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
      Thu Feb 10 04:51:17 2011 +0100
@@ -23,6 +23,7 @@
         title: '${fieldDefinition.label?js_string}',
         type: '${fieldDefinition.type}',
         disabled: ${fieldDefinition.readOnly?string},
+        updatable: ${fieldDefinition.updatable?string},
         parentProperty: ${fieldDefinition.parentProperty?string},
         colSpan: ${fieldDefinition.colSpan},
         rowSpan: ${fieldDefinition.rowSpan},
diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl
       Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl
       Thu Feb 10 04:51:17 2011 +0100
@@ -29,6 +29,23 @@
           , inpColumnName: '${field.inpColumnName?js_string}'
           , referencedKeyColumnName: 
'${field.referencedKeyColumnName?js_string}'        
           , targetEntity: '${field.targetEntity?js_string}'
+          , disabled: ${field.readOnly?string}
+          , updatable: ${field.updatable?string}
+          <#if field.redrawOnChange?string = "true" >
+          , redrawOnChange: true
+          , changed: function(form, item, value) {
+              this.Super('changed', arguments);
+              form.onFieldChanged(form, item, value);
+            }
+          </#if>
+          <#if field.showIf != "">
+          , showIf: function(item, value, form, currentValues) {
+              currentValues = currentValues || form.view.getCurrentValues();
+              var context = form.view.getContextInfo(false, true);
+              return context && (${field.showIf});
+            }
+          </#if>
+          
         }
         ${field.gridFieldProperties}
         ${field.filterEditorProperties}
diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFormComponent.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFormComponent.java
     Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFormComponent.java
     Thu Feb 10 04:51:17 2011 +0100
@@ -142,7 +142,7 @@
       final OBViewField viewField = new OBViewField();
       viewField.setField(field);
       viewField.setProperty(property);
-      viewField.setReadrawOnChange(fieldsInDynamicExpression.contains(field));
+      viewField.setRedrawOnChange(fieldsInDynamicExpression.contains(field));
       viewField.setShowIf(displayLogicMap.get(field) != null ? 
displayLogicMap.get(field) : "");
       viewField.setReadOnlyIf(readOnlyLogicMap.get(field) != null ? 
readOnlyLogicMap.get(field)
           : "");
@@ -217,6 +217,8 @@
 
     public boolean isReadOnly();
 
+    public boolean isUpdatable();
+
     public boolean isParentProperty();
 
     public boolean getRedrawOnChange();
@@ -237,7 +239,11 @@
     private String readOnlyIf = "";
 
     public boolean isReadOnly() {
-      return isParentProperty() || !property.isUpdatable();
+      return isParentProperty() || field.isReadOnly();
+    }
+
+    public boolean isUpdatable() {
+      return property.isUpdatable();
     }
 
     public boolean isParentProperty() {
@@ -380,7 +386,7 @@
       return field.isStartnewline();
     }
 
-    public void setReadrawOnChange(boolean redrawOnChange) {
+    public void setRedrawOnChange(boolean redrawOnChange) {
       this.redrawOnChange = redrawOnChange;
     }
 
@@ -415,6 +421,10 @@
       return false;
     }
 
+    public boolean isUpdatable() {
+      return true;
+    }
+
     public boolean isParentProperty() {
       return false;
     }
@@ -599,6 +609,10 @@
       return false;
     }
 
+    public boolean isUpdatable() {
+      return true;
+    }
+
     public boolean isParentProperty() {
       return false;
     }
diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java
     Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java
     Thu Feb 10 04:51:17 2011 +0100
@@ -21,12 +21,15 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.openbravo.base.model.Entity;
 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.kernel.BaseTemplateComponent;
 import org.openbravo.client.kernel.KernelUtils;
 import org.openbravo.client.kernel.Template;
@@ -55,6 +58,10 @@
   private Tab tab;
   private List<LocalField> fields = null;
 
+  private final List<Field> fieldsInDynamicExpression = new ArrayList<Field>();
+  private final Map<Field, String> displayLogicMap = new HashMap<Field, 
String>();
+  private final Map<Field, String> readOnlyLogicMap = new HashMap<Field, 
String>();
+
   protected Template getComponentTemplate() {
     return OBDal.getInstance().get(Template.class, TEMPLATE_ID);
   }
@@ -150,6 +157,42 @@
         fields.add(createLocalField(fld, prop, true));
       }
     }
+
+    // Processing dynamic expressions (display logic)
+    for (Field f : sortedFields) {
+      if (f.getDisplayLogic() == null || f.getDisplayLogic().equals("") || 
!f.isActive()
+          || !f.isDisplayed()) {
+        continue;
+      }
+
+      final DynamicExpressionParser parser = new 
DynamicExpressionParser(f.getDisplayLogic(), tab);
+      displayLogicMap.put(f, parser.getJSExpression());
+
+      for (Field fieldExpression : parser.getFields()) {
+        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
+          fieldsInDynamicExpression.add(fieldExpression);
+        }
+      }
+    }
+
+    // Processing dynamic expression (read-only logic)
+    for (Field f : sortedFields) {
+      if (f.getColumn().getReadOnlyLogic() == null || 
f.getColumn().getReadOnlyLogic().equals("")
+          || !f.isActive() || !f.getColumn().isActive()) {
+        continue;
+      }
+
+      final DynamicExpressionParser parser = new 
DynamicExpressionParser(f.getColumn()
+          .getReadOnlyLogic(), tab);
+      readOnlyLogicMap.put(f, parser.getJSExpression());
+
+      for (Field fieldExpression : parser.getFields()) {
+        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
+          fieldsInDynamicExpression.add(fieldExpression);
+        }
+      }
+    }
+
     // and add the non grid fields
     for (Field fld : sortedFields) {
       if (fld.isActive() && !fld.isShowInGridView()) {
@@ -185,6 +228,9 @@
     }
     localField.setTitle(OBViewUtil.getLabel(fld));
     localField.setInitialShow(showInitially);
+    localField.setRedrawOnChange(fieldsInDynamicExpression.contains(fld));
+    localField.setShowIf(displayLogicMap.get(fld) != null ? 
displayLogicMap.get(fld) : "");
+
     return localField;
   }
 
@@ -195,6 +241,8 @@
     private Property property;
     private UIDefinition uiDefinition;
     private boolean initialShow;
+    private String showIf;
+    private boolean redrawOnChange;
 
     public String getColumnName() {
       return property.getColumnName();
@@ -208,6 +256,14 @@
       return property.isMandatory();
     }
 
+    public boolean isReadOnly() {
+      return field.isReadOnly();
+    }
+
+    public boolean isUpdatable() {
+      return property.isUpdatable();
+    }
+
     public String getInpColumnName() {
       return "inp" + Sqlc.TransformaNombreColumna(property.getColumnName());
     }
@@ -320,6 +376,22 @@
     public void setInitialShow(boolean initialShow) {
       this.initialShow = initialShow;
     }
+
+    public String getShowIf() {
+      return showIf;
+    }
+
+    public void setShowIf(String showIf) {
+      this.showIf = showIf;
+    }
+
+    public boolean isRedrawOnChange() {
+      return redrawOnChange;
+    }
+
+    public void setRedrawOnChange(boolean redrawOnChange) {
+      this.redrawOnChange = redrawOnChange;
+    }
   }
 
   private class GridFieldComparator implements Comparator<Field> {
diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
  Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
  Thu Feb 10 04:51:17 2011 +0100
@@ -102,7 +102,9 @@
     
     this.setHasChanged(false);
 
-    this.setNewState(isNew);
+    // the new state can also be signaled through the record
+    // this is to edit new records which have been edited before
+    this.setNewState(isNew || this.getValue('_new'));
     
     // focus is done automatically, prevent the focus event if needed
     // the focus event will set the active view
diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
  Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
  Thu Feb 10 04:51:17 2011 +0100
@@ -265,6 +265,7 @@
     
     if (this.getField(this.view.parentProperty)) {
       this.getField(this.view.parentProperty).canFilter = false;
+      this.getField(this.view.parentProperty).canEdit = false;
     }
     
   },
diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
--- 
a/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
      Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
      Thu Feb 10 04:51:17 2011 +0100
@@ -312,7 +312,10 @@
   popupTextMatchStyle: 'startswith',
   suggestionTextMatchStyle: 'startswith',
   selectOnFocus: true,
-  
+  // setting this to false means that the change handler is called when picking
+  // a value and not earlier
+  addUnknownValues: false,
+
   // ** {{{ selectorGridFields }}} **
   // the definition of the columns in the popup window
   selectorGridFields: [{
diff -r ce6726829ab1 -r c1ca508f8ed3 
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
--- 
a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
  Thu Feb 10 03:51:49 2011 +0100
+++ 
b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
  Thu Feb 10 04:51:17 2011 +0100
@@ -78,6 +78,11 @@
   },
   
   isDisabled: function(){
+    // disabled if the property can not be updated and the form or record is 
new
+    // explicitly comparing with false as it is only set for edit form fields
+    if (this.updatable === false && !(this.form.isNew || 
this.form.getValue('_new'))) {
+      return true;
+    }
     return this.form.readOnly || this.disabled || this.form.allItemsDisabled;
   },
   

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to