[client-event-handlers] Execute pre-save actions when saving grid from keyboard
authorCarlos Aristu <carlos.aristu@openbravo.com>
Thu, 16 Jun 2016 12:50:45 +0200
changeset 29796 f7fd27fb10b9
parent 29795 d7b00f5a135c
child 29797 f4ae96b9cee9
[client-event-handlers] Execute pre-save actions when saving grid from keyboard
Pre-save actions should be fired also before saving a record in the grid with the up, down, enter or tab keys.
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 Jun 16 10:14:21 2016 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Thu Jun 16 12:50:45 2016 +0200
@@ -3345,10 +3345,34 @@
     return ret;
   },
 
+  cellEditEnd: function (editCompletionEvent, newValue, ficCallDone, autoSaveDone) {
+    var rowNum, colNum, nextEditCell, newRow, me = this;
+
+    rowNum = me.getEditRow();
+    colNum = me.getEditCol();
+    nextEditCell = ((rowNum || rowNum === 0) && (colNum || colNum === 0) ? this.getNextEditCell(rowNum, colNum, editCompletionEvent) : null);
+    newRow = nextEditCell && nextEditCell[0] !== rowNum;
+    if (newRow !== false && me.keyPressedForEditCompletion(editCompletionEvent) && me.view.existsAction && me.view.existsAction('PRESAVE')) {
+      me.view.executePreSaveActions(function () {
+        me.doCellEditEnd(editCompletionEvent, newValue, ficCallDone, autoSaveDone);
+      });
+      return;
+    }
+    me.doCellEditEnd(editCompletionEvent, newValue, ficCallDone, autoSaveDone);
+  },
+
+  keyPressedForEditCompletion: function (editCompletionEvent) {
+    return editCompletionEvent === isc.ListGrid.DOWN_ARROW_KEYPRESS //
+    || editCompletionEvent === isc.ListGrid.UP_ARROW_KEYPRESS //
+    || editCompletionEvent === isc.ListGrid.ENTER_KEYPRESS //
+    || editCompletionEvent === isc.ListGrid.TAB_KEYPRESS //
+    || editCompletionEvent === isc.ListGrid.SHIFT_TAB_KEYPRESS;
+  },
+
   // check if a fic call needs to be done when leaving a cell and moving to the next
   // row
   // see description in saveEditvalues
-  cellEditEnd: function (editCompletionEvent, newValue, ficCallDone, autoSaveDone) {
+  doCellEditEnd: function (editCompletionEvent, newValue, ficCallDone, autoSaveDone) {
     var rowNum = this.getEditRow(),
         colNum = this.getEditCol();
     var editForm = this.getEditForm(),