details:   https://code.openbravo.com/erp/devel/pi/rev/b71f486b4915
changeset: 25769:b71f486b4915
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Jan 28 17:29:42 2015 +0100
summary:   fixed bug 28779: value of combo not displayed after setting it with 
a trigger

  When creating/refreshing a record, if the value of a FK drop down (table, 
tableDir
  and selector references) is changed in the backed (ie. through a trigger) and 
that
  drop down was not previously opened the value was seen as empty. The problem 
was
  the actual value was set but not is identifier in the valueMap.

  The fix handles this case on the dataSource reponse. It adds the new values 
to the
  valueMap if it is not present.

  setEntries method has been moved from OBFKComboItem to OBSelectorItem to 
handle it
  both for selectors and table/tableDir references.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view-datasource.js
 |  25 +++-
 
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-formitem-fk-combo.js
     |  39 +------
 
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
         |  63 +++++++++-
 3 files changed, 85 insertions(+), 42 deletions(-)

diffs (186 lines):

diff -r 2ab32dc8dcea -r b71f486b4915 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view-datasource.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view-datasource.js
      Wed Jan 28 09:31:53 2015 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view-datasource.js
      Wed Jan 28 17:29:42 2015 +0100
@@ -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) 2011-2013 Openbravo SLU
+ * All portions are Copyright (C) 2011-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -204,6 +204,7 @@
   },
 
   transformResponse: function (dsResponse, dsRequest, jsonData) {
+    var fields, i, field, record;
 
     if (dsRequest.clientContext) {
       
this.hideProgress(dsRequest.clientContext.progressIndicatorSelectedRecord);
@@ -218,9 +219,27 @@
         }
       } else {
         // there are some cases where the jsonData is not passed, in case of
-        // errors
-        // make it available through the response object
+        // errors make it available through the response object
         dsResponse.dataObject = jsonData;
+
+        if ((dsRequest.operationType === 'update' || dsRequest.operationType 
=== 'add') && this.view.viewForm && jsonData.response && jsonData.response.data 
&& jsonData.response.data.length === 1) {
+          // adding or updating a single record: at this point it is possible 
valueMap for
+          // some fields not to contain current entry, let's add it now so it 
is properly
+          // displayed
+          fields = this.view.viewForm.getFields();
+          for (i = 0; i < fields.length; i++) {
+            field = fields[i];
+            record = jsonData.response.data[0];
+            if (field.addValueMapEntry && record[field.name] && 
record[field.name + OB.Constants.FIELDSEPARATOR + OB.Constants.IDENTIFIER]) {
+              field.addValueMapEntry(record[field.name], record[field.name + 
OB.Constants.FIELDSEPARATOR + OB.Constants.IDENTIFIER]);
+              if (field.invalidateLocalValueMapCache) {
+                // invalidate local cache to force request when the drop down 
is opened as
+                // current map might have now only actual value
+                field.invalidateLocalValueMapCache();
+              }
+            }
+          }
+        }
       }
     }
     return this.Super('transformResponse', arguments);
diff -r 2ab32dc8dcea -r b71f486b4915 
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-formitem-fk-combo.js
--- 
a/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-formitem-fk-combo.js
  Wed Jan 28 09:31:53 2015 +0100
+++ 
b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-formitem-fk-combo.js
  Wed Jan 28 17:29:42 2015 +0100
@@ -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) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -63,43 +63,6 @@
     }
   },
 
-  // all entries are set at once in client, this happens when a callout
-  // computes all possible values, from this point subsequent filtering
-  // requires to be done in local
-  setEntries: function (entries) {
-    var length = entries.length,
-        i, id, identifier, valueMap = {},
-        valueMapData = [];
-
-    if (!this.setValueMap) {
-      return;
-    }
-
-    for (i = 0; i < length; i++) {
-      id = entries[i][OB.Constants.ID] || '';
-      identifier = entries[i][OB.Constants.IDENTIFIER] || '';
-      valueMap[id] = identifier;
-
-      valueMapData.push({
-        _identifier: identifier,
-        id: id
-      });
-    }
-
-    this.wholeMapSet = true; // flag to use local filtering from now on
-    this.preventPickListRequest = true; // preventing 1st request triggered by 
setValueMap
-    this.setValueMap(valueMap);
-
-    if (this.pickList) {
-      // there is no a proper way of initializing local data, let's do it 
editing
-      // picklist.data properties
-      this.pickList.data.localData = valueMapData;
-      this.pickList.data.allRows = valueMapData;
-      this.pickList.data.allRowsCriteria = this.pickList.data.criteria;
-      this.pickList.data.cachedRows = valueMapData.length;
-    }
-  },
-
   // two special cases to take into account when filtering:
   //   1. preventPickListRequest flag is set when pick list creation is forced,
   //      by default this causes a DS request we want to prevent
diff -r 2ab32dc8dcea -r b71f486b4915 
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
      Wed Jan 28 09:31:53 2015 +0100
+++ 
b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
      Wed Jan 28 17:29:42 2015 +0100
@@ -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) 2011-2014 Openbravo SLU
+ * All portions are Copyright (C) 2011-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -500,6 +500,67 @@
     this.Super('hidePickListOnBlur', arguments);
   },
 
+  // adds a single entry to valueMap if it is not already present
+  addValueMapEntry: function (id, identifier) {
+    var i, entries = this.entries || [],
+        entry = {},
+        valueField = this.getValueFieldName(),
+        length = entries.length;
+    for (i = 0; i < length; i++) {
+      if (entries[i][valueField] === id) {
+        return;
+      }
+    }
+
+    // not found add/create a new one
+    entry[valueField] = id;
+
+    if (id && identifier) {
+      entry[OB.Constants.ID] = id;
+      entry[OB.Constants.IDENTIFIER] = identifier;
+    }
+
+    entries.push(entry);
+    this.setEntries(entries);
+  },
+
+  // all entries are set at once in client, this happens when a callout
+  // computes all possible values, from this point subsequent filtering
+  // requires to be done in local
+  setEntries: function (entries) {
+    var length = entries.length,
+        i, id, identifier, valueMap = {},
+        valueMapData = [];
+
+    if (!this.setValueMap) {
+      return;
+    }
+
+    for (i = 0; i < length; i++) {
+      id = entries[i][OB.Constants.ID] || '';
+      identifier = entries[i][OB.Constants.IDENTIFIER] || '';
+      valueMap[id] = identifier;
+
+      valueMapData.push({
+        _identifier: identifier,
+        id: id
+      });
+    }
+
+    this.wholeMapSet = true; // flag to use local filtering from now on
+    this.preventPickListRequest = true; // preventing 1st request triggered by 
setValueMap
+    this.setValueMap(valueMap);
+
+    if (this.pickList) {
+      // there is no a proper way of initializing local data, let's do it 
editing
+      // picklist.data properties
+      this.pickList.data.localData = valueMapData;
+      this.pickList.data.allRows = valueMapData;
+      this.pickList.data.allRowsCriteria = this.pickList.data.criteria;
+      this.pickList.data.cachedRows = valueMapData.length;
+    }
+  },
+
   setUpPickList: function (show, queueFetches, request) {
     this.pickListProperties.canResizeFields = true;
     // drawAllMaxCells is set to 0 to prevent extra reads of data

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to