[toolbar][ks] Added keyboard shortcuts capabilities to icon buttons - part2
authorDavid Baz Fayos <david.baz@openbravo.com>
Tue, 25 Jan 2011 20:42:18 +0100
changeset 10125 ddb356afbb3d
parent 10124 f2c71bba342c
child 10126 157e1d81beb8
[toolbar][ks] Added keyboard shortcuts capabilities to icon buttons - part2
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-toolbar.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Tue Jan 25 19:43:05 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Tue Jan 25 20:42:18 2011 +0100
@@ -632,20 +632,14 @@
   setAsActiveView: function(){
     this.standardWindow.setActiveView(this);
   },
-
-  setToolBarState: function(state) {
-    if (state) {
-      this.toolBar.setActive(true);
-    } else {
-      this.toolBar.setActive(false);
-    }
-  },
   
   setActiveViewProps: function(state){
     if (state) {
+      this.toolBar.show();
       this.activeBar.setActive(true);
       this.setViewFocus();
     } else {
+      this.toolBar.hide();
       this.activeBar.setActive(false);
       // note we can not check on viewForm visibility as 
       // the grid and form can both be hidden when changing
@@ -658,7 +652,6 @@
       }
     }
     this.setTabButtonState(state);
-    this.setToolBarState(state);
   },
   
   // do refresh contents with a small delay to not refresh child views
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js	Tue Jan 25 19:43:05 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js	Tue Jan 25 20:42:18 2011 +0100
@@ -41,20 +41,9 @@
       } else {
         // enable when supporting grid editing
         this.setDisabled(true);
-      }      
+      }
     },
-    enableShortcut: function(){
-      var me = this;
-      var ksAction = function(){
-        if (!me.disabled) {
-          me.action();
-        }
-      };
-      OB.KeyboardManager.KS.add('ToolBar_Save', ksAction);
-    },
-    disableShortcut: function(){
-      OB.KeyboardManager.KS.remove('ToolBar_Save');
-    }
+    keyboardShortcutId: 'ToolBar_Save'
   },
   NEW_ROW_BUTTON_PROPERTIES: {
     action: function(){
@@ -704,32 +693,39 @@
     } 
   },
 
-  isActive: false,
+  visibilityChanged: function(state) {
+    if (state) {
+      this.enableShortcuts();
+    } else {
+      this.disableShortcuts();
+    }
+  },
 
-  setActive: function(value) {
-    if (value === true && this.isActive === false) {
-      this.isActive = true;
-      this.show();
-      if (this.leftMembers) {
-        for (i = 0; i < this.leftMembers.length; i++) {
-          if (this.leftMembers[i].enableShortcut) {
-            this.leftMembers[i].enableShortcut();
-          }
+  draw: function() {
+    this.Super('draw', arguments);
+    this.enableShortcuts();
+  },
+
+  enableShortcuts: function() {
+    if (this.leftMembers) {
+      for (i = 0; i < this.leftMembers.length; i++) {
+        if (this.leftMembers[i].enableShortcut) {
+          this.leftMembers[i].enableShortcut();
         }
       }
-    } else if (value === false && this.isActive === true) {
-      this.isActive = false;
-      if (this.leftMembers) {
-        for (i = 0; i < this.leftMembers.length; i++) {
-          if (this.leftMembers[i].disableShortcut) {
-            this.leftMembers[i].disableShortcut();
-          }
+    }
+  },
+
+  disableShortcuts: function() {
+    if (this.leftMembers) {
+      for (i = 0; i < this.leftMembers.length; i++) {
+        if (this.leftMembers[i].disableShortcut) {
+          this.leftMembers[i].disableShortcut();
         }
       }
-      this.hide();
     }
   },
-  
+
   addMembers: 'null',
   
   leftMembers: [],
@@ -778,6 +774,24 @@
     }
     
     this.setBaseStyle('OBToolbarIconButton_icon_' + this.buttonType + this.customState + extraClass + 'OBToolbarIconButton');
+  },
+
+  keyboardShortcutId: null,
+  enableShortcut: function() {
+    if (this.keyboardShortcutId) {
+      var me = this;
+      var ksAction = function(){
+        if (!me.disabled) {
+          me.action();
+        }
+      };
+      OB.KeyboardManager.KS.add(this.keyboardShortcutId, ksAction);
+    }
+  },
+  disableShortcut: function() {
+    if (this.keyboardShortcutId) {
+      OB.KeyboardManager.KS.remove(this.keyboardShortcutId);
+    }
   }
 });