From 6892c4508e54553cac320a74e7ea7aeb4d28db71 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 19 Dec 2018 15:27:25 -0700 Subject: [PATCH] Keep a queue of callbacks for the same account and call them all back when we get it --- api/js/jsapi/egw_user.js | 43 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/api/js/jsapi/egw_user.js b/api/js/jsapi/egw_user.js index 19b86345bf..614f16143c 100644 --- a/api/js/jsapi/egw_user.js +++ b/api/js/jsapi/egw_user.js @@ -156,6 +156,11 @@ egw.extend('user', egw.MODULE_GLOBAL, function() data[id] = accountData[account_id][_field][id]; } } + else if (typeof accountData[account_id] === 'object') + { + // Add it to the list + accountData[_account_ids[i]].push({callback: _callback, context: _context}); + } else { continue; @@ -168,9 +173,18 @@ egw.extend('user', egw.MODULE_GLOBAL, function() { egw.json('EGroupware\\Api\\Framework::ajax_account_data',[_account_ids, _field, _resolve_groups], function(_data) { + var callbacks = []; for(var account_id in _data) { - if (typeof accountData[account_id] == 'undefined') accountData[account_id] = {}; + if(accountData[account_id]) + { + callbacks = callbacks.concat(accountData[account_id]); + accountData[account_id] = {}; + } + else if (typeof accountData[account_id] == 'undefined') + { + accountData[account_id] = {}; + } data[account_id] = accountData[account_id][_field] = _data[account_id]; } // If resolving for 1 group, cache the whole answer too @@ -178,12 +192,33 @@ egw.extend('user', egw.MODULE_GLOBAL, function() if(_resolve_groups && _account_ids.length === 1 && _account_ids[0] < 0) { var group_id = _account_ids[0]; - if (typeof accountData[group_id] === 'undefined') accountData[group_id] = {}; + if(accountData[group_id]) + { + callbacks = callbacks.concat(accountData[group_id]); + accountData[group_id] = {}; + } + else if (typeof accountData[group_id] == 'undefined') + { + accountData[group_id] = {}; + } accountData[group_id][_field] = _data; } - _callback.call(_context, data); + for(var i = 0; i < callbacks.length; i++) + { + if(typeof callbacks[i] !== 'object' || typeof callbacks[i].callback !== 'function') continue; + callbacks[i].callback.call(callbacks[i].context, data); + } } - ).sendRequest(false); + ).sendRequest(); + // Keep request so we know what we're waiting for + for(var i=0; i < _account_ids.length; ++i) + { + if(typeof accountData[_account_ids[i]] == 'undefined') + { + accountData[_account_ids[i]] = []; + } + accountData[_account_ids[i]].push({callback: _callback, context: _context}); + } } else {