summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/component_extension.js
diff options
context:
space:
mode:
authormcm-odoo <mcm@odoo.com>2020-01-14 10:13:15 +0000
committerAaron Bohy <aab@odoo.com>2020-01-21 10:21:08 +0000
commita8e65f22ed6224ba8125fb99c407928ff644cac2 (patch)
tree9b819fcc0162058bcc2faa0538c31b8acb617a5b /addons/web/static/src/js/component_extension.js
parent671a5471cd891ac87a2cffc8a0e7ebac1b519725 (diff)
[IMP] web: Owl compatibility: add WidgetAdapterMixin
and ComponentWrapper This commit adds the necessary tools to use when an Odoo legacy widget has to instantiate Owl components.
Diffstat (limited to 'addons/web/static/src/js/component_extension.js')
-rw-r--r--addons/web/static/src/js/component_extension.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/addons/web/static/src/js/component_extension.js b/addons/web/static/src/js/component_extension.js
index 39568bd0594..ce9a3228569 100644
--- a/addons/web/static/src/js/component_extension.js
+++ b/addons/web/static/src/js/component_extension.js
@@ -1,8 +1,14 @@
-/**
- * Add a new method to owl Components to ensure that no performed RPC is
- * resolved/rejected when the component is destroyed.
- */
(function () {
+ /**
+ * Symbol used in ComponentWrapper to redirect Owl events to Odoo legacy
+ * events.
+ */
+ odoo.widgetSymbol = Symbol('widget');
+
+ /**
+ * Add a new method to owl Components to ensure that no performed RPC is
+ * resolved/rejected when the component is destroyed.
+ */
owl.Component.prototype.rpc = function () {
return new Promise((resolve, reject) => {
return this.env.services.rpc(...arguments)
@@ -18,4 +24,19 @@
});
});
};
+
+ /**
+ * Patch owl.Component.__trigger method to call a hook that adds a listener
+ * for the triggered event just before triggering it. This is useful if
+ * there are legacy widgets in the ancestors. In that case, there would be
+ * a widgetSymbol key in the environment, corresponding to the hook to call
+ * (see ComponentWrapper).
+ */
+ const originalTrigger = owl.Component.prototype.__trigger;
+ owl.Component.prototype.__trigger = function (component, evType, payload) {
+ if (this.env[odoo.widgetSymbol]) {
+ this.env[odoo.widgetSymbol](evType);
+ }
+ originalTrigger.call(this, component, evType, payload);
+ };
})();