allow to use hierarchical function names, eg. app.filemanager.upload via new et2_call function

This commit is contained in:
Ralf Becker 2013-04-20 19:21:42 +00:00
parent 28aab234a7
commit 3a14e96d1a
2 changed files with 36 additions and 5 deletions

View File

@ -733,3 +733,35 @@ function et2_rangeSubstract(_ar1, _ar2)
return res;
}
/**
* Call a function specified by it's name (possibly dot separated, eg. "app.myapp.myfunc")
*
* @param string func dot-separated function name
* @param arguments variable number of arguments
* @returns {Boolean}
*/
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 && typeof parent[parts[i]] != 'undefined'; ++i)
{
parent = parent[parts[i]];
}
if (typeof parent[func] == 'function')
{
func = parent[func];
}
}
if (typeof func != 'function')
{
throw _func+" is not a function!";
}
return func.apply(parent, args);
}

View File

@ -258,7 +258,7 @@ var et2_file = et2_inputWidget.extend(
this.disabled_buttons = $j("input[type='submit'], button").not("[disabled]").attr("disabled", true);
event.data = this;
if(this.options.onStart && typeof this.options.onStart == 'function') return this.options.onStart(event,file_count);
if(this.options.onStart) return et2_call(this.options.onStart, event, file_count);
return true;
},
@ -268,7 +268,7 @@ var et2_file = et2_inputWidget.extend(
onFinish: function(event, file_count) {
this.disabled_buttons.attr("disabled", false);
event.data = this;
if(this.options.onFinish && typeof this.options.onFinish == 'function') return this.options.onFinish(event,file_count);
if(this.options.onFinish) return et2_call(this.options.onFinish, event, file_count);
},
@ -326,7 +326,6 @@ console.warn(event,name,error);
if(typeof response.response[0].data[key] == "string")
{
// Message from server - probably error
$j("[file='"+name+"']",this.progress)
.addClass("error")
.css("display", "block")
@ -349,9 +348,9 @@ console.warn(event,name,error);
.css("display", "block")
.text(this.egw().lang("Server error"));
}
if(this.options.onFinishOne && typeof this.options.onFinishOne == 'function')
if(this.options.onFinishOne)
{
return this.options.onFinishOne(event,response,name,number,total);
return et2_call(this.options.onFinishOne,event,response,name,number,total);
}
return true;
},