fixed 27860: "Go to previous/next record" with autosave set new state
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 14 Oct 2014 15:35:37 +0200
changeset 24080 f4010c9edcd3
parent 24079 83c29ab40446
child 24081 979e6707e985
fixed 27860: "Go to previous/next record" with autosave set new state

When previous/next record button is used on a non saved record and autosave is
executed. The loaded record is set with new UI.

The problem was the way used to determine after save if current record is new or
not: it checked if ID changed, which is correct in case of triggering autosave
with new button but not if it is triggered with next/back.

Using now for.isNewRecord to determine the same.
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 Aug 11 11:06:52 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Tue Oct 14 15:35:37 2014 +0200
@@ -1556,7 +1556,7 @@
     callback = function (resp, data, req) {
       var index1, index2, view = form.view,
           localRecord, status = resp.status,
-          sessionProperties, keepSelection, gridRefreshCallback, theGrid, theId, id = form.getValue('id');
+          sessionProperties, keepSelection, gridRefreshCallback, theGrid, theId, id;
 
       if (this.hasOwnProperty('previousExplicitOffline')) {
         isc.Offline.explicitOffline = this.previousExplicitOffline;
@@ -1565,6 +1565,7 @@
 
       // if no recordIndex then select explicitly
       if (recordIndex === -1) {
+        id = form.getValue('id');
         record = view.viewGrid.data.find('id', id);
         recordIndex = view.viewGrid.data.indexOf(record);
       }
@@ -1651,15 +1652,10 @@
         // remove any edit info in the grid
         view.viewGrid.discardEdits(recordIndex, null, false, isc.ListGrid.PROGRAMMATIC, true);
 
-        // Check if Id has changed 
-        if (id === form.getValue('id')) {
-          // Change some labels, set isNew as false
-          form.setNewState(false);
-        } else {
-          // New record, set isNew as true
-          form.setNewState(true);
-        }
-
+        // Change some labels:
+        //  * set isNew as false if we continue editing same record or we move to an existent one
+        //  * set isNew to true if autosaving record to start editing a new one
+        form.setNewState(form.isNewRecord());
 
         view.refreshParentRecord();