Fixes issue 21437: Recently added rows are visible after implicit refresh
authorAugusto Mauch <augusto.mauch@openbravo.com>
Tue, 11 Sep 2012 11:37:19 +0200
changeset 17920 7b629f7cbfe3
parent 17919 abef368d5c44
child 17921 f9fb375f5e05
Fixes issue 21437: Recently added rows are visible after implicit refresh

Now, after returning from a process, not only the current record will be shown in the grid, but also all the records that have been added in that view after th
e last explicit refresh.
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
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Tue Sep 11 09:32:37 2012 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Tue Sep 11 11:37:19 2012 +0200
@@ -279,19 +279,24 @@
     // issue 20722 (https://issues.openbravo.com/view.php?id=20722), remove the criteria
     // that makes reference to a specific id and return the original one
     removeSpecificIdFilter: function (criteria) {
+      var i, length;
       if (!criteria) {
         return criteria;
       }
       if (criteria.operator !== 'or') {
         return criteria;
       }
-      if (criteria.criteria && criteria.criteria.length !== 2) {
+      if (criteria.criteria && criteria.criteria.length < 2) {
         return criteria;
       }
-      if (criteria.criteria.get(0).fieldName !== 'id') {
-        return criteria;
+      // The original criteria is in the position 0, the rest are specific ids
+      length = criteria.criteria.length;
+      for (i = 1; i < length; i++) {
+        if (criteria.criteria.get(i).fieldName !== 'id') {
+          return criteria;
+        }
       }
-      return criteria.criteria.get(1);
+      return criteria.criteria.get(0);
     },
 
     // repair that filter criteria on fk fields can be 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Tue Sep 11 09:32:37 2012 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Tue Sep 11 11:37:19 2012 +0200
@@ -1013,13 +1013,14 @@
   },
 
   removeOrClause: function (criteria) {
-    // The original criteria is stored in the position #1
-    // The criteria to select the selected record is stored in position #0
-    return criteria.criteria.get(1);
+    // The original criteria is stored in the position #0
+    // The criteria to select the recently created records is stored in position #1..length-1
+    return criteria.criteria.get(0);
   },
 
-  refreshGrid: function (callback, forceCurrentRecordID) {
-    var originalCriteria, criteria = {};
+  refreshGrid: function (callback, newRecordsToBeIncluded) {
+    var originalCriteria, criteria = {},
+        newRecordsCriteria, newRecordsLength, i;
     if (this.getSelectedRecord()) {
       this.targetRecordId = this.getSelectedRecord()[OB.Constants.ID];
       // as the record is already selected it is already in the filter
@@ -1043,18 +1044,24 @@
     // If a record has to be included in the refresh, it must be included
     // in the filter with an 'or' operator, along with the original filter,
     // but only if there is an original filter
-    if (forceCurrentRecordID && originalCriteria.criteria.length > 0) {
+    if (newRecordsToBeIncluded && originalCriteria.criteria.length > 0) {
       // Adds the current record to the criteria
+      newRecordsCriteria = [];
+      newRecordsLength = newRecordsToBeIncluded.length;
+      for (i = 0; i < newRecordsLength; i++) {
+        newRecordsCriteria.push({
+          fieldName: 'id',
+          operator: 'equals',
+          value: newRecordsToBeIncluded[i]
+        });
+      }
+
+
       this._criteriaWithOrClause = true;
       criteria._constructor = 'AdvancedCriteria';
       criteria._OrExpression = true; // trick to get a really _or_ in the backend
       criteria.operator = 'or';
-      criteria.criteria = [{
-        fieldName: 'id',
-        operator: 'equals',
-        value: forceCurrentRecordID
-      }];
-      criteria.criteria.push(originalCriteria); // original filter
+      criteria.criteria = [originalCriteria].concat(newRecordsCriteria);
     } else {
       criteria = originalCriteria;
     }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Tue Sep 11 09:32:37 2012 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Tue Sep 11 11:37:19 2012 +0200
@@ -1384,9 +1384,9 @@
   // - refresh the current selected record without changing the selection
   // - refresh the parent/grand-parent in the same way without changing the selection
   // - recursive to children: refresh the children, put the children in grid mode and refresh
-  refresh: function (refreshCallback, autoSaveDone, forceCurrentRecordId) {
+  refresh: function (refreshCallback, autoSaveDone, newRecordsToBeIncluded) {
     // If a record should be visible after the refresh, even if it does not comply with the
-    // current filter, its ID should be entered in the forceCurrentRecordId parameter
+    // current filter, its ID should be entered in the newRecordsToBeIncluded parameter
     // See issue https://issues.openbravo.com/view.php?id=20722
     var me = this,
         view = this,
@@ -1397,7 +1397,7 @@
       actionObject = {
         target: this,
         method: this.refresh,
-        parameters: [refreshCallback, true, forceCurrentRecordId]
+        parameters: [refreshCallback, true, newRecordsToBeIncluded]
       };
       this.standardWindow.doActionAfterAutoSave(actionObject, false);
       return;
@@ -1414,18 +1414,21 @@
       me.viewForm.refresh();
     };
 
+    if (!newRecordsToBeIncluded) {
+      this.newRecordsAfterRefresh = [];
+    }
     if (!this.isShowingForm) {
-      this.viewGrid.refreshGrid(refreshCallback, forceCurrentRecordId);
+      this.viewGrid.refreshGrid(refreshCallback, newRecordsToBeIncluded);
     } else {
       if (this.viewForm.hasChanged) {
         callback = function (ok) {
           if (ok) {
-            view.viewGrid.refreshGrid(formRefresh, forceCurrentRecordId);
+            view.viewGrid.refreshGrid(formRefresh, newRecordsToBeIncluded);
           }
         };
         isc.ask(OB.I18N.getLabel('OBUIAPP_ConfirmRefresh'), callback);
       } else {
-        this.viewGrid.refreshGrid(formRefresh, forceCurrentRecordId);
+        this.viewGrid.refreshGrid(formRefresh, newRecordsToBeIncluded);
       }
     }
   },
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js	Tue Sep 11 09:32:37 2012 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js	Tue Sep 11 11:37:19 2012 +0200
@@ -162,10 +162,7 @@
         // The selected record should be shown after the refresh, even
         // if the filter would exclude it
         // See issue https://issues.openbravo.com/view.php?id=20722
-        if (currentView.viewGrid.getSelectedRecord()) {
-          currentRecordId = currentView.viewGrid.getSelectedRecord()[OB.Constants.ID];
-        }
-        currentView.refresh(null, autosaveDone, currentRecordId);
+        currentView.refresh(null, autosaveDone, currentView.newRecordsAfterRefresh);
       }
     };