details:   /erp/devel/pi/rev/41bdbdef85ec
changeset: 9197:41bdbdef85ec
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Dec 16 11:19:13 2010 +0100
summary:   Changed date handling in FIC and form

details:   /erp/devel/pi/rev/52005754cb79
changeset: 9198:52005754cb79
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Dec 16 11:19:38 2010 +0100
summary:   Changed date handling in FIC and form

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
 |   4 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
                      |  64 +++++----
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
               |   2 +
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
                   |  30 ++++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
                       |  22 ++-
 5 files changed, 85 insertions(+), 37 deletions(-)

diffs (257 lines):

diff -r 1d928ae48ca2 -r 52005754cb79 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
     Thu Dec 16 11:17:50 2010 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
     Thu Dec 16 11:19:38 2010 +0100
@@ -106,7 +106,9 @@
       }
       JSONObject jsContent = null;
       try {
-        if (content != null) {
+        if (content == null) {
+          jsContent = new JSONObject();
+        } else {
           jsContent = new JSONObject(content);
         }
       } catch (JSONException e) {
diff -r 1d928ae48ca2 -r 52005754cb79 
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 Dec 16 11:17:50 2010 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
  Thu Dec 16 11:19:38 2010 +0100
@@ -31,29 +31,29 @@
   view: null,
   numCols: 4,
   
-  fieldsByInpColumnName: null,  
+  fieldsByInpColumnName: null,
   fieldsByColumnName: null,
   
   initWidget: function(){
     // iterate over the fields and set the datasource
-//    var field, i, fieldsNum = this.fields.length;
-//    for (i = 0; i < fieldsNum; i++) {
-//      field = this.fields[i];
-//      if (field.dataSourceId) {
-        // field.optionDataSource = OB.Datasource.get(field.dataSourceId, 
field, 'optionDataSource');
-//      }
-//    }
+    //    var field, i, fieldsNum = this.fields.length;
+    //    for (i = 0; i < fieldsNum; i++) {
+    //      field = this.fields[i];
+    //      if (field.dataSourceId) {
+    // field.optionDataSource = OB.Datasource.get(field.dataSourceId, field, 
'optionDataSource');
+    //      }
+    //    }
     var ret = this.Super('initWidget', arguments);
     return ret;
   },
   
