From 8e69a1e23b97e3aef35626831e75547a0b7faf3e Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Sat, 11 Jan 2014 14:47:31 +0000 Subject: [PATCH] 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. --- phpgwapi/js/jsapi/egw_json.js | 18 ++++++++++-------- phpgwapi/js/jsapi/egw_jsonq.js | 3 +++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/phpgwapi/js/jsapi/egw_json.js b/phpgwapi/js/jsapi/egw_json.js index dcdf43e87a..a6774b53bc 100644 --- a/phpgwapi/js/jsapi/egw_json.js +++ b/phpgwapi/js/jsapi/egw_json.js @@ -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); + } } } diff --git a/phpgwapi/js/jsapi/egw_jsonq.js b/phpgwapi/js/jsapi/egw_jsonq.js index f89a841005..eb10abef8f 100644 --- a/phpgwapi/js/jsapi/egw_jsonq.js +++ b/phpgwapi/js/jsapi/egw_jsonq.js @@ -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)