Fixed issue 28466: Autosave was executed when creating a new record.
authorNaroa Iriarte <naroa.iriarte@openbravo.com>
Wed, 24 Dec 2014 16:42:09 +0100
changeset 25714 8965d2c4301b
parent 25713 b878d4b1ee9a
child 25715 4e47ac5c68fa
Fixed issue 28466: Autosave was executed when creating a new record.

When a window only has one subtab, and that subtab has a display logic, just after clicking the proper button to create a new
record in the header tab (both in grid and in form mode), the autosave is executed. This happens only the first time that a record is
created.

The problem was in the "updateSubtabVisibility" function of the "ob-standard-view.js".

The problem was that at first, in the function, there was a logic that was not taking into account the fact that if it was the record selected in the header tab has not been saved yet, its subtabs are empty, and it is not neccesary to refresh them.

Before the fix it tried to refresh the subtabs, which resulted in a call to autosave.

For fixing it a new condition has been added to the "updateSubtabVisibility" function. With this new condition
now, the call to the autosave is avoided in the case of the new record.

A new function called "isEditingNewRecord" has been created too. This function returns true if a new record is being edited in the view.
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/main/ob-standard-view.js	Mon Dec 29 11:13:30 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Wed Dec 24 16:42:09 2014 +0100
@@ -1700,7 +1700,7 @@
         } else {
           if (this.childTabSet.visibility === 'hidden') {
             this.childTabSet.show();
-            if (tabViewPane.showTabIf && !tabViewPane.data && !tabViewPane.refreshingData && tabViewPane.isVisible()) {
+            if (tabViewPane.showTabIf && !tabViewPane.data && !tabViewPane.refreshingData && tabViewPane.isVisible() && !this.isEditingNewRecord()) {
               // If the child tab does not have data yet, refresh it
               tabViewPane.refreshingData = true;
               tabViewPane.refresh();
@@ -1736,6 +1736,12 @@
     }
   },
 
+  //This function returns true if it is a new record and it is being edited
+  isEditingNewRecord: function () {
+    var form = this.isShowingForm ? this.viewForm : this.viewGrid.getEditForm();
+    return form === null ? false : form.isNew;
+  },
+
   // Adds to contextInfo the session attributes of the childView, 
   // unless the session attribute is an auxiliary input of its parent tab
   addPreferenceValues: function (contextInfo, childView) {