Fixes issue 22522: In P&E unselected records remain unselected after sorting
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 28 Jan 2013 12:20:13 +0100
changeset 19481 cc72a8879a12
parent 19480 c915c82a2e1d
child 19482 06da080dd39f
Fixes issue 22522: In P&E unselected records remain unselected after sorting

Before this fix, if a record was originally selected when a P&E window was opened, if it was deselected and a column sorted, the record was marked as selected again. This has been achieved by keeping a list that contains all the deselected records. When the data is reloaded, it a record is present in this list, it will not be marked as selected.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Mon Jan 28 11:44:47 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Mon Jan 28 12:20:13 2013 +0100
@@ -65,6 +65,7 @@
         theGrid;
 
     this.selectedIds = [];
+    this.deselectedIds = [];
 
     // the origSetValuesAsCriteria member is added as 'class' level
     // we only need to do it once
@@ -191,12 +192,31 @@
   },
 
   selectionUpdated: function (record, recordList) {
-    var i, len = recordList.length;
+    var i, j, len = recordList.length,
+        prevSelectedLen = this.selectedIds.length,
+        recordId, found;
+
+    // Look for deselected records (records in selectedIds not present in recordList)
+    for (i = 0; i < prevSelectedLen; i++) {
+      recordId = this.selectedIds[i];
+      found = false;
+      for (j = 0; j < len; j++) {
+        if (recordId === recordList[j].id) {
+          found = true;
+          break;
+        }
+      }
+      if (!found) {
+        this.deselectedIds.push(recordId);
+      }
+    }
 
     this.selectedIds = [];
 
     for (i = 0; i < len; i++) {
       this.selectedIds.push(recordList[i].id);
+      // Remove the record from deselectedIds
+      this.deselectedIds.remove(recordList[i].id);
     }
     // refresh it all as multiple lines can be selected
     this.markForRedraw('Selection changed');
@@ -260,15 +280,24 @@
   },
 
   dataArrived: function (startRow, endRow) {
-    var record, i, allRows, len = this.selectedIds.length;
-    for (i = 0; i < len; i++) {
+    var record, i, allRows, selectedLen = this.selectedIds.length,
+        len;
+    for (i = 0; i < selectedLen; i++) {
       record = this.data.findByKey(this.selectedIds[i]);
       if (record) {
         record[this.selectionProperty] = true;
       }
     }
 
-    if (len === 0) {
+    len = this.deselectedIds.length;
+    for (i = 0; i < len; i++) {
+      record = this.data.findByKey(this.deselectedIds[i]);
+      if (record) {
+        record[this.selectionProperty] = false;
+      }
+    }
+
+    if (selectedLen === 0) {
       // push all *selected* rows into selectedIds cache
       allRows = this.data.allRows || [];
       len = allRows.length;