Fixes issue 0026700: Wrong request after filtering in a field
authorShankar Balachandran <shankar.balachandran@openbravo.com>
Thu, 29 May 2014 09:51:07 +0530
changeset 23513 60c04ffe21c3
parent 23512 90c17ce2a4a8
child 23514 9acde5d913e7
Fixes issue 0026700: Wrong request after filtering in a field

obblur event, if more than one records were selected in filter, an additional request was being done.
Prevented the request in this case as the grid is already filtered.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Mon Jun 09 08:29:28 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Thu May 29 09:51:07 2014 +0530
@@ -152,6 +152,37 @@
     return this.Super('destroy', arguments);
   },
 
+  // When the selected value is part of the pickList the grid is already filtered,
+  // so no additional request is required. But when there is a keyword entered,
+  // the grid has to be filtered. Refer issue, https://issues.openbravo.com/view.php?id=26700.
+  handleEditorExit: function () {
+    var value = this.getValue(),
+        performFetch = false,
+        rows,i;
+    if (this.pickListProperties && this.pickList.data && (this.pickList.data.allRows || this.pickList.data.localData)) {
+      rows = this.pickList.data.allRows || this.pickList.data.localData;
+    }
+    if (value && isc.isA.Array(value) && value.length > 0 && rows) {
+      for (i = 0; i < value.length; i++) {
+        if (value[i].indexOf("==") === 0) {
+          value[i] = value[i].substring(2, value[i].length);
+          if (rows.find('name', value[i]) === undefined) {
+            performFetch = true;
+          }
+        }
+      }
+    } else {
+      if (rows && rows.find('name', value)) {
+        performFetch = true;
+      }
+    }
+    if (performFetch) {
+      this.Super('handleEditorExit', arguments);
+    } else {
+      return value;
+    }
+  },
+
   // note: can't override changed as it is used by the filter editor 
   // itself, see the RecordEditor source code and the changed event
   change: function (form, item, value, oldValue) {