Only call request callback once, when the request is finished.

Callback is not called if the response only has 'data' type responses, since data handler calls callback already.
This commit is contained in:
Nathan Gray 2014-01-11 14:47:31 +00:00
parent c8cfe6464e
commit 8e69a1e23b
2 changed files with 13 additions and 8 deletions

View File

@ -130,10 +130,15 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
}, this);
return;
}
// Flag for only data response - don't call callback if only data
var only_data = true;
for (var i = 0; i < data.response.length; i++)
{
// Get the response object
var res = data.response[i];
if(typeof res.type == 'string' && res.type != 'data') only_data = false;
// Check whether a plugin for the given type exists
if (typeof plugins[res.type] !== 'undefined')
@ -148,14 +153,6 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
plugin.context ? plugin.context : this.context,
res.type, res, this
);
// Call request callback, if provided
// Data is special, don't do the callback for it
if(this.callback != null && res.type != "data")
{
this.callback.call(this.context,res);
}
} catch(e) {
var msg = e.message ? e.message : e + '';
var stack = e.stack ? "\n-- Stack trace --\n" + e.stack : ""
@ -164,6 +161,11 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
}
}
}
// Call request callback, if provided
if(this.callback != null && !only_data)
{
this.callback.call(this.context,res);
}
}
}

View File

@ -44,6 +44,9 @@ egw.extend('jsonq', egw.MODULE_GLOBAL, function() {
function jsonq_callback(_data)
{
if (typeof _data != 'object') throw "jsonq_callback called with NO object as parameter!";
// Abort if type is set (multi-response support)
if (typeof _data.type != 'undefined') return;
var json = egw.json('none');
for(var uid in _data)