From 34a2f8c6e09b7c0c3d5b9e06ede97b4c8f7b6fc7 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 12 Apr 2013 16:03:45 +0000 Subject: [PATCH] support for non-global func eg. "app.someapp.func" need to be in both egw_json objects (until we fix it so one calls the other) --- phpgwapi/js/egw_json.js | 32 +++++++++++++------------------- phpgwapi/js/jsapi/egw_json.js | 25 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/phpgwapi/js/egw_json.js b/phpgwapi/js/egw_json.js index 334154b34b..2bcab2e914 100644 --- a/phpgwapi/js/egw_json.js +++ b/phpgwapi/js/egw_json.js @@ -461,37 +461,31 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe throw 'Invalid parameters'; break; case 'apply': - if (typeof res.data.func == 'string' && typeof window[res.data.func] == 'function') + if (typeof res.data.func == 'string') { - try + 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) { - window[res.data.func].apply(window, res.data.parms); + parent = parent[parts[i]]; } - catch (e) - { - _egw_json_debug_log(e, {'Function': res.data.func, 'Parameters': res.data.parms}); - } - hasResponse = true; - } else if (typeof res.data.func == "string" && - res.data.func.substr(0,4) == "app." && window.app) - { - - var parts = res.data.func.split("."); - if(parts.length == 3 && typeof window.app[parts[1]] == "object" && - typeof window.app[parts[1]][parts[2]] == "function") + if (typeof parent[func] == 'function') { try { - this.context = window.app[parts[1]][parts[2]].apply(window.app[parts[1]], res.data.parms); + parent[func].apply(parent, res.data.parms); } catch (e) { _egw_json_debug_log(e, {'Function': res.data.func, 'Parameters': res.data.parms}); } + hasResponse = true; } - hasResponse = true; - - } else + else + throw 'Invalid parameters'; + } + else throw 'Invalid parameters'; break; case 'jquery': diff --git a/phpgwapi/js/jsapi/egw_json.js b/phpgwapi/js/jsapi/egw_json.js index cb62b07def..2ba940aa31 100644 --- a/phpgwapi/js/jsapi/egw_json.js +++ b/phpgwapi/js/jsapi/egw_json.js @@ -283,19 +283,28 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) { // Register the "apply" plugin json.registerJSONPlugin(function(type, res, req) { - if (typeof res.data.func == 'string' && - typeof window[res.data.func] == 'function') + if (typeof res.data.func == 'string') { - try + 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) { - window[res.data.func].apply(window, res.data.parms); + parent = parent[parts[i]]; } - catch (e) + if (typeof parent[func] == 'function') { - req.egw.debug('error', 'Function', res.data.func, - 'Parameters', res.data.parms); + try + { + parent[func].apply(parent, res.data.parms); + } + catch (e) + { + req.egw.debug('error', 'Function', res.data.func, + 'Parameters', res.data.parms); + } + return true; } - return true; } throw 'Invalid parameters'; }, null, 'apply');