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; 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 **/ /** 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. // flag is not applied to container objects, it may lead to some strange behaviour.
var EGW_AO_FLAG_IS_CONTAINER = 0x01; 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 * The egwActionObject represents an abstract object to which actions may be
* applied. Communication with the DOM tree is established by using the * 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.parent != null)
{ {
if (this.getFocused() && !this.getSelected()) {
return this;
}
var idx = this.parent.children.indexOf(this); var idx = this.parent.children.indexOf(this);
if (idx > 0) if (idx > 0)
{ {
@ -1208,6 +1231,10 @@ egwActionObject.prototype.getNext = function(_intval)
{ {
if (this.parent != null) if (this.parent != null)
{ {
if (this.getFocused() && !this.getSelected()) {
return this;
}
var idx = this.parent.children.indexOf(this); var idx = this.parent.children.indexOf(this);
if (idx < this.parent.children.length - 1) if (idx < this.parent.children.length - 1)
{ {

View File

@ -49,7 +49,7 @@ function egwGridDataElement(_id, _parent, _columns, _readQueue, _objectManager)
if (!_parent) if (!_parent)
{ {
this.actionObject = this.parentActionObject.addObject(_id, null, 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); this.readQueue.setDataRoot(this);
} }

View File

@ -1506,7 +1506,7 @@ function egwGridViewRow__columnClick(_shiftState, _column)
break; break;
case EGW_SELECTMODE_TOGGLE: case EGW_SELECTMODE_TOGGLE:
this.aoi.updateState(EGW_AO_STATE_SELECTED, !isSelected, 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; break;
} }
} }

View File

@ -119,6 +119,26 @@ function egw_keycode_makeValid(_keyCode) {
return -1; 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 * Register the onkeypress handler on the document
*/ */
@ -135,6 +155,11 @@ $(document).ready(function() {
// Only go on if this is a valid key code - call the key handler // Only go on if this is a valid key code - call the key handler
if (keyCode != -1) if (keyCode != -1)
{
// 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 (egw_keyHandler(keyCode, e.shiftKey, e.ctrlKey || e.metaKey, e.altKey)) if (egw_keyHandler(keyCode, e.shiftKey, e.ctrlKey || e.metaKey, e.altKey))
{ {
@ -143,6 +168,7 @@ $(document).ready(function() {
e.preventDefault(); e.preventDefault();
} }
} }
}
}); });
}); });
@ -223,7 +249,36 @@ function egw_keyHandler(_keyCode, _shift, _ctrl, _alt) {
// Get the object manager and fetch the container of the currently // Get the object manager and fetch the container of the currently
// focused object // focused object
var focusedObject = egw_getObjectManager().getFocusedObject(); var appMgr = egw_getAppObjectManager(false);
if (appMgr)
{
var focusedObject = appMgr.getFocusedObject();
if (!focusedObject)
{
// 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) if (focusedObject)
{ {
var cntr = focusedObject.getContainerRoot(); var cntr = focusedObject.getContainerRoot();
@ -232,6 +287,7 @@ function egw_keyHandler(_keyCode, _shift, _ctrl, _alt) {
return cntr.handleKeyPress(_keyCode, _shift, _ctrl, _alt); return cntr.handleKeyPress(_keyCode, _shift, _ctrl, _alt);
} }
} }
}
} }

View File

@ -189,6 +189,21 @@ function egw_getApp(_name)
return window.parent.framework.getApplicationByName(_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 * 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']=''; $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); $this->tpl->set_var($vars);
$content .= $this->tpl->fp('out','navbar_header'); $content .= $this->tpl->fp('out','navbar_header');