Fixes issue 25811: No unneeded requests are done when the grid is refreshed
authorAugusto Mauch <augusto.mauch@openbravo.com>
Wed, 12 Nov 2014 15:14:42 +0100
changeset 25272 f62c66b02a9f
parent 25271 c3491ae284fe
child 25273 5827d159c89a
Fixes issue 25811: No unneeded requests are done when the grid is refreshed

This changesets handles the case when the grid is refreshed after having been scrolled down, without no records selected. When this happens, the refreshingWithScrolledGrid flag is set to true. This will be
used in the fetchRemoteData function to help prevent a grid redrawal that would result in an unneeded datasource request.

Also, all the flags used in this development are cleared in the callback of the filterData function done in OBViewGrid.refreshGrid.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Wed Nov 12 13:02:18 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Wed Nov 12 15:14:42 2014 +0100
@@ -1378,7 +1378,9 @@
     var newDrawArea, grid, drawArea, firstRecord, loading;
     // Dont redraw while the grid is being refreshed with a selected record to 
     // prevent unneeded requests. See issue https://issues.openbravo.com/view.php?id=25811
-    if (this.grid.refreshingWithSelectedRecord) {
+    // Also dont redraw if the user has refreshed after scrolling down if 
+    // a page other than the first one is going to be requested
+    if (this.grid.preventRedraw) {
       return;
     }
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Wed Nov 12 13:02:18 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Wed Nov 12 15:14:42 2014 +0100
@@ -211,6 +211,9 @@
         //  instead of using targetRecordId to improve the performance
         startRow = this.grid.selectedRecordInitInterval;
         endRow = this.grid.selectedRecordendInterval;
+        this.grid.preventRedraw = true;
+      } else if (this.grid.refreshingWithScrolledGrid && startRow > 0) {
+        this.grid.preventRedraw = true;
       }
       return this.Super('fetchRemoteData', arguments);
     },
@@ -1696,7 +1699,7 @@
 
   refreshGrid: function (callback, newRecordsToBeIncluded) {
     var originalCriteria, criteria = {},
-        newRecordsCriteria, newRecordsLength, i, index, selectedRecordIndex;
+        newRecordsCriteria, newRecordsLength, i, index, selectedRecordIndex, visibleRows, filterDataCallback, me = this;
 
     //check whether newRecordsToBeIncluded contains records not part of the current grid and remove them.
     if (newRecordsToBeIncluded && newRecordsToBeIncluded.length > 0 && this.data) {
@@ -1724,6 +1727,12 @@
         this.selectedRecordendInterval = this.selectedRecordInitInterval + this.data.resultSize;
       }
       this.notRemoveFilter = true;
+    } else {
+      visibleRows = this.getVisibleRows();
+      if (visibleRows && visibleRows[0] > 0) {
+        this.refreshingWithScrolledGrid = true;
+      }
+
     }
     this.actionAfterDataArrived = callback;
     this.invalidateCache();
@@ -1763,7 +1772,14 @@
     } else {
       criteria = originalCriteria;
     }
-    this.filterData(criteria, null, context);
+    filterDataCallback = function () {
+      delete me.refreshingWithScrolledGrid;
+      delete me.preventRedraw;
+      delete me.selectedRecordInitInterval;
+      delete me.selectedRecordendInterval;
+      delete me.selectedRecordId;
+    };
+    this.filterData(criteria, filterDataCallback, context);
     // At this point the original criteria should be restored, to prevent
     // the 'or' clause that was just added to be used in subsequent refreshes.
     // It is not possible to do it here, though, because a this.setCriteria(originalCriteria)