move global et2_call function to egw.call and egw.apply methods, ensuring app.js is loaded, if not yet loaded, also using that as apply plugin for egw.json

This commit is contained in:
Ralf Becker
2021-03-01 11:50:22 +02:00
parent 9128d15bb2
commit e36c6c4cec
4 changed files with 95 additions and 65 deletions

View File

@@ -472,39 +472,13 @@ var exports = {};
* Call a function specified by it's name (possibly dot separated, eg. "app.myapp.myfunc")
*
* @param {string} _func dot-separated function name
* variable number of arguments
* @returns {Boolean}
* @param {mixed} ...args variable number of arguments
* @returns {Mixed|Promise}
* @deprecated use egw.call(_func, ...) or egw.apply(_func, args)
*/
function et2_call(_func)
{
var args = [].slice.call(arguments); // convert arguments to array
var func = args.shift();
var parent = window;
if (typeof _func == 'string')
{
var parts = _func.split('.');
func = parts.pop();
for(var i=0; i < parts.length; ++i)
{
if (typeof parent[parts[i]] != 'undefined')
{
parent = parent[parts[i]];
}
// check if we need a not yet instanciated app.js object --> instanciate it now
else if (i == 1 && parts[0] == 'app' && typeof app.classes[parts[1]] == 'function')
{
parent = parent[parts[1]] = new app.classes[parts[1]]();
}
}
if (typeof parent[func] == 'function')
{
func = parent[func];
}
}
if (typeof func != 'function')
{
throw _func+" is not a function!";
}
return func.apply(parent, args);
let args = [].slice.call(arguments); // convert arguments to array
let func = args.shift();
return egw.apply(func, args, window);
}