Added keyboard short cuts to form close and inline grid editing
authorMartin Taal <martin.taal@openbravo.com>
Thu, 03 Mar 2011 15:36:30 +0100
changeset 10994 2f0491185ae7
parent 10993 8fa360d7c861
child 10995 59896f979c5a
Added keyboard short cuts to form close and inline grid editing
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Thu Mar 03 15:01:36 2011 +0100
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Thu Mar 03 15:36:30 2011 +0100
@@ -28,7 +28,9 @@
   {"id": "TabSet_ActivateTab9", "keyComb": {"ctrl": true, "alt": true, "key": "9"}},
   {"id": "TabSet_closeAllTabs", "keyComb": {"ctrl": true, "alt": true, "key": "0"}},
   {"id": "TabSet_ActivateRightTab", "keyComb": {"ctrl": true, "alt": true, "key": "+"}},
-  {"id": "TabSet_ActivateLeftTab", "keyComb": {"ctrl": true, "alt": true, "key": "-"}}
+  {"id": "TabSet_ActivateLeftTab", "keyComb": {"ctrl": true, "alt": true, "key": "-"}},
+  {"id": "Grid_EditInForm", "keyComb": {"ctrl": true, "alt": false, "key": "f2"}},
+  {"id": "Grid_EditInGrid", "keyComb": {"ctrl": false, "alt": false, "key": "f2"}}
 ]]]></VALUE>
 <!--5EE6D055A7FE4C4DA7EB557F6C61D0EA-->  <PROPERTY><![CDATA[OBUIAPP_KeyboardShortcuts]]></PROPERTY>
 <!--5EE6D055A7FE4C4DA7EB557F6C61D0EA-->  <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST>
@@ -60,6 +62,7 @@
 <!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <VALUE><![CDATA[[
   {"id": "ToolBar_Save", "keyComb": {"ctrl": true, "alt": true, "key": "S"}},
+  {"id": "ToolBar_SaveClose", "keyComb": {"ctrl": true, "alt": true, "key": "X"}},
   {"id": "ToolBar_NewRow", "keyComb": {"ctrl": true, "alt": true, "key": "I"}},
   {"id": "ToolBar_NewDoc", "keyComb": {"ctrl": true, "alt": true, "key": "N"}},
   {"id": "ToolBar_Eliminate", "keyComb": {"ctrl": true, "alt": true, "key": "D"}},
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Thu Mar 03 15:01:36 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Thu Mar 03 15:36:30 2011 +0100
@@ -556,12 +556,14 @@
       this.toolBar.show();
       this.activeBar.setActive(true);
       this.setViewFocus();
+      this.viewGrid.setActive(true);
     } else {
       
       // close any editors we may have
       this.viewGrid.closeAnyOpenEditor();
       
       this.toolBar.hide();
+      this.viewGrid.setActive(false);
       this.activeBar.setActive(false);
       // note we can not check on viewForm visibility as 
       // the grid and form can both be hidden when changing
@@ -779,7 +781,7 @@
       // also handle the case that there are unsaved values in the grid
       // show them in the form
       var rowNum = this.viewGrid.getRecordIndex(record);
-      this.viewForm.editRecord(this.viewGrid.getEditedRecord(rowNum), preventFocus);
+      this.viewForm.editRecord(this.viewGrid.getEditedRecord(rowNum), preventFocus, this.viewGrid.recordHasChanges(rowNum));
     }
   },
   
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js	Thu Mar 03 15:01:36 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js	Thu Mar 03 15:36:30 2011 +0100
@@ -107,9 +107,12 @@
     }
   },
   
-  editRecord: function(record, preventFocus){
+  editRecord: function(record, preventFocus, hasChanges){
     var ret = this.Super('editRecord', arguments);
     this.doEditRecordActions(preventFocus, false);
+    if (hasChanges) {
+      this.setHasChanged(true);
+    }
     return ret;
   },
   
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js	Thu Mar 03 15:01:36 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js	Thu Mar 03 15:36:30 2011 +0100
@@ -341,6 +341,38 @@
     return this.Super('bodyKeyPress', arguments);
   },
 
+  // called when the view gets activated
+  setActive: function(active) {
+    if (active) {
+      this.enableKeyBoardShortCuts();
+    } else {
+      this.disableKeyBoardShortCuts();
+    }    
+  },
+
+  disableKeyBoardShortCuts: function() {
+    OB.KeyboardManager.KS.set('Grid_EditInGrid', function() { return true; });
+    OB.KeyboardManager.KS.set('Grid_EditInForm', function() { return true; });
+  },
+  
+  enableKeyBoardShortCuts: function() {
+    var grid = this;
+    var editInGridAction = function(){
+      if (grid.getSelectedRecords().length === 1) {    
+        grid.endEditing();
+        grid.startEditing(grid.getRecordIndex(grid.getSelectedRecords()[0]));
+      }
+    };
+    OB.KeyboardManager.KS.set('Grid_EditInGrid', editInGridAction);
+    var editInFormAction = function(){
+      if (grid.getSelectedRecords().length === 1) {          
+        grid.endEditing();
+        grid.view.editRecord(grid.getSelectedRecords()[0]);
+      }
+    };
+    OB.KeyboardManager.KS.set('Grid_EditInForm', editInFormAction);
+  },
+
   // overridden to set the enterkeyaction to nextrowstart in cases the current row
   // is the last being edited  
   getNextEditCell : function (rowNum, colNum, editCompletionEvent) {
@@ -1548,6 +1580,9 @@
   
   // we are being reshown, get new values for the combos
   visibilityChanged: function(visible){
+    if (visible && this.view.isActiveView()) {      
+      this.enableKeyBoardShortCuts();
+    }
     if (visible && this.getEditRow()) {
       this.getEditForm().doChangeFICCall();
     }