From 20a48d2fe44aed289b969d0016b9f746737f567f Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 8 Oct 2020 14:57:45 -0600 Subject: [PATCH] Fix methods in hidden app objects could not be used as action handlers Now nextmatch sets the etemplate's EgwApp object as context for the action manager. Actions now check and will use the set context instead of global when binding to handlers --- api/js/egw_action/egw_action_common.js | 23 +++++++++++++------ .../et2_extension_nextmatch_controller.js | 3 ++- .../et2_extension_nextmatch_controller.ts | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/api/js/egw_action/egw_action_common.js b/api/js/egw_action/egw_action_common.js index 196da77642..282ec76de0 100644 --- a/api/js/egw_action/egw_action_common.js +++ b/api/js/egw_action/egw_action_common.js @@ -381,15 +381,24 @@ egwFnct.prototype.setValue = function(_value) } // egw application specific function - else if (typeof _value == "string" && - _value.substr(0,15) == "javaScript:app." && app) + else if (typeof _value === "string" && + _value.substr(0,15) === "javaScript:app." && app) { var parts = _value.split("."); - if(parts.length == 3 && typeof app[parts[1]] == "object" && - typeof app[parts[1]][parts[2]] == "function") - { - this.fnct = app[parts[1]][parts[2]]; - this.context = app[parts[1]]; + var existing_func = parts.pop(); + var parent = this.context.getManager().data.context || window.app; + for (var i = 1; i < parts.length; ++i) { + if (typeof parent[parts[i]] !== "undefined") { + parent = parent[parts[i]]; + } + // Nope + else { + break; + } + } + if (typeof parent[existing_func] === "function") { + this.fnct = parent[existing_func]; + this.context = parent; } } diff --git a/api/js/etemplate/et2_extension_nextmatch_controller.js b/api/js/etemplate/et2_extension_nextmatch_controller.js index 6514adf381..1ce78b35d9 100644 --- a/api/js/etemplate/et2_extension_nextmatch_controller.js +++ b/api/js/etemplate/et2_extension_nextmatch_controller.js @@ -236,13 +236,14 @@ var et2_nextmatch_controller = /** @class */ (function (_super) { if (this._actionManager == null) { this._actionManager = gam.addAction("actionManager", uid); } - this._actionManager.updateActions(_actions, this.egw.appName); var data = this._actionManager.data; if (data == 'undefined' || !data) { data = {}; } data.nextmatch = this._widget; + data.context = this._widget.getInstanceManager().app_obj; this._actionManager.set_data(data); + this._actionManager.updateActions(_actions, this.egw.appName); // Set the default execute handler var self = this; this._actionManager.setDefaultExecute(function (_action, _senders, _target) { diff --git a/api/js/etemplate/et2_extension_nextmatch_controller.ts b/api/js/etemplate/et2_extension_nextmatch_controller.ts index 404f492ba1..d205d1bc69 100644 --- a/api/js/etemplate/et2_extension_nextmatch_controller.ts +++ b/api/js/etemplate/et2_extension_nextmatch_controller.ts @@ -278,14 +278,15 @@ export class et2_nextmatch_controller extends et2_dataview_controller implements { this._actionManager = gam.addAction("actionManager", uid); } - this._actionManager.updateActions(_actions, this.egw.appName); var data = this._actionManager.data; if (data == 'undefined' || !data) { data = {}; } data.nextmatch = this._widget; + data.context = this._widget.getInstanceManager().app_obj; this._actionManager.set_data(data); + this._actionManager.updateActions(_actions, this.egw.appName); // Set the default execute handler var self = this;