From 4239b83bd0816e079efe00d20ea98036ea5d17d4 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 16 Apr 2013 18:44:43 +0000 Subject: [PATCH] Add not implemented js function type. It understands app.appname.function style arguments --- etemplate/js/et2_core_common.js | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/etemplate/js/et2_core_common.js b/etemplate/js/et2_core_common.js index 76d3641cff..2582675975 100644 --- a/etemplate/js/et2_core_common.js +++ b/etemplate/js/et2_core_common.js @@ -209,6 +209,40 @@ function et2_checkType(_val, _type, _attr, _cname) return _err(); } + // Javascript + if (_type == "js") + { + if (typeof _val == "function") + { + return _val; + } + + // Check to see if it's a string in app.appname.function format, and wrap it in + // a closure to make sure context is preserved + if(typeof _val == "string" && _val.substr(0,4) == "app." && window.app) + { + var parts = res.data.func.split('.'); + var func = parts.pop(); + var parent = window; + for(var i=0; i < parts.length && typeof parent[parts[i]] != 'undefined'; ++i) + { + parent = parent[parts[i]]; + } + if (typeof parent[func] == 'function') + { + try + { + return jQuery.proxy(parent,parent[func]); + } + catch (e) + { + req.egw.debug('error', 'Function', _val); + return _err(); + } + } + } + } + // We should never come here throw("Invalid type identifier '" + _attr + ": " + _type + "' supplied by '" + _cname + "'"); }