Implemented default focusing of objects in the tab manager, added new egw_getAppName function on js side, which returns the name of the currently active application - this is needed for the keyboard handler to pass the key events to the correct application object manager.

This commit is contained in:
Andreas Stöckel 2011-06-15 20:54:58 +00:00
parent 509ff8aa53
commit 9db8424e15
6 changed files with 115 additions and 11 deletions

View File

@ -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)
{

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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
*

View File

@ -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 .= '<script type="tex/javascript">window.egw_appName = "'.
$GLOBALS['egw_info']['flags']['currentapp'].'";</script>'."\n";
$this->tpl->set_var($vars);
$content .= $this->tpl->fp('out','navbar_header');