mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-08 23:19:04 +01:00
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:
parent
782de6d887
commit
29ab26b731
@ -496,45 +496,32 @@ 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
|
// The ajax request has completed, get just the data & pass it on
|
||||||
let resolvePromise = function(resolve, reject) {
|
if(response && response.response)
|
||||||
// Bind to ajax response - this is called _after_ any other handling
|
{
|
||||||
ajax_promise.always(function(response, status, p) {
|
for(let value of response.response)
|
||||||
if(status !== "success") reject();
|
|
||||||
|
|
||||||
// The ajax request has completed, get just the data & pass it on
|
|
||||||
if(response && response.response)
|
|
||||||
{
|
{
|
||||||
for(let value of response.response)
|
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
|
||||||
{
|
return value.data;
|
||||||
// Data was packed in response
|
}
|
||||||
resolve(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
|
||||||
{
|
return value;
|
||||||
// Just raw data
|
|
||||||
resolve(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// No data? Resolve the promise with nothing
|
return undefined;
|
||||||
resolve();
|
});
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const myPromise = new Promise(resolvePromise);
|
|
||||||
|
|
||||||
return myPromise;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user