2012-03-27 12:18:42 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS Nextmatch object
|
2012-03-27 12:18:42 +02: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
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
2014-09-04 10:29:02 +02:00
|
|
|
* @copyright Stylite AG 2012-14
|
2012-03-27 12:18:42 +02:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default action for nextmatch rows, runs action specified _action.data.nm_action: see nextmatch_widget::egw_actions()
|
2013-09-16 12:40:19 +02:00
|
|
|
*
|
2014-09-04 10:29:02 +02:00
|
|
|
* @param {egwAction} _action action object with attributes caption, id, nm_action, ...
|
|
|
|
* @param {array} _senders array of rows selected
|
|
|
|
* @param {object} _target
|
|
|
|
* @param {object} _ids attributs all and ids (array of string)
|
2012-03-27 12:18:42 +02:00
|
|
|
*/
|
2012-03-29 16:11:22 +02:00
|
|
|
function nm_action(_action, _senders, _target, _ids)
|
2012-03-27 12:18:42 +02:00
|
|
|
{
|
|
|
|
// ignore checkboxes, unless they have an explicit defined nm_action
|
|
|
|
if (_action.checkbox && (!_action.data || typeof _action.data.nm_action == 'undefined')) return;
|
|
|
|
|
|
|
|
if (typeof _action.data == 'undefined' || !_action.data) _action.data = {};
|
2013-04-01 20:19:59 +02:00
|
|
|
if (typeof _action.data.nm_action == 'undefined' && _action.type == 'popup') _action.data.nm_action = 'submit';
|
2012-03-29 16:11:22 +02:00
|
|
|
|
2013-03-20 23:20:05 +01:00
|
|
|
if(typeof _ids == 'undefined')
|
|
|
|
{
|
|
|
|
// Get IDs from nextmatch - nextmatch is in the top of the action tree
|
|
|
|
// @see et2_extension_nextmatch_controller._initActions()
|
|
|
|
var nm = null;
|
2013-04-13 21:00:13 +02:00
|
|
|
var action = _action;
|
2013-03-20 23:20:05 +01:00
|
|
|
while(nm == null && action != null)
|
|
|
|
{
|
|
|
|
if(action.data != null && action.data.nextmatch)
|
|
|
|
{
|
|
|
|
nm = action.data.nextmatch;
|
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
action = action.parent;
|
2013-03-20 23:20:05 +01:00
|
|
|
}
|
|
|
|
if(nm)
|
|
|
|
{
|
|
|
|
_ids = nm.getSelection();
|
|
|
|
_action.data.nextmatch = nm;
|
|
|
|
}
|
|
|
|
}
|
2017-09-11 19:10:47 +02:00
|
|
|
// row ids
|
2017-09-12 14:47:08 +02:00
|
|
|
var row_ids = "";
|
|
|
|
for (var i = 0; i < _ids.ids.length; i++)
|
|
|
|
{
|
|
|
|
var row_id = _ids.ids[i];
|
|
|
|
row_ids += (row_id.indexOf(',') >= 0 ? '"'+row_id.replace(/"/g,'""')+'"' : row_id) +
|
|
|
|
((i < _ids.ids.length - 1) ? "," : "");
|
|
|
|
}
|
|
|
|
|
2012-03-30 13:43:39 +02:00
|
|
|
// Translate the internal uids back to server uids
|
2012-03-29 16:11:22 +02:00
|
|
|
var idsArr = _ids.ids;
|
2012-03-30 13:43:39 +02:00
|
|
|
for (var i = 0; i < idsArr.length; i++)
|
|
|
|
{
|
2014-08-28 11:48:27 +02:00
|
|
|
// empty placeholder gets reported --> ignore it
|
|
|
|
if (!idsArr[i])
|
|
|
|
{
|
2014-09-01 18:53:59 +02:00
|
|
|
idsArr.splice(i,1);
|
|
|
|
continue;
|
2014-08-28 11:48:27 +02:00
|
|
|
}
|
2014-09-01 18:53:59 +02:00
|
|
|
idsArr[i] = idsArr[i].split("::").pop();
|
2012-03-30 13:43:39 +02:00
|
|
|
}
|
2012-03-29 16:11:22 +02:00
|
|
|
|
2012-03-30 13:43:39 +02:00
|
|
|
// Calculate the ids parameters
|
2012-03-27 12:18:42 +02:00
|
|
|
var ids = "";
|
2012-03-29 16:11:22 +02:00
|
|
|
for (var i = 0; i < idsArr.length; i++)
|
2012-03-27 12:18:42 +02:00
|
|
|
{
|
2012-03-30 13:43:39 +02:00
|
|
|
var id = idsArr[i];
|
2013-09-16 12:40:19 +02:00
|
|
|
ids += (id.indexOf(',') >= 0 ? '"'+id.replace(/"/g,'""')+'"' : id) +
|
2012-03-29 16:11:22 +02:00
|
|
|
((i < idsArr.length - 1) ? "," : "");
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
//console.log(_action); console.log(_senders);
|
|
|
|
|
|
|
|
var mgr = _action.getManager();
|
|
|
|
|
|
|
|
var url = '#';
|
|
|
|
if (typeof _action.data.url != 'undefined')
|
|
|
|
{
|
2014-07-07 18:46:16 +02:00
|
|
|
// Add selected IDs to url
|
|
|
|
url = _action.data.url.replace(/(\$|%24)id/,encodeURIComponent(ids))
|
|
|
|
// Include select all flag too
|
2017-09-11 19:10:47 +02:00
|
|
|
.replace(/(\$|%24)select_all/,_ids.all)
|
|
|
|
// Add row_ids to url
|
2017-09-12 14:47:08 +02:00
|
|
|
.replace(/(\$|%24)row_id/,encodeURIComponent(row_ids));
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var target = null;
|
|
|
|
if (typeof _action.data.target != 'undefined')
|
|
|
|
{
|
|
|
|
target = _action.data.target;
|
|
|
|
}
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2012-03-27 12:18:42 +02:00
|
|
|
switch(_action.data.nm_action)
|
|
|
|
{
|
|
|
|
case 'alert':
|
|
|
|
alert(_action.caption + " (\'" + _action.id + "\') executed on rows: " + ids);
|
|
|
|
break;
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2012-03-27 12:18:42 +02:00
|
|
|
case 'location':
|
|
|
|
if (typeof _action.data.targetapp != 'undefined')
|
|
|
|
{
|
|
|
|
top.egw_appWindowOpen(_action.data.targetapp, url);
|
2013-09-16 12:40:19 +02:00
|
|
|
}
|
2012-03-27 12:18:42 +02:00
|
|
|
else if(target)
|
|
|
|
{
|
2014-01-15 16:05:10 +01:00
|
|
|
egw.open_link(url, target, _action.data.width ? _action.data.width+'x'+_action.data.height : false);
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.href = url;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2012-03-27 12:18:42 +02:00
|
|
|
case 'popup':
|
2019-01-23 12:18:40 +01:00
|
|
|
|
|
|
|
// Accoring to microsoft, IE 10/11 can only accept a url with 2083 caharacters
|
|
|
|
// therefore we need to send request to compose window with POST method
|
|
|
|
// instead of GET. We create a temporary <Form> and will post emails.
|
|
|
|
// ** WebServers and other browsers also have url length limit:
|
|
|
|
// Firefox:~ 65k, Safari:80k, Chrome: 2MB, Apache: 4k, Nginx: 4k
|
|
|
|
if (url.length > 2083)
|
|
|
|
{
|
|
|
|
var $tmpForm = jQuery(document.createElement('form'));
|
|
|
|
var $tmpSubmitInput = jQuery(document.createElement('input')).attr({type:"submit"});
|
|
|
|
var params = url.split('&');
|
|
|
|
url = params[0];
|
|
|
|
for (var i=1;i<params.length;i++)
|
|
|
|
{
|
|
|
|
var values = params[i].split('=');
|
|
|
|
switch (values[0])
|
|
|
|
{
|
|
|
|
case 'cd':
|
|
|
|
case 'tz':
|
|
|
|
case 'menuaction':
|
|
|
|
case 'hasupdate':
|
|
|
|
url = url + '&' + values.join('=');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$tmpForm.append(jQuery(document.createElement('input')).attr({name:values[0], type:"text", value: values[1]}));
|
|
|
|
}
|
|
|
|
var postRequest = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var popup_window = egw.open_link(url,target,_action.data.width+'x'+_action.data.height);
|
|
|
|
|
|
|
|
if (postRequest)
|
|
|
|
{
|
|
|
|
popup_window.name = popup_window.name ? popup_window.name : 'postRequest';
|
|
|
|
// Set the temporary form's attributes
|
|
|
|
$tmpForm.attr({target:popup_window.name, action:url, method:"post"})
|
|
|
|
.append($tmpSubmitInput).appendTo('body');
|
|
|
|
$tmpForm.submit();
|
|
|
|
// Remove the form after submit
|
|
|
|
$tmpForm.remove();
|
|
|
|
}
|
2012-03-27 12:18:42 +02:00
|
|
|
break;
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2014-01-16 14:54:19 +01:00
|
|
|
case 'long_task':
|
|
|
|
// Run a long task once for each ID with a nice dialog instead of
|
|
|
|
// freezing for a while. If egw_open is set, and only 1 row selected,
|
|
|
|
// egw_open will be used instead.
|
2014-10-06 23:31:14 +02:00
|
|
|
if(doLongTask(idsArr, _ids.all,_action, mgr.data.nextmatch)) break;
|
2014-08-27 17:56:01 +02:00
|
|
|
|
2014-01-16 14:54:19 +01:00
|
|
|
// Fall through
|
2012-03-27 12:18:42 +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"
|
2014-01-15 16:05:10 +01:00
|
|
|
|
2013-02-05 10:14:14 +01:00
|
|
|
var egw_open_id = idsArr[0];
|
2014-01-15 16:05:10 +01:00
|
|
|
var type = params.shift();
|
|
|
|
var app = params.shift();
|
|
|
|
if (typeof params[2] != 'undefined')
|
|
|
|
{
|
|
|
|
if(egw_open_id.indexOf(':') >= 0)
|
|
|
|
{
|
|
|
|
egw_open_id = egw_open_id.split(':')[params.shift(params[2])];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-24 09:23:22 +01:00
|
|
|
// Discard , special handling when from=merge is involved
|
|
|
|
if(params.length>1 && params[0]=='' && params[1].indexOf('from=merge')!=-1)
|
|
|
|
{
|
|
|
|
params.shift();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params.shift(params[2]);
|
|
|
|
}
|
2014-01-15 16:05:10 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-24 09:23:22 +01:00
|
|
|
//special handling when from=merge is involved
|
|
|
|
if(params.length>1 && params[0]=='' && params[1].indexOf('from=merge')!=-1)
|
|
|
|
{
|
|
|
|
params.shift();
|
|
|
|
}
|
2014-01-15 16:05:10 +01:00
|
|
|
// Re-join, in case extra has a -
|
|
|
|
var extra = params.join('-');
|
|
|
|
egw(app,window).open(egw_open_id,app,type,extra,target);
|
2012-03-27 12:18:42 +02:00
|
|
|
break;
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2012-03-27 12:18:42 +02:00
|
|
|
case 'open_popup':
|
|
|
|
// open div styled as popup contained in current form and named action.id+'_popup'
|
|
|
|
if (nm_popup_action == null)
|
|
|
|
{
|
2012-04-18 00:56:04 +02:00
|
|
|
nm_open_popup(_action, _ids.ids);
|
2012-03-27 12:18:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through, if popup is open --> submit form
|
|
|
|
case 'submit':
|
|
|
|
var checkboxes = mgr.getActionsByAttr("checkbox", true);
|
2013-11-08 17:38:12 +01:00
|
|
|
var checkbox_values = {};
|
|
|
|
if (checkboxes)
|
2012-03-27 12:18:42 +02:00
|
|
|
for (var i in checkboxes)
|
2013-11-08 17:38:12 +01:00
|
|
|
checkbox_values[checkboxes[i].id] = checkboxes[i].checked;
|
2012-03-27 12:18:42 +02:00
|
|
|
|
2012-04-10 22:27:37 +02:00
|
|
|
var nextmatch = _action.data.nextmatch;
|
|
|
|
if(!nextmatch && _senders.length)
|
2012-03-27 12:18:42 +02:00
|
|
|
{
|
2012-04-10 22:27:37 +02:00
|
|
|
// Pull it from deep within, where it was stuffed in et2_dataview_controller_selection._attachActionObject()
|
|
|
|
nextmatch = _senders[0]._context._widget;
|
|
|
|
}
|
|
|
|
if(nextmatch)
|
|
|
|
{
|
|
|
|
// Fake a getValue() function
|
2013-08-19 22:23:26 +02:00
|
|
|
var old_value = nextmatch.getValue;
|
|
|
|
var value = nextmatch.getValue();
|
2019-05-15 00:43:15 +02:00
|
|
|
jQuery.extend(value, _action.data, this.activeFilters, {
|
2013-08-19 22:23:26 +02:00
|
|
|
"selected": idsArr,
|
2013-10-03 17:30:27 +02:00
|
|
|
"select_all": _ids.all,
|
2014-09-04 10:29:02 +02:00
|
|
|
"checkboxes": checkbox_values
|
2013-08-19 22:23:26 +02:00
|
|
|
});
|
2019-07-26 18:25:28 +02:00
|
|
|
// Skip this one, it would cause the nm to change ID on reload
|
|
|
|
delete value.id;
|
2013-08-19 22:23:26 +02:00
|
|
|
value[nextmatch.options.settings.action_var]= _action.id;
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2019-05-15 00:43:15 +02:00
|
|
|
// Don't try to send the nextmatch
|
|
|
|
delete value['nextmatch'];
|
|
|
|
|
2012-04-10 22:27:37 +02:00
|
|
|
nextmatch.getValue = function() {
|
|
|
|
return value;
|
2014-09-04 10:29:02 +02:00
|
|
|
};
|
2012-04-10 22:27:37 +02:00
|
|
|
|
2013-11-08 17:38:12 +01:00
|
|
|
|
2013-10-04 14:48:11 +02:00
|
|
|
// downloads need a regular submit via POST (no Ajax)
|
|
|
|
if (_action.data.postSubmit)
|
|
|
|
{
|
|
|
|
nextmatch.getInstanceManager().postSubmit();
|
2012-04-18 00:56:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-08 17:38:12 +01:00
|
|
|
nextmatch.getInstanceManager().submit();
|
2013-10-04 14:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(_action.data.nm_action == 'open_popup')
|
|
|
|
{
|
2014-02-19 23:02:09 +01:00
|
|
|
// Force nextmatch to re-load affected rows
|
|
|
|
// Must be after submit, so server gives us up to date info
|
|
|
|
// Otherwise, old info will be sent and could overwrite the new,
|
|
|
|
// depending on timing.
|
|
|
|
nextmatch.refresh(idsArr);
|
2014-08-27 17:56:01 +02:00
|
|
|
|
2013-10-04 14:48:11 +02:00
|
|
|
// Reset action in case there's another one
|
|
|
|
nextmatch.getValue = old_value;
|
2012-04-18 00:56:04 +02:00
|
|
|
}
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-10 22:27:37 +02:00
|
|
|
egw().debug("error", "Missing nextmatch widget, could not submit", _action);
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-09-22 21:39:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch all IDs to the client side, user wants to do something with them...
|
|
|
|
*
|
|
|
|
* @param {string[]} ids Array of selected IDs
|
|
|
|
* @param {et2_nextmatch} nextmatch
|
|
|
|
* @param {function} callback Callback function
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
function fetchAll(ids, nextmatch, callback)
|
|
|
|
{
|
|
|
|
if(!nextmatch || !nextmatch.controller) return false;
|
|
|
|
var selection = nextmatch.getSelection();
|
|
|
|
if(!selection.all) return false;
|
2014-03-04 21:35:41 +01:00
|
|
|
|
2014-09-22 21:39:50 +02:00
|
|
|
if(nextmatch.controller._grid && nextmatch.controller._grid.getTotalCount() > ids.length)
|
2014-03-04 21:35:41 +01:00
|
|
|
{
|
2014-09-22 21:39:50 +02:00
|
|
|
// Need to actually fetch all (TODO: just ids) to do this client side
|
|
|
|
var idsArr = [];
|
|
|
|
var count = idsArr.length;
|
|
|
|
var total = nextmatch.controller._grid.getTotalCount();
|
|
|
|
var cancel = false;
|
|
|
|
var dialog = et2_dialog.show_dialog(
|
|
|
|
// Abort the long task if they canceled the data load
|
|
|
|
function() {count = total; cancel=true;},
|
|
|
|
egw.lang('Loading'), egw.lang('please wait...'),{},[
|
2019-08-27 20:04:06 +02:00
|
|
|
{"button_id": et2_dialog.CANCEL_BUTTON,"text": egw.lang('cancel'),id: 'dialog[cancel]',image: 'cancel'}
|
2014-09-22 21:39:50 +02:00
|
|
|
]
|
|
|
|
);
|
2014-03-04 21:35:41 +01:00
|
|
|
|
2014-09-22 21:39:50 +02:00
|
|
|
// dataFetch() is asyncronous, so all these requests just get fired off...
|
|
|
|
// 200 rows chosen arbitrarily to reduce requests.
|
|
|
|
do {
|
|
|
|
nextmatch.controller.dataFetch({start:count, num_rows: 200}, function(data) {
|
|
|
|
if(data && data.order)
|
2014-03-04 21:35:41 +01:00
|
|
|
{
|
2014-09-22 21:39:50 +02:00
|
|
|
for(var i = 0; i < data.order.length; i++)
|
|
|
|
{
|
|
|
|
idsArr.push(data.order[i].split("::").pop());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update total, just in case it changed
|
|
|
|
if(data && data.total) total = data.total;
|
2014-03-04 21:35:41 +01:00
|
|
|
|
2014-09-22 21:39:50 +02:00
|
|
|
if(idsArr.length >= total)
|
|
|
|
{
|
|
|
|
dialog.destroy();
|
|
|
|
if(!cancel)
|
|
|
|
{
|
|
|
|
callback.call(this, idsArr);
|
|
|
|
}
|
2014-03-04 21:35:41 +01:00
|
|
|
}
|
2014-09-22 21:39:50 +02:00
|
|
|
},this);
|
|
|
|
count += 200;
|
|
|
|
} while (count < total)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch all IDs and run a long task.
|
2015-02-04 09:38:41 +01:00
|
|
|
*
|
2014-09-22 21:39:50 +02:00
|
|
|
* @param {String[]} idsArr Array of IDs
|
|
|
|
* @param {boolean} all True if all IDs are selected. They'll have to be fetched if missing.
|
|
|
|
* @param {type} _action
|
|
|
|
* @param {et2_nextmatch} nextmatch
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
function doLongTask(idsArr, all, _action, nextmatch)
|
|
|
|
{
|
|
|
|
if(all || idsArr.length > 1 || typeof _action.data.egw_open == 'undefined')
|
|
|
|
{
|
|
|
|
if(all)
|
|
|
|
{
|
|
|
|
var fetching = fetchAll(idsArr, nextmatch,function(idsArr){
|
|
|
|
et2_dialog.long_task(null,_action.data.message||_action.caption,_action.data.title,_action.data.menuaction,idsArr);
|
|
|
|
});
|
|
|
|
if(fetching) return true;
|
2014-03-04 21:35:41 +01:00
|
|
|
}
|
2014-09-22 21:39:50 +02:00
|
|
|
et2_dialog.long_task(null,_action.data.message||_action.caption,_action.data.title,_action.data.menuaction,idsArr);
|
|
|
|
return true;
|
2014-03-04 21:35:41 +01:00
|
|
|
}
|
2014-09-22 21:39:50 +02:00
|
|
|
return false;
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to check if a certain field (_action.data.fieldId) is (not) equal to given value (_action.data.fieldValue)
|
2013-09-16 12:40:19 +02:00
|
|
|
*
|
2012-03-27 12:18:42 +02:00
|
|
|
* If field is not found, we return false too!
|
2013-09-16 12:40:19 +02:00
|
|
|
*
|
2012-03-27 12:18:42 +02:00
|
|
|
* @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)
|
|
|
|
{
|
2013-06-10 21:26:04 +02:00
|
|
|
var value = false;
|
|
|
|
|
|
|
|
// This probably won't work...
|
2012-03-27 12:18:42 +02:00
|
|
|
var field = document.getElementById(_action.data.fieldId);
|
|
|
|
|
2013-06-10 21:26:04 +02:00
|
|
|
// Use widget
|
|
|
|
if (!field)
|
|
|
|
{
|
|
|
|
var nextmatch = _action.data.nextmatch;
|
|
|
|
if(!nextmatch && _senders.length)
|
|
|
|
{
|
|
|
|
// Pull it from deep within, where it was stuffed in et2_dataview_controller_selection._attachActionObject()
|
|
|
|
nextmatch = _senders[0]._context._widget;
|
|
|
|
}
|
|
|
|
if(!nextmatch) return false;
|
|
|
|
|
|
|
|
field = nextmatch.getWidgetById(_action.data.fieldId);
|
|
|
|
value = field.getValue();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
value = jQuery(field).val();
|
2013-06-10 21:26:04 +02:00
|
|
|
}
|
2012-03-27 12:18:42 +02:00
|
|
|
if (!field) return false;
|
|
|
|
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2012-03-27 12:18:42 +02:00
|
|
|
if (_action.data.fieldValue.substr(0,1) == '!')
|
|
|
|
return value != _action.data.fieldValue.substr(1);
|
2013-09-16 12:40:19 +02:00
|
|
|
|
2012-03-27 12:18:42 +02:00
|
|
|
return value == _action.data.fieldValue;
|
|
|
|
}
|
|
|
|
|
2012-03-29 16:11:22 +02:00
|
|
|
// TODO: This code is rather suboptimal! No global variables as this code will
|
|
|
|
// run in a global context
|
|
|
|
var nm_popup_action, nm_popup_ids = null;
|
2012-03-27 12:18:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open popup for a certain action requiring further input
|
2013-09-16 12:40:19 +02:00
|
|
|
*
|
2012-03-27 12:18:42 +02:00
|
|
|
* Popup needs to have eTemplate name of action id plus "_popup"
|
2013-09-16 12:40:19 +02:00
|
|
|
*
|
2014-09-01 18:30:31 +02:00
|
|
|
* @param {egwAction} _action
|
|
|
|
* @param {egwActionObject[]} _selected
|
2012-03-27 12:18:42 +02:00
|
|
|
*/
|
2014-09-01 18:30:31 +02:00
|
|
|
function nm_open_popup(_action, _selected)
|
2012-03-27 12:18:42 +02:00
|
|
|
{
|
2013-09-16 12:40:19 +02:00
|
|
|
//Check if there is nextmatch on _action otherwise gets the uniqueid from _ids
|
|
|
|
var uid;
|
|
|
|
if (typeof _action.data.nextmatch !== 'undefined')
|
|
|
|
uid = _action.data.nextmatch.getInstanceManager().uniqueId;
|
2014-09-01 18:30:31 +02:00
|
|
|
else if(typeof _selected[0] !== 'undefined')
|
|
|
|
uid = _selected[0].manager.data.nextmatch.getInstanceManager().uniqueId;
|
2013-08-21 00:23:18 +02:00
|
|
|
// Find the popup div
|
2013-09-16 12:40:19 +02:00
|
|
|
var popup = jQuery("#"+(uid||"") + "_"+_action.id+"_popup").first() || jQuery("[id*='" + _action.id + "_popup']").first();
|
2012-03-27 12:18:42 +02:00
|
|
|
if (popup) {
|
|
|
|
nm_popup_action = _action;
|
2014-09-01 18:30:31 +02:00
|
|
|
if(_selected.length && typeof _selected[0] == 'object')
|
2012-04-24 21:47:23 +02:00
|
|
|
{
|
2014-09-01 18:30:31 +02:00
|
|
|
_action.data.nextmatch = _selected[0]._context._widget;
|
2014-09-04 10:29:02 +02:00
|
|
|
nm_popup_ids = _selected;
|
2012-04-24 21:47:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-04 10:29:02 +02:00
|
|
|
egw().debug("warn", 'Not proper format for IDs, should be array of egwActionObject',_selected);
|
2014-09-01 20:44:13 +02:00
|
|
|
nm_popup_ids = _selected;
|
2012-04-24 21:47:23 +02:00
|
|
|
}
|
2012-05-03 00:33:46 +02:00
|
|
|
|
2012-04-18 00:56:04 +02:00
|
|
|
var dialog = jQuery('.action_popup-content',popup);
|
2012-05-30 00:23:02 +02:00
|
|
|
if(dialog.length == 0)
|
|
|
|
{
|
|
|
|
// Couldn't get the dialog, use the div less the first (header) & last (buttons) nodes
|
|
|
|
dialog = jQuery(document.createElement('div'))
|
|
|
|
.addClass('action_popup-content');
|
|
|
|
if(popup.children().length == 1)
|
|
|
|
{
|
|
|
|
dialog.append(popup.children().children().slice(1,popup.children().children().length-1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dialog.append(popup.children().slice(1,popup.children().length-1));
|
|
|
|
}
|
|
|
|
dialog.appendTo(popup);
|
|
|
|
}
|
|
|
|
if(dialog.length == 1)
|
2012-05-03 00:33:46 +02:00
|
|
|
{
|
2013-08-21 00:23:18 +02:00
|
|
|
// Set up the buttons
|
2012-05-03 00:33:46 +02:00
|
|
|
var dialog_parent = dialog.parent();
|
|
|
|
var d_buttons = [];
|
|
|
|
var action = _action;
|
2014-04-28 22:20:54 +02:00
|
|
|
popup.show();
|
2017-12-18 22:51:07 +01:00
|
|
|
var close_function = function()
|
|
|
|
{
|
|
|
|
dialog_parent.append(dialog);
|
|
|
|
};
|
2017-11-28 23:59:06 +01:00
|
|
|
jQuery('button:visible',popup).each(function(index) {
|
2012-05-03 00:33:46 +02:00
|
|
|
var but = jQuery(this);
|
2013-08-21 00:23:18 +02:00
|
|
|
if(but.attr("id"))
|
|
|
|
{
|
|
|
|
// Find the associated widget
|
|
|
|
var widget_id = but.attr("id").replace(_action.data.nextmatch.getInstanceManager().uniqueId+'_', '');
|
|
|
|
var button = nm_popup_action.data.nextmatch.getRoot().getWidgetById(widget_id);
|
|
|
|
}
|
2017-11-28 23:59:06 +01:00
|
|
|
var button_data = {
|
2012-05-03 00:33:46 +02:00
|
|
|
text: but.text(),
|
2017-11-28 23:59:06 +01:00
|
|
|
id: widget_id,
|
2013-08-21 00:23:18 +02:00
|
|
|
click: button && button.onclick ? function(e) {
|
2017-11-28 23:59:06 +01:00
|
|
|
jQuery(this).dialog("close");
|
2012-05-03 00:33:46 +02:00
|
|
|
nm_popup_action = action;
|
|
|
|
button.onclick.apply(button, e.currentTarget);
|
2017-12-18 22:51:07 +01:00
|
|
|
close_function();
|
2012-05-03 00:33:46 +02:00
|
|
|
} : function(e) {
|
2017-11-28 23:59:06 +01:00
|
|
|
jQuery(this).dialog("close");
|
2014-02-19 23:02:09 +01:00
|
|
|
nm_popup_action = null;
|
2017-12-18 22:51:07 +01:00
|
|
|
close_function();
|
2012-05-03 00:33:46 +02:00
|
|
|
}
|
2017-11-28 23:59:06 +01:00
|
|
|
};
|
|
|
|
if(button && button.options && button.options.image)
|
|
|
|
{
|
|
|
|
button_data.image = button.options.image;
|
2012-05-03 00:33:46 +02:00
|
|
|
}
|
2017-11-28 23:59:06 +01:00
|
|
|
d_buttons.push(button_data);
|
2012-04-18 00:56:04 +02:00
|
|
|
});
|
2017-11-28 23:59:06 +01:00
|
|
|
|
|
|
|
popup.hide();
|
2017-12-18 22:51:07 +01:00
|
|
|
var _dialog = et2_dialog.show_dialog(
|
|
|
|
close_function,
|
2017-11-28 23:59:06 +01:00
|
|
|
'',
|
|
|
|
jQuery('.promptheader',popup).text(),
|
|
|
|
{},
|
|
|
|
d_buttons
|
|
|
|
);
|
|
|
|
_dialog.set_dialog_type('');
|
|
|
|
_dialog.div.append(dialog)
|
|
|
|
.css('overflow', 'initial');
|
2012-05-03 00:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset global variables
|
|
|
|
nm_popup_action = null;
|
|
|
|
nm_popup_senders = null;
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit a popup action
|
2014-09-04 10:29:02 +02:00
|
|
|
*
|
|
|
|
* @param {DOMNode} button DOM node of button
|
2012-03-27 12:18:42 +02:00
|
|
|
*/
|
|
|
|
function nm_submit_popup(button)
|
|
|
|
{
|
2015-02-04 09:38:41 +01:00
|
|
|
if (nm_popup_action.data.nextmatch)
|
2012-04-18 00:56:04 +02:00
|
|
|
{
|
2013-08-21 00:23:18 +02:00
|
|
|
// Find the associated widget
|
2016-06-02 16:51:15 +02:00
|
|
|
var widget_id = jQuery(button).attr("id").replace(nm_popup_action.data.nextmatch.getInstanceManager().uniqueId+'_', '');
|
2013-08-21 00:23:18 +02:00
|
|
|
nm_popup_action.data.nextmatch.getRoot().getWidgetById(widget_id).clicked = true;
|
2012-04-18 00:56:04 +02:00
|
|
|
}
|
2012-03-27 12:18:42 +02:00
|
|
|
|
2012-04-10 22:27:37 +02:00
|
|
|
// Mangle senders to get IDs where nm_action() wants them
|
2014-09-01 18:30:31 +02:00
|
|
|
if(nm_popup_ids.length && typeof nm_popup_ids[0] != 'object')
|
2012-04-10 22:27:37 +02:00
|
|
|
{
|
2014-09-01 18:30:31 +02:00
|
|
|
// Legacy ID just as string
|
|
|
|
var ids = {ids:[]};
|
|
|
|
for(var i in nm_popup_ids)
|
|
|
|
{
|
|
|
|
if(nm_popup_ids[i])
|
|
|
|
ids.ids.push(nm_popup_ids[i]);
|
|
|
|
}
|
2012-04-10 22:27:37 +02:00
|
|
|
}
|
2014-09-01 18:30:31 +02:00
|
|
|
|
2012-03-27 12:18:42 +02:00
|
|
|
// call regular nm_action to transmit action and senders correct
|
2014-09-01 18:30:31 +02:00
|
|
|
nm_action(nm_popup_action,nm_popup_ids, button, ids );
|
2012-04-24 21:47:23 +02:00
|
|
|
|
|
|
|
nm_hide_popup(button, null);
|
2014-09-01 18:30:31 +02:00
|
|
|
nm_popup_ids = null;
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide popup
|
2014-09-04 10:29:02 +02:00
|
|
|
*
|
|
|
|
* @param {DOMNode} element
|
|
|
|
* @param {string} div_id
|
|
|
|
* @returns {Boolean}
|
2012-03-27 12:18:42 +02:00
|
|
|
*/
|
2013-09-16 12:40:19 +02:00
|
|
|
function nm_hide_popup(element, div_id)
|
2012-03-27 12:18:42 +02:00
|
|
|
{
|
|
|
|
var prefix = element.id.substring(0,element.id.indexOf('['));
|
2012-05-02 21:37:24 +02:00
|
|
|
var popup = div_id ? document.getElementById(div_id) : jQuery("#"+prefix+"_popup").get(0) || jQuery("[id*='" + prefix + "_popup']").get(0);
|
2012-03-27 12:18:42 +02:00
|
|
|
|
|
|
|
// Hide popup
|
|
|
|
if(popup) {
|
|
|
|
popup.style.display = 'none';
|
|
|
|
}
|
|
|
|
nm_popup_action = null;
|
|
|
|
nm_popup_senders = null;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activate/click first link in row
|
2014-09-04 10:29:02 +02:00
|
|
|
*
|
|
|
|
* @param {egwAction} _action
|
|
|
|
* @param {array} _senders of egwActionObject
|
2012-03-27 12:18:42 +02:00
|
|
|
*/
|
|
|
|
function nm_activate_link(_action, _senders)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(_senders[0].iface.getDOMNode()).find('.et2_clickable:first').trigger('click');
|
2012-03-27 12:18:42 +02:00
|
|
|
}
|