-  editRecord: function (record) {
+  editRecord: function(record){
     var ret = this.Super("editRecord", arguments);
     this.retrieveInitialValues();
     return ret;
   },
   
-  getFieldFromInpColumnName: function(inpColumnName) {
+  getFieldFromInpColumnName: function(inpColumnName){
     if (!this.fieldsByInpColumnName) {
       var localResult = [], fields = this.getFields();
       for (var i = 0; i < fields.length; i++) {
@@ -64,7 +64,7 @@
     return this.fieldsByInpColumnName[inpColumnName.toLowerCase()];
   },
   
-  getFieldFromColumnName: function(columnName) {
+  getFieldFromColumnName: function(columnName){
     if (!this.fieldsByColumnName) {
       var localResult = [], fields = this.getFields();
       for (var i = 0; i < fields.length; i++) {
@@ -75,32 +75,29 @@
     return this.fieldsByColumnName[columnName.toLowerCase()];
   },
   
-  setFields: function() {
+  setFields: function(){
     this.Super('setFields', arguments);
     this.fieldsByInpColumnName = null;
     this.fieldsByColumnName = null;
   },
   
-  retrieveInitialValues: function() {
+  retrieveInitialValues: function(){
     var parentId = null, me = this;
     if (this.view.parentProperty) {
       parentId = this.getValue(this.view.parentProperty);
     }
-     
OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent',
 null, {
-        MODE: 'EDIT',
-        PARENT_ID: parentId,
-        TAB_ID: this.view.tabId,
-        ROW_ID: this.getValue(OB.Constants.ID)
-      }, function(response, data, request){
-        me.processInitialValues(response, data, request);
-      });
+    
OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent',
 null, {
+      MODE: 'EDIT',
+      PARENT_ID: parentId,
+      TAB_ID: this.view.tabId,
+      ROW_ID: this.getValue(OB.Constants.ID)
+    }, function(response, data, request){
+      me.processInitialValues(response, data, request);
+    });
   },
   
-  processInitialValues: function(response, data, request) {
-    var columnValues = data.columnValues, 
-    calloutMessages = data.calloutMessages,
-    auxInputs = data.auxiliaryInputValues, 
-    prop, value;
+  processInitialValues: function(response, data, request){
+    var columnValues = data.columnValues, calloutMessages = 
data.calloutMessages, auxInputs = data.auxiliaryInputValues, prop, value;
     if (columnValues) {
       for (prop in columnValues) {
         if (columnValues.hasOwnProperty(prop)) {
@@ -116,8 +113,8 @@
     }
   },
   
-  processColumnValue: function(columnName, columnValue) {
-    var i, valueMap = {}, field = this.getFieldFromColumnName(columnName), 
entries = columnValue.entries;
+  processColumnValue: function(columnName, columnValue){
+    var isDate, i, valueMap = {}, field = 
this.getFieldFromColumnName(columnName), entries = columnValue.entries;
     if (!field) {
       // ignore for now, the pk is also passed in
       //isc.warn('No field found using column name: ' + columnName + ' for tab 
' + this.view.tabId);
@@ -134,7 +131,16 @@
       }
     }
     if (columnValue.value) {
-      this.setValue(field.name, columnValue.value);
+      isDate = field.type &&
+        (isc.SimpleType.getType(field.type).inheritsFrom === 'date' ||
+        isc.SimpleType.getType(field.type).inheritsFrom === 'datetime');
+      if (isDate) {
+        this.setValue(field.name, isc.Date.parseSchemaDate(columnValue.value));
+      } else {
+        this.setValue(field.name, columnValue.value);
+      }
+    } else {
+      this.clearValue(field.name);
     }
   }
 });
diff -r 1d928ae48ca2 -r 52005754cb79 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
   Thu Dec 16 11:17:50 2010 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
   Thu Dec 16 11:19:38 2010 +0100
@@ -18,6 +18,7 @@
  */
 package org.openbravo.client.kernel.reference;
 
+
 /**
  * Implementation of the date time ui definition.
  * 
@@ -39,4 +40,5 @@
   public String getFilterEditorType() {
     return "OBDateItem";
   }
+
 }
diff -r 1d928ae48ca2 -r 52005754cb79 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
       Thu Dec 16 11:17:50 2010 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
       Thu Dec 16 11:19:38 2010 +0100
@@ -18,6 +18,12 @@
  */
 package org.openbravo.client.kernel.reference;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.model.domaintype.PrimitiveDomainType;
+
 /**
  * Implementation of the date ui definition.
  * 
@@ -25,6 +31,17 @@
  */
 public class DateUIDefinition extends UIDefinition {
 
+  private static final String PATTERN = "yyyy-MM-dd HH:mm:ss";
+  private SimpleDateFormat format = null;
+
+  public SimpleDateFormat getFormat() {
+    if (format == null) {
+      format = new SimpleDateFormat(PATTERN);
+      format.setLenient(true);
+    }
+    return format;
+  }
+
   @Override
   public String getParentType() {
     return "date";
@@ -36,6 +53,19 @@
   }
 
   @Override
+  protected synchronized Object createJsonValueFromClassicValueString(String 
value) {
+    try {
+      if (value == null || value.length() == 0) {
+        return null;
+      }
+      final Date date = getFormat().parse(value);
+      return ((PrimitiveDomainType) getDomainType()).convertToString(date);
+    } catch (Exception e) {
+      throw new OBException(e);
+    }
+  }
+
+  @Override
   public String getTypeProperties() {
     final StringBuilder sb = new StringBuilder();
     sb.append("shortDisplayFormatter: function(value, field, component, 
record) {"
diff -r 1d928ae48ca2 -r 52005754cb79 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
   Thu Dec 16 11:17:50 2010 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
   Thu Dec 16 11:19:38 2010 +0100
@@ -186,12 +186,7 @@
     }
     JSONObject jsnobject = new JSONObject();
     try {
-      if (getDomainType() instanceof PrimitiveDomainType) {
-        jsnobject.put("value", ((PrimitiveDomainType) getDomainType())
-            .createFromString(columnValue));
-      } else {
-        jsnobject.put("value", columnValue);
-      }
+      jsnobject.put("value", 
createJsonValueFromClassicValueString(columnValue));
     } catch (JSONException e) {
       log.error("Couldn't get field property value for column "
           + field.getColumn().getDBColumnName());
@@ -200,6 +195,19 @@
   }
 
   /**
+   * Convert a string value as used in classic OB to a type safe value.
+   * 
+   * @see PrimitiveDomainType#createFromString(String)
+   */
+  protected Object createJsonValueFromClassicValueString(String value) {
+    if (getDomainType() instanceof PrimitiveDomainType) {
+      return ((PrimitiveDomainType) getDomainType()).createFromString(value);
+    } else {
+      return value;
+    }
+  }
+
+  /**
    * Computes properties to initialize and set the field in a Smartclient grid 
filter. This can be
    * the default value or the sets of values in the valuemap.
    * 
@@ -317,7 +325,7 @@
       if 
(field.getColumn().getDBColumnName().equalsIgnoreCase("AD_CLIENT_ID")) {
         clientList = Utility.getContext(new DalConnectionProvider(false), 
vars, "#User_Client",
             field.getTab().getWindow().getId(), (int) 
field.getTab().getTabLevel().longValue());
-        // clientList = vars.getSessionValue("#User_Client");
+        clientList = vars.getSessionValue("#User_Client");
         orgList = null;
       }
       if (field.getColumn().getDBColumnName().equalsIgnoreCase("AD_ORG_ID")) {

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to