details:   https://code.openbravo.com/erp/devel/pi/rev/699bc76591a4
changeset: 32450:699bc76591a4
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Tue Jul 11 09:13:34 2017 +0200
summary:   fixed bug 36454: in grid can trigger save before FIC response is 
received

  While editing in grid mode, it is possible to trigger save action by clicking
  grid's save button while FIC response is not received yet. If this occurs, the
  data sent to backend misses information that FIC should update.

  If grid's save button is clicked while in FIC call, postpone save action till
  FIC return.

details:   https://code.openbravo.com/erp/devel/pi/rev/5a4d53a0947f
changeset: 32451:5a4d53a0947f
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Tue Jul 11 13:29:02 2017 +0200
summary:   fixed 36457: inconsistent grid state if cancelling changes before 
FIC response

  If while editing in grid mode, changes are cancelled before receiving FIC
  response, it was possible to:
   - Create a new partial and incorrect line with only the data returned from
     FIC in case no line was being edited
   - Apply changes from FIC to incorrect row if another one was being edited

  Both problems are fixed by applying FIC changes only if the record is the same
  the request was triggered for, this is checked by ensuring both row number and
  record id. If editin a different record, FIC response is simply ignored.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
 |  46 ++++-----
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
 |  18 +-
 2 files changed, 29 insertions(+), 35 deletions(-)

diffs (119 lines):

diff -r 33b542f18c28 -r 5a4d53a0947f 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Mon Jul 10 17:14:46 2017 -0400
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Tue Jul 11 13:29:02 2017 +0200
@@ -680,10 +680,7 @@
 
     // store grid editing information which can be used when the fic returns
     // this is needed as after the fic return the edit row may have changed.
-    var gridEditInformation = this.view.viewGrid.getEditForm() ? {
-      grid: this.view.viewGrid,
-      editRow: this.view.viewGrid.getEditRow()
-    } : null;
+    var gridEditInformation = this.view.viewGrid.getEditForm() ? 
this.getGridEditInformation() : null;
 
     // do not make a request to the FIC in NEW mode if:
     // - the record is new and
@@ -785,7 +782,7 @@
 
   processFICReturn: function (response, data, request, gridEditInformation) {
     var length, modeIsNew = request.params.MODE === 'NEW',
-        noErrors, errorSolved;
+        noErrors, errorSolved, editingSameRecord, id;
 
     delete this.contextInfo;
 
@@ -815,6 +812,15 @@
         sessionAttributes = data.sessionAttributes,
         editValues, item, section, retHiddenInputs = data.hiddenInputs;
 
+    if (this.grid && gridEditInformation) {
+      id = this.getValue(OB.Constants.ID);
+      editingSameRecord = this.grid.getEditRow() === 
gridEditInformation.editRow && (!gridEditInformation.id || !id || id === 
gridEditInformation.id);
+      if (!editingSameRecord) {
+        // We're trying to process a FIC response that was triggered for a 
different row than the
+        // one that's currently being edited, it must be discarded
+        return;
+      }
+    }
 
     // apparently sometimes an empty string is returned
     if (calloutMessages && calloutMessages.length > 0 && 
calloutMessages[calloutMessages.length - 1].text !== '') {
@@ -822,23 +828,6 @@
       
this.view.messageBar.setMessage(isc.OBMessageBar[calloutMessages[calloutMessages.length
 - 1].severity], null, calloutMessages[calloutMessages.length - 1].text);
     }
 
-    // edit row has changed when returning, don't update the form anymore
-    if (this.grid && gridEditInformation && this.grid.getEditRow() !== 
gridEditInformation.editRow) {
-      if (columnValues) {
-        for (prop in columnValues) {
-          if (columnValues.hasOwnProperty(prop)) {
-            this.setColumnValuesInEditValues(prop, columnValues[prop], 
gridEditInformation);
-          }
-        }
-      }
-      editValues = 
gridEditInformation.grid.getEditValues(gridEditInformation.editRow);
-      if (editValues && editValues.actionAfterFicReturn) {
-        OB.Utilities.callAction(editValues.actionAfterFicReturn);
-        gridEditInformation.grid.setEditValue(gridEditInformation.editRow, 
'actionAfterFicReturn', null, true, true);
-      }
-      return;
-    }
-
     if (columnValues) {
       for (prop in columnValues) {
         if (columnValues.hasOwnProperty(prop)) {
@@ -1455,10 +1444,7 @@
 
     // store grid editing information which can be used when the fic returns
     // this is needed as after the fic return the edit row may have changed.
-    var gridEditInformation = this.view.viewGrid.isEditing() ? {
-      grid: this.view.viewGrid,
-      editRow: this.view.viewGrid.getEditRow()
-    } : null;
+    var gridEditInformation = this.view.viewGrid.isEditing() ? 
this.getGridEditInformation() : null;
 
     
OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent',
 allProperties, requestParams, function (response, data, request) {
 
@@ -1484,6 +1470,14 @@
     this.view.toolBar.updateButtonState(true);
   },
 
+  getGridEditInformation: function () {
+    return {
+      grid: this.view.viewGrid,
+      editRow: this.view.viewGrid.getEditRow(),
+      id: this.view.viewGrid.getEditForm().getValue(OB.Constants.ID)
+    };
+  },
+
   itemChanged: function (item, newValue) {
     this.itemChangeActions(item);
   },
diff -r 33b542f18c28 -r 5a4d53a0947f 
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-view-grid.js
     Mon Jul 10 17:14:46 2017 -0400
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
     Tue Jul 11 13:29:02 2017 +0200
@@ -3675,15 +3675,15 @@
       var focusItem = editForm.getFocusItem();
       if (focusItem && !focusItem.hasPickList) {
         focusItem.blur(focusItem.form, focusItem);
-        if (editForm.inFicCall) {
-          // use editValues object as the edit form will be re-used for a next 
row
-          this.setEditValue(rowNum, 'actionAfterFicReturn', {
-            target: this,
-            method: this.saveEditedValues,
-            parameters: [rowNum, colNum, newValues, oldValues, editValuesID, 
editCompletionEvent, saveCallback, true]
-          }, true, true);
-          return;
-        }
+      }
+      if (editForm.inFicCall) {
+        // use editValues object as the edit form will be re-used for a next 
row
+        this.setEditValue(rowNum, 'actionAfterFicReturn', {
+          target: this,
+          method: this.saveEditedValues,
+          parameters: [rowNum, colNum, newValues, oldValues, editValuesID, 
editCompletionEvent, saveCallback, true]
+        }, true, true);
+        return;
       }
     }
     // reset the new values as this can have changed because of a fic call or 
in the blur event of the focused item

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to