fix egw.request() which was using jQuery defered.always() which egw_json.sendRequest() no longer returns in favor to a Promise

This commit is contained in:
Ralf Becker 2021-08-14 08:42:24 +02:00
parent 782de6d887
commit 29ab26b731

View File

@ -496,19 +496,13 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
* @param {string} _menuaction * @param {string} _menuaction
* @param {any[]} _parameters * @param {any[]} _parameters
* *
* @return Promise * @return Promise resolving to data part (not full response, which can contain other parts)
*/ */
request: function(_menuaction, _parameters) request: function(_menuaction, _parameters)
{ {
let request = new json_request(_menuaction, _parameters, null, this, true, this, this); const request = new json_request(_menuaction, _parameters, null, this, true, this, this);
let ajax_promise = request.sendRequest(); return request.sendRequest().then(function(response)
{
// This happens first, immediately
let resolvePromise = function(resolve, reject) {
// Bind to ajax response - this is called _after_ any other handling
ajax_promise.always(function(response, status, p) {
if(status !== "success") reject();
// The ajax request has completed, get just the data & pass it on // The ajax request has completed, get just the data & pass it on
if(response && response.response) if(response && response.response)
{ {
@ -517,24 +511,17 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
if(value.type && value.type === "data" && typeof value.data !== "undefined") if(value.type && value.type === "data" && typeof value.data !== "undefined")
{ {
// Data was packed in response // Data was packed in response
resolve(value.data); return value.data;
} }
else if (value && typeof value.type === "undefined" && typeof value.data === "undefined") else if (value && typeof value.type === "undefined" && typeof value.data === "undefined")
{ {
// Just raw data // Just raw data
resolve(value); return value;
} }
} }
} }
return undefined;
// No data? Resolve the promise with nothing
resolve();
}); });
};
const myPromise = new Promise(resolvePromise);
return myPromise;
}, },
/** /**