diff --git a/phpgwapi/js/egw_action/egw_action.js b/phpgwapi/js/egw_action/egw_action.js index ef46e83bf2..a9b7cd6f06 100644 --- a/phpgwapi/js/egw_action/egw_action.js +++ b/phpgwapi/js/egw_action/egw_action.js @@ -81,6 +81,20 @@ function egw_getObjectManager(_id, _create) { return res; } +/** + * Returns the object manager for the current application + */ +function egw_getAppObjectManager(_create) { + return egw_getObjectManager(egw_getAppName(), _create); +} + +/** + * Returns the action manager for the current application + */ +function egw_getAppActionManager(_create) { + return egw_getActionManager(egw_getAppName(), _create); +} + /** egwActionHandler Interface **/ @@ -665,6 +679,10 @@ var EGW_AO_SHIFT_STATE_BLOCK = 0x02; // flag is not applied to container objects, it may lead to some strange behaviour. var EGW_AO_FLAG_IS_CONTAINER = 0x01; +// If this flag is set, the object will gets its focus when no other object is +// selected and e.g. a key is pressed. +var EGW_AO_FLAG_DEFAULT_FOCUS = 0x02; + /** * The egwActionObject represents an abstract object to which actions may be * applied. Communication with the DOM tree is established by using the @@ -1189,6 +1207,11 @@ egwActionObject.prototype.getPrevious = function(_intval) { if (this.parent != null) { + if (this.getFocused() && !this.getSelected()) { + return this; + } + + var idx = this.parent.children.indexOf(this); if (idx > 0) { @@ -1208,6 +1231,10 @@ egwActionObject.prototype.getNext = function(_intval) { if (this.parent != null) { + if (this.getFocused() && !this.getSelected()) { + return this; + } + var idx = this.parent.children.indexOf(this); if (idx < this.parent.children.length - 1) { diff --git a/phpgwapi/js/egw_action/egw_grid_data.js b/phpgwapi/js/egw_action/egw_grid_data.js index f7ac5c9ced..1934010586 100644 --- a/phpgwapi/js/egw_action/egw_grid_data.js +++ b/phpgwapi/js/egw_action/egw_grid_data.js @@ -49,7 +49,7 @@ function egwGridDataElement(_id, _parent, _columns, _readQueue, _objectManager) if (!_parent) { this.actionObject = this.parentActionObject.addObject(_id, null, - EGW_AO_FLAG_IS_CONTAINER); + EGW_AO_FLAG_IS_CONTAINER | EGW_AO_FLAG_DEFAULT_FOCUS); this.readQueue.setDataRoot(this); } diff --git a/phpgwapi/js/egw_action/egw_grid_view.js b/phpgwapi/js/egw_action/egw_grid_view.js index 2d9c18b3d5..b8894df5ca 100644 --- a/phpgwapi/js/egw_action/egw_grid_view.js +++ b/phpgwapi/js/egw_action/egw_grid_view.js @@ -1506,7 +1506,7 @@ function egwGridViewRow__columnClick(_shiftState, _column) break; case EGW_SELECTMODE_TOGGLE: this.aoi.updateState(EGW_AO_STATE_SELECTED, !isSelected, - egwSetBit(EGW_AO_SHIFT_STATE_MULTI, _shiftState, true)); + egwSetBit(_shiftState, EGW_AO_SHIFT_STATE_MULTI, true)); break; } } diff --git a/phpgwapi/js/egw_action/egw_keymanager.js b/phpgwapi/js/egw_action/egw_keymanager.js index d2c57b9159..9072407191 100644 --- a/phpgwapi/js/egw_action/egw_keymanager.js +++ b/phpgwapi/js/egw_action/egw_keymanager.js @@ -119,6 +119,26 @@ function egw_keycode_makeValid(_keyCode) { return -1; } +function _egw_nodeIsInInput(_node) +{ + if ((_node != null) && (_node != document)) + { + var tagName = _node.tagName.toLowerCase(); + if (tagName == "input" || tagName == "select") + { + return true; + } + else + { + return _egw_nodeIsInInput(_node.parentNode); + } + } + else + { + return false; + } +} + /** * Register the onkeypress handler on the document */ @@ -136,11 +156,17 @@ $(document).ready(function() { // Only go on if this is a valid key code - call the key handler if (keyCode != -1) { - if (egw_keyHandler(keyCode, e.shiftKey, e.ctrlKey || e.metaKey, e.altKey)) + // Check whether the event came from an input field - if yes, only + // allow function keys (like F1) to be captured by our code + var inInput = _egw_nodeIsInInput(e.target); + if (!inInput || (keyCode >= EGW_KEY_F1 && keyCode <= EGW_KEY_F12)) { - // If the key handler successfully passed the key event to some - // sub component, prevent the default action - e.preventDefault(); + if (egw_keyHandler(keyCode, e.shiftKey, e.ctrlKey || e.metaKey, e.altKey)) + { + // If the key handler successfully passed the key event to some + // sub component, prevent the default action + e.preventDefault(); + } } } }); @@ -223,13 +249,43 @@ function egw_keyHandler(_keyCode, _shift, _ctrl, _alt) { // Get the object manager and fetch the container of the currently // focused object - var focusedObject = egw_getObjectManager().getFocusedObject(); - if (focusedObject) + var appMgr = egw_getAppObjectManager(false); + if (appMgr) { - var cntr = focusedObject.getContainerRoot(); - if (cntr) + var focusedObject = appMgr.getFocusedObject(); + + if (!focusedObject) { - return cntr.handleKeyPress(_keyCode, _shift, _ctrl, _alt); + // If the current application doesn't have a focused object, + // check whether the application object manager contains an object + // with the EGW_AO_FLAG_DEFAULT_FOCUS flag set. + var cntr = null; + for (var i = 0; i < appMgr.children.length; i++) + { + var child = appMgr.children[i]; + if (egwBitIsSet(EGW_AO_FLAG_DEFAULT_FOCUS, child.flags)) + { + cntr = child; + break; + } + } + + // Get the first child of the found container and focus the first + // object + if (cntr && cntr.children.length > 0) + { + cntr.children[0].setFocused(true); + focusedObject = cntr.children[0]; + } + } + + if (focusedObject) + { + var cntr = focusedObject.getContainerRoot(); + if (cntr) + { + return cntr.handleKeyPress(_keyCode, _shift, _ctrl, _alt); + } } } diff --git a/phpgwapi/js/jsapi/jsapi.js b/phpgwapi/js/jsapi/jsapi.js index e9f77b6a95..2b7f930cca 100644 --- a/phpgwapi/js/jsapi/jsapi.js +++ b/phpgwapi/js/jsapi/jsapi.js @@ -189,6 +189,21 @@ function egw_getApp(_name) return window.parent.framework.getApplicationByName(_name); } +/** + * Returns the name of the currently active application + */ +function egw_getAppName() +{ + if (typeof egw_appName == 'undefined') + { + return 'egroupware'; + } + else + { + return egw_appName; + } +} + /** * Refresh given application _targetapp display of entry _app _id, incl. outputting _msg * diff --git a/phpgwapi/templates/idots/class.idots_framework.inc.php b/phpgwapi/templates/idots/class.idots_framework.inc.php index c70b72a05b..596e49aa19 100644 --- a/phpgwapi/templates/idots/class.idots_framework.inc.php +++ b/phpgwapi/templates/idots/class.idots_framework.inc.php @@ -158,6 +158,12 @@ class idots_framework extends egw_framework $vars['current_users'] = $vars['quick_add'] = $vars['user_info']=''; } + // add the name of the current application as global js variable - the + // name of the current application can be obtained by using the + // jsapi egw_getAppName() function + $content .= ''."\n"; + $this->tpl->set_var($vars); $content .= $this->tpl->fp('out','navbar_header');