Related to issue 26228: Date and datetime fields are shown properly in treeview
authorAugusto Mauch <augusto.mauch@openbravo.com>
Tue, 15 Apr 2014 18:59:23 +0200
changeset 22922 9f4a800d3f0a
parent 22921 e7bdfd86edfb
child 22923 c25c56618b6d
Related to issue 26228: Date and datetime fields are shown properly in treeview

If a date or datetime field was shown in the tree grid view, the record was shown properly. But if then the record was opened in form view, the value of its date and datetime fields was being deleted.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-tree-grid.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-tree-grid.js	Tue Apr 15 17:32:17 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-tree-grid.js	Tue Apr 15 18:59:23 2014 +0200
@@ -148,5 +148,29 @@
       value = Date.parseSchemaDate(value);
     }
     return this.Super('applyCellTypeFormatters', [value, record, field, rowNum, colNum, isMultipleElement]);
+  },
+
+  
+  // converts the date and datetime fields from string to a js date
+  transformData: function (data) {
+    var dateFields = [],
+        fieldName, i, j, type, record;
+    for (i = 0; i < this.getFields().length; i++) {
+      type = isc.SimpleType.getType(this.getFields()[i].type);
+      if (type.inheritsFrom === 'date' || type.inheritsFrom === 'datetime') {
+        dateFields.add(this.getFields()[i].name);
+      }
+    }
+    if (dateFields.length > 0) {
+      for (i = 0; i < data.length; i++) {
+        record = data[i];
+        for (j = 0; j < dateFields.length; j++) {
+          fieldName = dateFields[j];
+          if (!isc.isA.Date(record[fieldName]) && isc.isA.Date(isc.Date.parseSchemaDate(record[fieldName]))) {
+            record[fieldName] = isc.Date.parseSchemaDate(record[fieldName]);
+          }
+        }
+      }
+    }
   }
 });
\ No newline at end of file