Updated aoi code, prevented unwanted browser selection, row is only selectable when a checkbox is found

This commit is contained in:
Andreas Stöckel 2011-03-22 19:55:57 +00:00
parent f6d0edbdc1
commit 20b769678f

View File

@ -1,5 +1,20 @@
/**
* eGroupWare eTemplate nextmatch row action object interface
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link http://www.egroupware.org
* @author Andreas Stöckel (as AT stylite.de)
* @version $Id$
*/
// An action object interface for the listbox - "inherits" from /**
* Contains the action object interface implementation for the nextmatch widget
* row.
*/
// An action object interface for each nextmatch widget row - "inherits" from
// egwActionObjectInterface // egwActionObjectInterface
function nextmatchRowAOI(_node) function nextmatchRowAOI(_node)
{ {
@ -8,36 +23,53 @@ function nextmatchRowAOI(_node)
aoi.node = _node; aoi.node = _node;
aoi.checkBox = ($(":checkbox", aoi.node))[0]; aoi.checkBox = ($(":checkbox", aoi.node))[0];
aoi.checkBox.checked = false;
aoi.doGetDOMNode = function() { // Rows without a checkbox are unselectable
return aoi.node; if (typeof aoi.checkBox != "undefined")
} {
aoi.doGetDOMNode = function() {
// Now append some action code to the node return aoi.node;
$(_node).click(function(e) {
if (e.target != aoi.checkBox)
{
var selected = egwBitIsSet(aoi.getState(), EGW_AO_STATE_SELECTED);
var state = egwGetShiftState(e);
aoi.updateState(EGW_AO_STATE_SELECTED,
!egwBitIsSet(state, EGW_AO_SHIFT_STATE_MULTI) || !selected,
state);
} }
});
$(aoi.checkBox).change(function() { // Prevent the browser from selecting the content of the element, when
aoi.updateState(EGW_AO_STATE_SELECTED, this.checked, EGW_AO_SHIFT_STATE_MULTI); // a special key is pressed.
}); $(_node).mousedown(egwPreventSelect);
aoi.doSetState = function(_state) { // Now append some action code to the node
var selected = egwBitIsSet(_state, EGW_AO_STATE_SELECTED); $(_node).click(function(e) {
this.checkBox.checked = selected;
$(this.node).toggleClass('focused', // Reset the prevent selection code (in order to allow wanted
egwBitIsSet(_state, EGW_AO_STATE_FOCUSED)); // selection of text)
$(this.node).toggleClass('selected', _node.onselectstart = null;
selected);
if (e.target != aoi.checkBox)
{
var selected = egwBitIsSet(aoi.getState(), EGW_AO_STATE_SELECTED);
var state = egwGetShiftState(e);
aoi.updateState(EGW_AO_STATE_SELECTED,
!egwBitIsSet(state, EGW_AO_SHIFT_STATE_MULTI) || !selected,
state);
}
});
$(aoi.checkBox).change(function() {
aoi.updateState(EGW_AO_STATE_SELECTED, this.checked, EGW_AO_SHIFT_STATE_MULTI);
});
aoi.doSetState = function(_state) {
var selected = egwBitIsSet(_state, EGW_AO_STATE_SELECTED);
if (this.checkBox)
{
this.checkBox.checked = selected;
}
$(this.node).toggleClass('focused',
egwBitIsSet(_state, EGW_AO_STATE_FOCUSED));
$(this.node).toggleClass('selected',
selected);
}
} }
return aoi; return aoi;