details:   https://code.openbravo.com/erp/devel/pi/rev/a821c504f959
changeset: 16566:a821c504f959
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu May 17 11:56:12 2012 +0200
summary:   Fixes issue 20474: When you save a register in grid view, amounts 
fields change to the previous value
Object returned from ListGrid.getEditValues can't be used directly always go 
through the ListGrid api
For example: ListGrid.setEditValue

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
      |   4 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-encrypted.js
 |   4 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
                   |  88 +++++----
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
                        |   4 +
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
                   |  11 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
    |   7 +-
 6 files changed, 63 insertions(+), 55 deletions(-)

diffs (truncated from 338 to 300 lines):

diff -r a683fa9bce54 -r a821c504f959 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
        Thu May 17 11:42:14 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
        Thu May 17 11:56:12 2012 +0200
@@ -260,8 +260,8 @@
       //  the grid does not save the value before making the FIC call, so the 
value has to 
       //  be saved explicitly
       //  See issue 19694 (https://issues.openbravo.com/view.php?id=19694)
-      if (this.grid && this.grid.getEditRow()) {
-        this.grid.getEditValues(this.grid.getEditRow())[this.name] = 
this.getValue();
+      if (this.grid && this.grid.isEditing()) {
+        this.grid.setEditValue(this.grid.getEditRow(), this.name, 
this.getValue(), true, true);
       }
       this.textField._textChanged = false;
     }
diff -r a683fa9bce54 -r a821c504f959 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-encrypted.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-encrypted.js
   Thu May 17 11:42:14 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-encrypted.js
   Thu May 17 11:56:12 2012 +0200
@@ -26,8 +26,8 @@
   changed: function (form, item, value) {
     this.Super('changed', arguments);
     this.form.setValue(item.name + '_cleartext', value);
-    if (this.grid.getEditRow() !== null) {
-      this.grid.getEditValues(this.grid.getEditRow())[item.name + 
'_cleartext'] = value;
+    if (this.grid.isEditing()) {
+      this.grid.setEditValue(this.grid.getEditRow(), item.name + '_cleartext', 
value, true, true);
     }
   }
 });
\ No newline at end of file
diff -r a683fa9bce54 -r a821c504f959 
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
     Thu May 17 11:42:14 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Thu May 17 11:56:12 2012 +0200
@@ -597,16 +597,16 @@
     // note that only the fields with errors are validated anyway
     this.validateAfterFicReturn = true;
 
-    // get the editRow before doing the call
-    var editRow = me.view.viewGrid.getEditRow();
+    // 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;
 
     this.inFicCall = true;
 
     
OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent',
 allProperties, requestParams, function (response, data, request) {
-      var editValues;
-      if (editRow || editRow === 0) {
-        editValues = me.view.viewGrid.getEditValues(editRow);
-      }
 
       // no focus item found, focus on the body of the grid
       // this makes sure that keypresses end up in the 
@@ -615,9 +615,9 @@
         me.view.viewGrid.body.focus();
       }
 
-      me.processFICReturn(response, data, request, editValues, editRow);
+      me.processFICReturn(response, data, request, gridEditInformation);
 
-      if (!this.grid || this.grid.getEditRow() !== editRow) {
+      if (!this.grid || !gridEditInformation || this.grid.getEditRow() !== 
gridEditInformation.editRow) {
         // remember the initial values, if we are still editing the same row
         me.rememberValues();
       }
@@ -676,7 +676,7 @@
     }
   },
 
