# HG changeset patch
# User Carlos Aristu <carlos.aristu@openbravo.com>
# Date 1506597546 -7200
#      Thu Sep 28 13:19:06 2017 +0200
# Node ID 9fca411c3c753cf5d19e7b938b4f9d01b7c2d031
# Parent  7d2c288c2d470f971606243ce4bd450430465de6
fixes bug 36970: Return focus to the record if failed to be edited in grid view

  When a record failed to be edited in grid view right after moving to the form view of its parent record, the window ended in an inconsitent state:
    - The focus was placed at the header
    - The active view still was the child tab

  This was not happening when editing the child record in form view, because the focus was always returned to the form. To fix the problem now the same behavior has been implemented in grid view: in the described scenario the focus is returned to the edit form of the grid.

  Besides, the "editRow" and "editSession" variables were unused in the editFailed() function. Thus, both have been removed.

diff --git a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js b/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
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
@@ -3085,7 +3085,7 @@
 
   editFailed: function (rowNum, colNum, newValues, oldValues, editCompletionEvent, dsResponse, dsRequest) {
     var record = this.getRecord(rowNum),
-        editRow, editSession, view = this.view,
+        view = this.view,
         form, isNewRecord;
 
     // set the default error message,
@@ -3107,9 +3107,14 @@
       isc.warn(OB.I18N.getLabel('OBUIAPP_AutoSaveError', [this.view.tabTitle]));
     }
 
-    // show an error message in the toolbar if the event that triggered the action was an autosave, to mimic the way client side validation errors are handled
+    form = this.getEditForm();
     if (view.standardWindow.isAutoSaving) {
+      // show an error message in the toolbar if the event that triggered the action was an autosave, to mimic the way client side validation errors are handled
       view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, OB.I18N.getLabel('OBUIAPP_ErrorInFieldsGrid', [view.ID]));
+      if (form) {
+        // return the focus to the edit form of the record that failed to be edited
+        form.setFocusInForm();
+      }
     }
     view.standardWindow.cleanUpAutoSaveProperties();
     view.updateTabTitle();
@@ -3120,7 +3125,6 @@
       this.selectRecord(record);
     }
 
-    form = this.getEditForm();
     isNewRecord = (form === null) ? false : form.isNew;
     if (isNewRecord) {
       delete this.view._savingNewRecord;
