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-06-15 17:49:05 +02:00
|
|
|
var EGW_SELECTMODE_DEFAULT = 0;
|
|
|
|
var EGW_SELECTMODE_TOGGLE = 1;
|
|
|
|
|
2011-04-17 11:52:54 +02:00
|
|
|
/**
|
|
|
|
* An action object interface for each nextmatch widget row - "inherits" from
|
|
|
|
* egwActionObjectInterface
|
|
|
|
*/
|
2011-06-15 17:49:05 +02:00
|
|
|
function nextmatchRowAOI(_node, _selectMode)
|
2011-03-22 18:06:02 +01:00
|
|
|
{
|
|
|
|
var aoi = new egwActionObjectInterface();
|
|
|
|
|
|
|
|
aoi.node = _node;
|
2011-06-15 17:49:05 +02:00
|
|
|
aoi.selectMode = _selectMode;
|
2011-03-22 18:06:02 +01:00
|
|
|
|
2011-07-03 11:12:55 +02:00
|
|
|
aoi.checkBox = ($j(":checkbox", aoi.node))[0];
|
2011-03-22 18:06:02 +01:00
|
|
|
|
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.
|
2011-07-03 11:12:55 +02:00
|
|
|
$j(_node).mousedown(egwPreventSelect);
|
2011-03-22 20:55:57 +01:00
|
|
|
|
|
|
|
// Now append some action code to the node
|
2011-06-03 00:50:35 +02:00
|
|
|
selectHandler = function(e) {
|
2011-03-22 20:55:57 +01:00
|
|
|
|
2011-06-16 22:43:33 +02:00
|
|
|
// Reset the focus so that keyboard navigation will work properly
|
|
|
|
// after the element has been clicked
|
|
|
|
egwUnfocus();
|
|
|
|
|
2011-03-22 20:55:57 +01:00
|
|
|
// 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);
|
|
|
|
|
2011-06-15 17:49:05 +02:00
|
|
|
switch (aoi.selectMode)
|
|
|
|
{
|
|
|
|
case EGW_SELECTMODE_DEFAULT:
|
|
|
|
aoi.updateState(EGW_AO_STATE_SELECTED,
|
|
|
|
!egwBitIsSet(state, EGW_AO_SHIFT_STATE_MULTI) || !selected,
|
|
|
|
state);
|
|
|
|
break;
|
|
|
|
case EGW_SELECTMODE_TOGGLE:
|
|
|
|
aoi.updateState(EGW_AO_STATE_SELECTED, !selected,
|
2011-06-15 22:50:24 +02:00
|
|
|
egwSetBit(state, EGW_AO_SHIFT_STATE_MULTI, true));
|
2011-06-15 17:49:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-03-22 20:55:57 +01:00
|
|
|
}
|
2011-06-03 00:50:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (egwIsMobile()) {
|
|
|
|
_node.ontouchend = selectHandler;
|
|
|
|
} else {
|
2011-07-03 11:12:55 +02:00
|
|
|
$j(_node).click(selectHandler);
|
2011-06-03 00:50:35 +02:00
|
|
|
}
|
2011-03-22 20:55:57 +01:00
|
|
|
|
2011-07-03 11:12:55 +02:00
|
|
|
$j(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
|
2011-07-03 11:12:55 +02:00
|
|
|
$j(aoi.checkBox).dblclick(function() {
|
2011-03-23 21:07:07 +01:00
|
|
|
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-07-03 11:12:55 +02:00
|
|
|
$j(this.node).toggleClass('focused',
|
2011-03-22 20:55:57 +01:00
|
|
|
egwBitIsSet(_state, EGW_AO_STATE_FOCUSED));
|
2011-07-03 11:12:55 +02:00
|
|
|
$j(this.node).toggleClass('selected',
|
2011-03-22 20:55:57 +01:00
|
|
|
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)
|
|
|
|
{
|
2011-04-27 09:49:46 +02:00
|
|
|
// ignore checkboxes, unless they have an explicit defined nm_action
|
|
|
|
if (_action.checkbox && (!_action.data || typeof _action.data.nm_action == 'undefined')) return;
|
|
|
|
|
2011-04-16 23:45:13 +02:00
|
|
|
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) ? "," : "");
|
|
|
|
}
|
2011-04-17 20:53:45 +02:00
|
|
|
//console.log(_action); console.log(_senders);
|
2011-04-16 23:45:13 +02:00
|
|
|
|
2011-06-02 16:49:56 +02:00
|
|
|
var mgr = _action.getManager();
|
|
|
|
|
|
|
|
var select_all = mgr.getActionById("select_all");
|
2011-04-27 09:49:46 +02:00
|
|
|
var confirm_msg = (_senders.length > 1 || select_all && select_all.checked) &&
|
2011-04-25 14:15:05 +02:00
|
|
|
typeof _action.data.confirm_multiple != 'undefined' ?
|
|
|
|
_action.data.confirm_multiple : _action.data.confirm;
|
2011-04-17 20:53:45 +02:00
|
|
|
|
|
|
|
// let user confirm the action first (if not select_all set and nm_action == 'submit' --> confirmed later)
|
2011-04-27 09:49:46 +02:00
|
|
|
if (!(select_all && select_all.checked && _action.data.nm_action == 'submit') &&
|
2011-04-17 20:53:45 +02:00
|
|
|
typeof _action.data.confirm != 'undefined')
|
2011-04-16 23:45:13 +02:00
|
|
|
{
|
2011-04-17 20:53:45 +02:00
|
|
|
if (!confirm(confirm_msg)) return;
|
2011-04-16 23:45:13 +02:00
|
|
|
}
|
2011-06-30 19:35:52 +02:00
|
|
|
// in case we only need to confirm multiple selected (only _action.data.confirm_multiple)
|
|
|
|
else if (typeof _action.data.confirm_multiple != 'undefined' && (_senders.length > 1 || select_all && select_all.checked))
|
|
|
|
{
|
|
|
|
if (!confirm(_action.data.confirm_multiple)) return;
|
|
|
|
}
|
2011-04-16 23:45:13 +02:00
|
|
|
|
|
|
|
var url = '#';
|
|
|
|
if (typeof _action.data.url != 'undefined')
|
|
|
|
{
|
2011-09-06 08:23:54 +02:00
|
|
|
url = _action.data.url.replace(/(\$|%24)id/,encodeURIComponent(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':
|
2012-01-09 23:09:11 +01:00
|
|
|
if (typeof _action.data.targetapp != 'undefined')
|
|
|
|
{
|
|
|
|
top.egw_appWindowOpen(_action.data.targetapp, url);
|
|
|
|
}
|
|
|
|
else if(target)
|
2011-06-06 22:22:49 +02:00
|
|
|
{
|
|
|
|
window.open(url, target);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.href = url;
|
|
|
|
}
|
2011-04-16 23:45:13 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'popup':
|
|
|
|
egw_openWindowCentered2(url,target,_action.data.width,_action.data.height);
|
|
|
|
break;
|
|
|
|
|
2011-06-02 22:03:34 +02:00
|
|
|
case 'egw_open':
|
|
|
|
var params = _action.data.egw_open.split('-'); // type-appname-idNum (idNum is part of id split by :), eg. "edit-infolog"
|
|
|
|
console.log(params);
|
|
|
|
var egw_open_id = _senders[0].id;
|
|
|
|
if (typeof params[2] != 'undefined') egw_open_id = egw_open_id.split(':')[params[2]];
|
|
|
|
egw_open(egw_open_id,params[1],params[0],params[3]);
|
|
|
|
break;
|
|
|
|
|
2011-05-07 10:47:58 +02:00
|
|
|
case 'open_popup':
|
|
|
|
// open div styled as popup contained in current form and named action.id+'_popup'
|
2011-08-09 16:25:16 +02:00
|
|
|
if (nm_popup_action == null)
|
2011-05-07 10:47:58 +02:00
|
|
|
{
|
|
|
|
nm_open_popup(_action, _senders);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through, if popup is open --> submit form
|
2011-04-16 23:45:13 +02:00
|
|
|
case 'submit':
|
2011-04-17 20:53:45 +02:00
|
|
|
// let user confirm select-all
|
2011-04-27 09:49:46 +02:00
|
|
|
if (select_all && select_all.checked)
|
2011-04-17 20:53:45 +02:00
|
|
|
{
|
2011-06-03 20:45:40 +02:00
|
|
|
if (!confirm((confirm_msg ? confirm_msg : _action.caption.replace(/^( | | )+/,''))+"\n\n"+select_all.hint)) return;
|
2011-04-17 20:53:45 +02:00
|
|
|
}
|
2011-06-02 16:49:56 +02:00
|
|
|
var checkboxes = mgr.getActionsByAttr("checkbox", true);
|
|
|
|
var checkboxes_elem = document.getElementById(mgr.etemplate_var_prefix+'[nm][checkboxes]');
|
2011-04-27 09:49:46 +02:00
|
|
|
if (checkboxes && checkboxes_elem)
|
|
|
|
for (var i in checkboxes)
|
|
|
|
checkboxes_elem.value += checkboxes[i].id + ":" + (checkboxes[i].checked ? "1" : "0") + ";";
|
|
|
|
|
2011-06-02 16:49:56 +02:00
|
|
|
document.getElementById(mgr.etemplate_var_prefix+'[nm][nm_action]').value = _action.id;
|
|
|
|
document.getElementById(mgr.etemplate_var_prefix+'[nm][selected]').value = ids;
|
2011-04-16 23:45:13 +02:00
|
|
|
if (typeof _action.data.button != 'undefined')
|
|
|
|
{
|
2011-06-02 16:49:56 +02:00
|
|
|
submitit(mgr.etemplate_form.context, mgr.etemplate_var_prefix+'[nm][rows]['+_action.data.button+']['+ids+']');
|
2011-04-16 23:45:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-02 16:49:56 +02:00
|
|
|
mgr.etemplate_form.submit();
|
2011-04-16 23:45:13 +02:00
|
|
|
}
|
2011-05-17 21:13:55 +02:00
|
|
|
// Clear action in case there's another one
|
2011-06-02 16:49:56 +02:00
|
|
|
document.getElementById(mgr.etemplate_var_prefix+'[nm][nm_action]').value = null;
|
2011-05-17 21:13:55 +02:00
|
|
|
|
2011-04-16 23:45:13 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-04-17 20:53:45 +02:00
|
|
|
|
2011-04-17 22:45:21 +02:00
|
|
|
/**
|
|
|
|
* Callback to check if none of _senders rows has disableClass set
|
|
|
|
*
|
|
|
|
* @param _action egwAction object, we use _action.data.disableClass to check
|
|
|
|
* @param _senders array of egwActionObject objects
|
|
|
|
* @param _target egwActionObject object, get's called for every object in _senders
|
|
|
|
* @returns boolean true if none has disableClass, false otherwise
|
|
|
|
*/
|
|
|
|
function nm_not_disableClass(_action, _senders, _target)
|
|
|
|
{
|
2011-07-03 11:12:55 +02:00
|
|
|
return !$j(_target.iface.getDOMNode()).hasClass(_action.data.disableClass);
|
2011-04-17 22:45:21 +02:00
|
|
|
}
|
2011-04-25 16:13:40 +02:00
|
|
|
|
2011-04-27 18:54:35 +02:00
|
|
|
/**
|
|
|
|
* Callback to check if all of _senders rows have enableClass set
|
|
|
|
*
|
|
|
|
* @param _action egwAction object, we use _action.data.enableClass to check
|
|
|
|
* @param _senders array of egwActionObject objects
|
|
|
|
* @param _target egwActionObject object, get's called for every object in _senders
|
|
|
|
* @returns boolean true if none has disableClass, false otherwise
|
|
|
|
*/
|
|
|
|
function nm_enableClass(_action, _senders, _target)
|
|
|
|
{
|
2011-07-03 11:12:55 +02:00
|
|
|
return $j(_target.iface.getDOMNode()).hasClass(_action.data.enableClass);
|
2011-04-27 18:54:35 +02:00
|
|
|
}
|
|
|
|
|
2011-06-02 22:03:34 +02:00
|
|
|
/**
|
|
|
|
* Enable an _action, if it matches a given regular expresstion in _action.data.enableId
|
|
|
|
*
|
|
|
|
* @param _action egwAction object, we use _action.data.enableId to check
|
|
|
|
* @param _senders array of egwActionObject objects
|
|
|
|
* @param _target egwActionObject object, get's called for every object in _senders
|
|
|
|
* @returns boolean true if _target.id matches _action.data.enableId
|
|
|
|
*/
|
|
|
|
function nm_enableId(_action, _senders, _target)
|
|
|
|
{
|
|
|
|
if (typeof _action.data.enableId == 'string')
|
|
|
|
_action.data.enableId = new RegExp(_action.data.enableId);
|
|
|
|
|
|
|
|
return _target.id.match(_action.data.enableId);
|
|
|
|
}
|
|
|
|
|
2011-04-25 16:13:40 +02:00
|
|
|
/**
|
|
|
|
* Callback to check if a certain field (_action.data.fieldId) is (not) equal to given value (_action.data.fieldValue)
|
|
|
|
*
|
|
|
|
* If field is not found, we return false too!
|
|
|
|
*
|
|
|
|
* @param _action egwAction object, we use _action.data.fieldId to check agains _action.data.fieldValue
|
|
|
|
* @param _senders array of egwActionObject objects
|
|
|
|
* @param _target egwActionObject object, get's called for every object in _senders
|
|
|
|
* @returns boolean true if field found and has specified value, false otherwise
|
|
|
|
*/
|
|
|
|
function nm_compare_field(_action, _senders, _target)
|
|
|
|
{
|
|
|
|
var field = document.getElementById(_action.data.fieldId);
|
|
|
|
|
|
|
|
if (!field) return false;
|
|
|
|
|
2011-07-03 11:12:55 +02:00
|
|
|
var value = $j(field).val();
|
2011-04-25 16:13:40 +02:00
|
|
|
|
|
|
|
if (_action.data.fieldValue.substr(0,1) == '!')
|
|
|
|
return value != _action.data.fieldValue.substr(1);
|
|
|
|
|
|
|
|
return value == _action.data.fieldValue;
|
|
|
|
}
|
2011-05-07 10:47:58 +02:00
|
|
|
|
2011-08-09 16:25:16 +02:00
|
|
|
var nm_popup_action, nm_popup_senders = null;
|
2011-05-07 10:47:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open popup for a certain action requiring further input
|
|
|
|
*
|
|
|
|
* Popup needs to have eTemplate name of action id plus "_popup"
|
|
|
|
*
|
|
|
|
* @param _action
|
|
|
|
* @param _senders
|
|
|
|
*/
|
|
|
|
function nm_open_popup(_action, _senders)
|
|
|
|
{
|
2011-06-02 16:49:56 +02:00
|
|
|
var popup = document.getElementById(_action.getManager().etemplate_var_prefix + '[' + _action.id + '_popup]');
|
2011-05-07 10:47:58 +02:00
|
|
|
|
|
|
|
if (popup) {
|
|
|
|
nm_popup_action = _action;
|
|
|
|
nm_popup_senders = _senders;
|
|
|
|
popup.style.display = 'block';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit a popup action
|
|
|
|
*/
|
|
|
|
function nm_submit_popup(button)
|
|
|
|
{
|
|
|
|
button.form.submit_button.value = button.name; // set name of button (sub-action)
|
|
|
|
|
|
|
|
// call regular nm_action to transmit action and senders correct
|
|
|
|
nm_action(nm_popup_action, nm_popup_senders);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide popup
|
|
|
|
*/
|
|
|
|
function nm_hide_popup(element, div_id)
|
|
|
|
{
|
|
|
|
var prefix = element.id.substring(0,element.id.indexOf('['));
|
|
|
|
var popup = document.getElementById(prefix+'['+div_id+']');
|
|
|
|
|
|
|
|
// Hide popup
|
|
|
|
if(popup) {
|
|
|
|
popup.style.display = 'none';
|
|
|
|
}
|
2011-08-09 16:25:16 +02:00
|
|
|
nm_popup_action = null;
|
|
|
|
nm_popup_senders = null;
|
2011-05-07 10:47:58 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-30 14:43:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Activate/click first link in row
|
|
|
|
*/
|
|
|
|
function nm_activate_link(_action, _senders)
|
|
|
|
{
|
2011-07-03 11:12:55 +02:00
|
|
|
// $j(_senders[0].iface.getDOMNode()).find('a:first').trigger('click'); not sure why this is NOT working
|
2012-03-13 12:06:45 +01:00
|
|
|
|
|
|
|
var a_href = $j(_senders[0].iface.getDOMNode()).find('a:first');
|
|
|
|
|
|
|
|
if (typeof a_href != undefined)
|
|
|
|
{
|
|
|
|
var target = a_href.attr('target');
|
|
|
|
var href = a_href.attr('href');
|
|
|
|
if (a_href.attr('onclick'))
|
|
|
|
a_href.click();
|
|
|
|
else if (target)
|
|
|
|
window.open(href,target);
|
|
|
|
else
|
|
|
|
window.location = href;
|
|
|
|
}
|
2011-06-30 14:43:04 +02:00
|
|
|
}
|