improve egw.langRequire to return a Promise, if no callback specified

This commit is contained in:
Ralf Becker 2021-04-29 09:44:26 +02:00
parent d185a53f8e
commit eefd8ed972

View File

@ -133,6 +133,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function()
* } * }
* @param {function} _callback called after loading, if not given ready event will be postponed instead * @param {function} _callback called after loading, if not given ready event will be postponed instead
* @param {object} _context for callback * @param {object} _context for callback
* @return Promise if no _callback specified
*/ */
langRequire: function(_window, _apps, _callback, _context) { langRequire: function(_window, _apps, _callback, _context) {
// Get the ready and the files module for the given window // Get the ready and the files module for the given window
@ -171,10 +172,14 @@ egw.extend('lang', egw.MODULE_GLOBAL, function()
// Require a "ready postpone token" // Require a "ready postpone token"
var token = ready.readyWaitFor(); var token = ready.readyWaitFor();
// Call "readyDone" once all js files have been included. return new Promise(function(resolve)
files.includeJS(jss, function () { {
ready.readyDone(token); // Call "readyDone" once all js files have been included.
}, this); files.includeJS(jss, function () {
ready.readyDone(token);
resolve();
}, this);
});
} }
} }
else if (typeof _callback == 'function') else if (typeof _callback == 'function')