-  processFICReturn: function (response, data, request, editValues, editRow) {
+  processFICReturn: function (response, data, request, gridEditInformation) {
     var length, modeIsNew = request.params.MODE === 'NEW',
         noErrors, errorSolved;
 
@@ -704,21 +704,22 @@
         calloutMessages = data.calloutMessages,
         auxInputs = data.auxiliaryInputValues,
         prop, value, i, j, dynamicCols = data.dynamicCols,
-        sessionAttributes = data.sessionAttributes,
+        sessionAttributes = data.sessionAttributes, editValues,
         item, section, retHiddenInputs = data.hiddenInputs;
 
     // edit row has changed when returning, don't update the form anymore
-    if (this.grid && this.grid.getEditRow() !== editRow) {
+    if (this.grid && gridEditInformation && this.grid.getEditRow() !== 
gridEditInformation.editRow) {
       if (columnValues) {
         for (prop in columnValues) {
           if (columnValues.hasOwnProperty(prop)) {
-            this.setColumnValuesInEditValues(prop, columnValues[prop], 
editValues);
+            this.setColumnValuesInEditValues(prop, columnValues[prop], 
gridEditInformation);
           }
         }
       }
+      editValues = 
gridEditInformation.grid.getEditValues(gridEditInformation.editRow);
       if (editValues && editValues.actionAfterFicReturn) {
         OB.Utilities.callAction(editValues.actionAfterFicReturn);
-        delete editValues.actionAfterFicReturn;
+        gridEditInformation.grid.setEditValue(gridEditInformation.editRow, 
'actionAfterFicReturn', null, true, true);
       }
       return;
     }
@@ -726,7 +727,7 @@
     if (columnValues) {
       for (prop in columnValues) {
         if (columnValues.hasOwnProperty(prop)) {
-          this.processColumnValue(prop, columnValues[prop], editValues);
+          this.processColumnValue(prop, columnValues[prop], 
gridEditInformation);
         }
       }
     }
@@ -780,7 +781,9 @@
     }
 
     // grid editing    
-    if (this.grid && this.grid.setEditValues && this.grid.getEditRow() === 
editRow) {
+    if (this.grid && gridEditInformation && this.grid.setEditValues && 
this.grid.getEditRow() === gridEditInformation.editRow) {
+      editValues = 
gridEditInformation.grid.getEditValues(gridEditInformation.editRow);
+
       // keep it as it is overwritten by the setEditValues
       var tmpActionAfterFic = null;
       if (editValues && editValues.actionAfterFicReturn) {
@@ -788,8 +791,8 @@
       }
       this.grid.setEditValues(this.grid.getEditRow(), this.getValues(), true);
       this.grid.storeUpdatedEditorValue(true);
-      if (editValues) {
-        editValues.actionAfterFicReturn = tmpActionAfterFic;
+      if (tmpActionAfterFic) {
+        this.grid.setEditValue(gridEditInformation.editRow, 
'actionAfterFicReturn', tmpActionAfterFic, true, true);
       }
     }
 
@@ -901,7 +904,7 @@
     this.fetchData(criteria);
   },
 
-  processColumnValue: function (columnName, columnValue, editValues) {
+  processColumnValue: function (columnName, columnValue, gridEditInformation) {
     // Modifications in this method should go also in 
setColumnValuesInEditValues because both almost do the same
     var typeInstance;
     var assignValue;
@@ -937,10 +940,10 @@
       field.setEntries(entries);
     }
 
-    if (editValues && field.valueMap) {
+    if (gridEditInformation && field.valueMap) {
       // store the valuemap in the edit values so it can be retrieved later
       // when the form is rebuild
-      editValues[prop + '._valueMap'] = field.valueMap;
+      gridEditInformation.grid.setEditValue(gridEditInformation.editRow, prop 
+ '._valueMap', field.valueMap, true, true);
     }
 
     // Adjust to formatting if exists value and classicValue. 
@@ -1016,12 +1019,12 @@
     }
   },
 
-  setColumnValuesInEditValues: function (columnName, columnValue, editValues) {
+  setColumnValuesInEditValues: function (columnName, columnValue, 
gridEditInformation) {
     // Modifications in this method should go also in processColumnValue 
because both almost do the same
     var assignClassicValue, typeInstance, length, isDate;
 
     // no editvalues even anymore, go away
-    if (!editValues) {
+    if (!gridEditInformation) {
       return;
     }
 
@@ -1042,18 +1045,18 @@
         identifier = entries[i][OB.Constants.IDENTIFIER] || '';
         valueMap[id] = identifier;
       }
-      editValues[prop + '._valueMap'] = valueMap;
+      gridEditInformation.grid.setEditValue(gridEditInformation.editRow, prop 
+ '._valueMap', valueMap, true, true);
     }
 
     if (columnValue.value && (columnValue.value === 'null' || 
columnValue.value === '')) {
       // handle the case that the FIC returns a null value as a string
       // should be repaired in the FIC
       // note: do not use clearvalue as this removes the value from the form
-      editValues[prop] = null;
+      gridEditInformation.grid.setEditValue(gridEditInformation.editRow, prop, 
null, true, true);
     } else if (columnValue.value || columnValue.value === 0 || 
columnValue.value === false) {
       isDate = field && field.type && 
(isc.SimpleType.getType(field.type).inheritsFrom === 'date' || 
isc.SimpleType.getType(field.type).inheritsFrom === 'datetime');
       if (isDate) {
-        editValues[prop] = isc.Date.parseSchemaDate(columnValue.value);
+        gridEditInformation.grid.setEditValue(gridEditInformation.editRow, 
prop, isc.Date.parseSchemaDate(columnValue.value), true, true);
       } else {
 
         // set the identifier/display field if the identifier is passed also
@@ -1064,14 +1067,14 @@
           identifier = valueMap[columnValue.value];
         }
         if (identifier) {
-          editValues[prop + OB.Constants.FIELDSEPARATOR + 
OB.Constants.IDENTIFIER] = identifier;
+          gridEditInformation.grid.setEditValue(gridEditInformation.editRow, 
prop + OB.Constants.FIELDSEPARATOR + OB.Constants.IDENTIFIER, identifier, true, 
true);
         }
-        editValues[prop] = columnValue.value;
+        gridEditInformation.grid.setEditValue(gridEditInformation.editRow, 
prop, columnValue.value, true, true);
       }
     } else {
       // note: do not use clearvalue as this removes the value from the form
       // which results it to not be sent to the server anymore
-      editValues[prop] = null;
+      gridEditInformation.grid.setEditValue(gridEditInformation.editRow, prop, 
null, true, true);
     }
 
     // store the textualvalue so that it is correctly send back to the server
@@ -1080,25 +1083,27 @@
       assignClassicValue = (field.typeInstance && 
field.typeInstance.parseInput && field.typeInstance.editFormatter) ? 
field.typeInstance.editFormatter(field.typeInstance.parseInput(columnValue.classicValue))
 : columnValue.classicValue;
       typeInstance = isc.SimpleType.getType(field.type);
       if (columnValue.classicValue && typeInstance.decSeparator) {
-        this.setTextualValue(field.name, assignClassicValue, typeInstance, 
editValues);
+        this.setTextualValue(field.name, assignClassicValue, typeInstance, 
gridEditInformation);
       }
     }
   },
 
   // note textValue is in user format using users decimal and group separator
-  setTextualValue: function (fldName, textValue, type, editValues) {
+  setTextualValue: function (fldName, textValue, type, gridEditInformation) {
     if (!textValue || textValue.trim() === '') {
       textValue = '';
     } else {
       textValue = OB.Utilities.Number.OBMaskedToOBPlain(textValue, 
type.decSeparator, type.groupSeparator);
       textValue = textValue.replace(type.decSeparator, '.');
     }
-    if (editValues) {
-      editValues[fldName + '_textualValue'] = textValue;
-    } else if (this.grid && this.grid.getEditForm()) {
-      this.grid.getEditValues(this.grid.getEditRow())[fldName + 
'_textualValue'] = textValue;
+    
+    this.setValue(fldName + '_textualValue', textValue);
+    
+    if (gridEditInformation) {
+      gridEditInformation.grid.setEditValue(gridEditInformation.editRow, 
fldName + '_textualValue', textValue, true, true);
+    } else if (this.grid && this.grid.isEditing()) {
+      this.grid.setEditValue(this.grid.getEditRow(), fldName + 
'_textualValue', textValue, true, true);
     }
-    this.setValue(fldName + '_textualValue', textValue);
   },
 
   // calls setValue and the onchange handling
@@ -1224,15 +1229,16 @@
       this.delayCall('setDisabledWhenStillInFIC', [true], 10);
     }
 
-    var editRow = this.view.viewGrid.getEditRow();
+    // 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;
 
     
OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent',
 allProperties, requestParams, function (response, data, request) {
-      var editValues;
-      if (editRow || editRow === 0) {
-        editValues = me.view.viewGrid.getEditValues(editRow);
-      }
 
-      me.processFICReturn(response, data, request, editValues, editRow);
+      me.processFICReturn(response, data, request, gridEditInformation);
 
       // compute the focus item after the fic has been done
       // and fields have become visible
diff -r a683fa9bce54 -r a821c504f959 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
  Thu May 17 11:42:14 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
  Thu May 17 11:56:12 2012 +0200
@@ -121,6 +121,10 @@
     return response;
   },
 
+  isEditing: function() {
+    return this.getEditForm();
+  },
+  
   focusInFirstFilterEditor: function () {
     if (this.getFilterEditor()) { // there is a filter editor
       var object = this.getFilterEditor().getEditForm(),
diff -r a683fa9bce54 -r a821c504f959 
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
     Thu May 17 11:42:14 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
     Thu May 17 11:56:12 2012 +0200
@@ -2156,12 +2156,11 @@
         focusItem.blur(focusItem.form, focusItem);
         if (editForm.inFicCall) {
           // use editValues object as the edit form will be re-used for a next 
row
-          var editValues = this.getEditValues(rowNum);
-          editValues.actionAfterFicReturn = {
-            target: this,
-            method: this.saveEditedValues,
-            parameters: [rowNum, colNum, newValues, oldValues, editValuesID, 
editCompletionEvent, saveCallback, true]
-          };
+          this.setEditValue(rowNum, 'actionAfterFicReturn', {
+              target: this,
+              method: this.saveEditedValues,
+              parameters: [rowNum, colNum, newValues, oldValues, editValuesID, 
editCompletionEvent, saveCallback, true]

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to