Added possibility for egw_json plugins to be executed in the context of the creator of the request object

This commit is contained in:
Andreas Stöckel 2011-08-15 14:26:37 +00:00
parent fd21e247a1
commit c999373490

View File

@ -9,6 +9,11 @@
* @version $Id$
*/
/*egw:uses
jsapi.jsapi; // Contains some helper functions
jquery.jquery; // Used for the ajax requests
*/
/* The egw_json_request is the javaScript side implementation of class.egw_json.inc.php.*/
function _egw_json_escape_string(input)
@ -164,12 +169,19 @@ function egw_json_register_plugin(_callback, _context)
/**
* Function used internally to pass a response to all registered plugins
*/
function _egw_json_plugin_handle(_type, _response) {
function _egw_json_plugin_handle(_type, _response, _context) {
for (var i = 0; i < _egw_json_plugins.length; i++)
{
try {
var plugin = _egw_json_plugins[i];
if (plugin.callback.call(plugin.context, _type, _response)) {
var context = plugin.context;
if (!plugin.context && typeof _context != "undefined")
{
context = _context;
}
if (plugin.callback.call(context, _type, _response)) {
return true;
}
} catch (e) {
@ -532,7 +544,7 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
}
//Try to handle the json response with all registered plugins
hasResponse |= _egw_json_plugin_handle(data.response[i].type, res);
hasResponse |= _egw_json_plugin_handle(data.response[i].type, res, this.context);
} catch(e) {
this.jsonError('Internal JSON handler error', e);
}