Related with issue 25811: Extracts function OBViewGrid.updatedRecord
authorAugusto Mauch <augusto.mauch@openbravo.com>
Tue, 11 Nov 2014 09:56:37 +0100
changeset 25266 dc5f7d2a708d
parent 25265 b00aae95f22c
child 25267 31d3d17e8d78
Related with issue 25811: Extracts function OBViewGrid.updatedRecord

In the function OBStandardView.refreshCurrentRecord, there was some code that took an updated record and applied it to the grid. This code has been extraced to the OBViewGrid.updatedRecord function, for clarity and to make it reusable.
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
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Tue Nov 11 09:20:54 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Tue Nov 11 09:56:37 2014 +0100
@@ -3806,6 +3806,52 @@
         }
       }
     }
+  },
+
+  updateRecord: function (recordIndex, data, req) {
+    var sessionProperties = this.view.getContextInfo(true, true, false, true),
+        me = this;
+    data = OB.Utilities.Date.convertUTCTimeToLocalTime(data, this.completeFields);
+    if (this.data.updateCacheData) {
+      this.data.updateCacheData(data, req);
+    }
+    if (this.isGrouped) {
+      // if the grid is group update its values to show the updated data
+      this.setEditValues(recordIndex, data[0]);
+    }
+    this.selectRecord(this.getRecord(recordIndex));
+    this.refreshRow(recordIndex);
+    this.redraw();
+    if (!this.view.isShowingForm) {
+      OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent', sessionProperties, {
+        MODE: 'SETSESSION',
+        TAB_ID: this.view.tabId,
+        PARENT_ID: this.view.getParentId(),
+        ROW_ID: this.getSelectedRecord() ? this.getSelectedRecord().id : this.view.getCurrentValues().id
+      }, function (response, data, request) {
+        var sessionAttributes = data.sessionAttributes,
+            auxInputs = data.auxiliaryInputValues,
+            attachmentExists = data.attachmentExists,
+            prop;
+        if (sessionAttributes) {
+          me.view.viewForm.sessionAttributes = sessionAttributes;
+        }
+
+        if (auxInputs) {
+          this.auxInputs = {};
+          for (prop in auxInputs) {
+            if (auxInputs.hasOwnProperty(prop)) {
+              me.view.viewForm.setValue(prop, auxInputs[prop].value);
+              me.view.viewForm.auxInputs[prop] = auxInputs[prop].value;
+            }
+          }
+        }
+        me.view.viewForm.view.attachmentExists = attachmentExists;
+        //compute and apply tab display logic again after fetching auxilary inputs.
+        me.view.handleDefaultTreeView();
+        me.view.updateSubtabVisibility();
+      });
+    }
   }
 });
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Tue Nov 11 09:20:54 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Tue Nov 11 09:56:37 2014 +0100
@@ -2007,7 +2007,6 @@
     });
 
     callback = function (resp, data, req) {
-      var sessionProperties = me.getContextInfo(true, true, false, true);
       // this line does not work, but it should:
       //      me.getDataSource().updateCaches(resp, req);
       // therefore do an explicit update of the visual components
@@ -2016,47 +2015,7 @@
       }
       if (me.viewGrid.data) {
         var recordIndex = me.viewGrid.getRecordIndex(me.viewGrid.getSelectedRecord());
-        data = OB.Utilities.Date.convertUTCTimeToLocalTime(data, me.viewGrid.completeFields);
-        if (me.viewGrid.data.updateCacheData) {
-          me.viewGrid.data.updateCacheData(data, req);
-        }
-        if (me.viewGrid.isGrouped) {
-          // if the grid is group update its values to show the updated data
-          me.viewGrid.setEditValues(recordIndex, data[0]);
-        }
-        me.viewGrid.selectRecord(me.viewGrid.getRecord(recordIndex));
-        me.viewGrid.refreshRow(recordIndex);
-        me.viewGrid.redraw();
-        if (!me.isShowingForm) {
-          OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent', sessionProperties, {
-            MODE: 'SETSESSION',
-            TAB_ID: me.tabId,
-            PARENT_ID: me.getParentId(),
-            ROW_ID: me.viewGrid.getSelectedRecord() ? me.viewGrid.getSelectedRecord().id : me.getCurrentValues().id
-          }, function (response, data, request) {
-            var sessionAttributes = data.sessionAttributes,
-                auxInputs = data.auxiliaryInputValues,
-                attachmentExists = data.attachmentExists,
-                prop;
-            if (sessionAttributes) {
-              me.viewForm.sessionAttributes = sessionAttributes;
-            }
-
-            if (auxInputs) {
-              this.auxInputs = {};
-              for (prop in auxInputs) {
-                if (auxInputs.hasOwnProperty(prop)) {
-                  me.viewForm.setValue(prop, auxInputs[prop].value);
-                  me.viewForm.auxInputs[prop] = auxInputs[prop].value;
-                }
-              }
-            }
-            me.viewForm.view.attachmentExists = attachmentExists;
-            //compute and apply tab display logic again after fetching auxilary inputs.
-            me.handleDefaultTreeView();
-            me.updateSubtabVisibility();
-          });
-        }
+        me.viewGrid.updateRecord(recordIndex, data, req);
       }