Fixes issue 21437: Recently added rows are visible after implicit refresh
authorAugusto Mauch <augusto.mauch@openbravo.com>
Thu, 13 Sep 2012 12:38:10 +0200
changeset 17935 e4be9ce5c5fa
parent 17934 c010adeccdd2
child 17936 3292566b5a1b
Fixes issue 21437: Recently added rows are visible after implicit refresh

The part of the fix where the ids of the rows that were added after the last refresh was missing, now it has been included, and works both while saving in the form as with saving in the grid view.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.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/form/ob-view-form.js	Wed Sep 12 20:39:59 2012 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Thu Sep 13 12:38:10 2012 +0200
@@ -1493,6 +1493,11 @@
           return;
         }
 
+        if (!view.newRecordsAfterRefresh) {
+          view.newRecordsAfterRefresh = [];
+        }
+        view.newRecordsAfterRefresh.push(data[OB.Constants.ID]);
+
         // do this after doing autoSave as the setHasChanged will clean
         // the autosave info
         form.setHasChanged(false);
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Wed Sep 12 20:39:59 2012 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Thu Sep 13 12:38:10 2012 +0200
@@ -1044,7 +1044,7 @@
     // 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 (newRecordsToBeIncluded && originalCriteria.criteria.length > 0) {
+    if (newRecordsToBeIncluded && newRecordsToBeIncluded.length > 0 && originalCriteria.criteria.length > 0) {
       // Adds the current record to the criteria
       newRecordsCriteria = [];
       newRecordsLength = newRecordsToBeIncluded.length;
@@ -2286,8 +2286,8 @@
   // latest values. This can happen when the focus is in a field and the save action is
   // done, at that point first try to force a fic call (handleItemChange) and if that
   // indeed happens stop the saveEdit until the fic returns
-  saveEditedValues: function (rowNum, colNum, newValues, oldValues, editValuesID, editCompletionEvent, saveCallback, ficCallDone) {
-    var previousExplicitOffline;
+  saveEditedValues: function (rowNum, colNum, newValues, oldValues, editValuesID, editCompletionEvent, originalCallback, ficCallDone) {
+    var previousExplicitOffline, saveCallback;
     if (!rowNum && rowNum !== 0) {
       rowNum = this.getEditRow();
     }
@@ -2297,12 +2297,24 @@
 
     // nothing changed just fire the calback and bail
     if (!ficCallDone && this.getEditForm() && !this.getEditForm().hasChanged && !this.getEditForm().isNew) {
-      if (saveCallback) {
-        this.fireCallback(saveCallback, "rowNum,colNum,editCompletionEvent,success", [rowNum, colNum, editCompletionEvent]);
+      if (originalCallback) {
+        this.fireCallback(originalCallback, "rowNum,colNum,editCompletionEvent,success", [rowNum, colNum, editCompletionEvent]);
       }
       return true;
     }
 
+    saveCallback = function () {
+      if (originalCallback) {
+        if (this.getSelectedRecord() && this.getSelectedRecord()[OB.Constants.ID]) {
+          if (!this.view.newRecordsAfterRefresh) {
+            this.view.newRecordsAfterRefresh = [];
+          }
+          this.view.newRecordsAfterRefresh.push(this.getSelectedRecord()[OB.Constants.ID]);
+        }
+        this.fireCallback(originalCallback, "rowNum,colNum,editCompletionEvent,success", [rowNum, colNum, editCompletionEvent]);
+      }
+    };
+
     if (ficCallDone) {
       // reset the new values as this can have changed because of a fic call
       newValues = this.getEditValues(rowNum);