2011-03-22 20:55:57 +01:00
|
|
|
/**
|
2011-04-17 11:52:54 +02:00
|
|
|
* EGroupware eTemplate nextmatch row action object interface
|
2011-03-22 20:55:57 +01:00
|
|
|
*
|
|
|
|
* @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)
|
2011-04-17 11:52:54 +02:00
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
2011-03-22 20:55:57 +01:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
2011-03-22 18:06:02 +01:00
|
|
|
|
2011-03-22 20:55:57 +01:00
|
|
|
/**
|
|
|
|
* Contains the action object interface implementation for the nextmatch widget
|
|
|
|
* row.
|
|
|
|
*/
|
|
|
|
|
2011-04-17 11:52:54 +02:00
|
|
|
/**
|
|
|
|
* An action object interface for each nextmatch widget row - "inherits" from
|
|
|
|
* egwActionObjectInterface
|
|
|
|
*/
|
2011-03-22 18:06:02 +01:00
|
|
|
function nextmatchRowAOI(_node)
|
|
|
|
{
|
|
|
|
var aoi = new egwActionObjectInterface();
|
|
|
|
|
|
|
|
aoi.node = _node;
|
|
|
|
|
|
|
|
aoi.checkBox = ($(":checkbox", aoi.node))[0];
|
|
|
|
|
2011-04-16 23:45:13 +02:00
|
|
|
// Rows without a checkbox OR an id set are unselectable
|
|
|
|
if (typeof aoi.checkBox != "undefined" || _node.id)
|
2011-03-22 20:55:57 +01:00
|
|
|
{
|
|
|
|
aoi.doGetDOMNode = function() {
|
|
|
|
return aoi.node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent the browser from selecting the content of the element, when
|
|
|
|
// a special key is pressed.
|
|
|
|
$(_node).mousedown(egwPreventSelect);
|
|
|
|
|
|
|
|
// Now append some action code to the node
|
|
|
|
$(_node).click(function(e) {
|
|
|
|
|
|
|
|
// Reset the prevent selection code (in order to allow wanted
|
|
|
|
// selection of text)
|
|
|
|
_node.onselectstart = null;
|
|
|
|
|
|
|
|
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() {
|
2011-03-23 21:07:07 +01:00
|
|
|
aoi.updateState(EGW_AO_STATE_SELECTED, this.checked, EGW_AO_SHIFT_STATE_MULTI);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't execute the default action when double clicking on an entry
|
|
|
|
$(aoi.checkBox).dblclick(function() {
|
|
|
|
return false;
|
|
|
|
});
|
2011-03-22 20:55:57 +01:00
|
|
|
|
|
|
|
aoi.doSetState = function(_state) {
|
|
|
|
var selected = egwBitIsSet(_state, EGW_AO_STATE_SELECTED);
|
2011-03-22 18:06:02 +01:00
|
|
|
|
2011-03-22 20:55:57 +01:00
|
|
|
if (this.checkBox)
|
|
|
|
{
|
|
|
|
this.checkBox.checked = selected;
|
|
|
|
}
|
2011-03-22 18:06:02 +01:00
|
|
|
|
2011-03-22 20:55:57 +01:00
|
|
|
$(this.node).toggleClass('focused',
|
|
|
|
egwBitIsSet(_state, EGW_AO_STATE_FOCUSED));
|
|
|
|
$(this.node).toggleClass('selected',
|
|
|
|
selected);
|
2011-03-22 18:06:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aoi;
|
|
|
|
}
|
|
|
|
|
2011-04-16 23:45:13 +02:00
|
|
|
/**
|
2011-04-17 11:52:54 +02:00
|
|
|
* Default action for nextmatch rows, runs action specified _action.data.nm_action: see nextmatch_widget::egw_actions()
|
2011-04-16 23:45:13 +02:00
|
|
|
*
|
|
|
|
* @param _action action object with attributes caption, id, nm_action, ...
|
|
|
|
* @param _senders array of rows selected
|
|
|
|
*/
|
|
|
|
function nm_action(_action, _senders)
|
|
|
|
{
|
|
|
|
if (typeof _action.data == 'undefined' || !_action.data) _action.data = {};
|
|
|
|
if (typeof _action.data.nm_action == 'undefined') _action.data.nm_action = 'submit';
|
|
|
|
|
|
|
|
var ids = "";
|
|
|
|
for (var i = 0; i < _senders.length; i++)
|
|
|
|
{
|
|
|
|
ids += (_senders[i].id.indexOf(',') >= 0 ? '"'+_senders[i].id.replace(/"/g,'""')+'"' : _senders[i].id) +
|
|
|
|
((i < _senders.length - 1) ? "," : "");
|
|
|
|
}
|
|
|
|
console.log(_action);
|
|
|
|
console.log(_senders);
|
|
|
|
|
|
|
|
// let user confirm the action first
|
|
|
|
if (typeof _action.data.confirm != 'undefined')
|
|
|
|
{
|
|
|
|
if (!confirm(_action.data.confirm)) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var url = '#';
|
|
|
|
if (typeof _action.data.url != 'undefined')
|
|
|
|
{
|
2011-04-17 11:52:54 +02:00
|
|
|
url = _action.data.url.replace(/(\$|%24)id/,ids);
|
2011-04-16 23:45:13 +02:00
|
|
|
}
|
2011-04-17 18:53:24 +02:00
|
|
|
|
|
|
|
var target = null;
|
|
|
|
if (typeof _action.data.target != 'undefined')
|
|
|
|
{
|
|
|
|
target = _action.data.target;
|
|
|
|
}
|
2011-04-16 23:45:13 +02:00
|
|
|
|
|
|
|
switch(_action.data.nm_action)
|
|
|
|
{
|
|
|
|
case 'alert':
|
|
|
|
alert(_action.caption + " (\'" + _action.id + "\') executed on rows: " + ids);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'location':
|
|
|
|
window.location.href = url;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'popup':
|
|
|
|
egw_openWindowCentered2(url,target,_action.data.width,_action.data.height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'submit':
|
2011-04-17 18:53:24 +02:00
|
|
|
var form = document.getElementsByName("eTemplate")[0];
|
|
|
|
|
2011-04-16 23:45:13 +02:00
|
|
|
document.getElementById('exec[nm][action]').value = _action.id;
|
|
|
|
document.getElementById('exec[nm][selected]').value = ids;
|
|
|
|
if (typeof _action.data.button != 'undefined')
|
|
|
|
{
|
2011-04-17 18:53:24 +02:00
|
|
|
submitit(form.context, 'exec[nm][rows]['+_action.data.button+']['+ids+']');
|
2011-04-16 23:45:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-17 18:53:24 +02:00
|
|
|
form.submit();
|
2011-04-16 23:45:13 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|