diff options
| author | Aaron Bohy <aab@odoo.com> | 2020-05-28 09:55:44 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-06-12 08:04:14 +0000 |
| commit | 26fe23201bb495176d14c15c8866e8fc72ca044c (patch) | |
| tree | d464bed68b4a9e5494869db375c0aea103d69350 /addons/web/static/src/js/core | |
| parent | c4786fccfd23360a02e442c48ae2fb9f1e70aa4c (diff) | |
[IMP] web,*: properly define env in the frontend
*bus,mail
This commit extracts the common basis of the env to use both in
the frontend and the backend. The public env now contains most of
the features that were previously (only) in the webclient env.
Moreover, the PublicRoot no longer uses the ServiceProviderMixin,
such that services are only deployed once, in the (public) env.
Owl components can now be defined in the website, and rely on a
properly built env. Legacy widgets still works as they access
services through the PublicRoot (via trigger_up) which redirects
those requests to the env.
Diffstat (limited to 'addons/web/static/src/js/core')
| -rw-r--r-- | addons/web/static/src/js/core/abstract_service.js | 29 | ||||
| -rw-r--r-- | addons/web/static/src/js/core/service_mixins.js | 2 |
2 files changed, 29 insertions, 2 deletions
diff --git a/addons/web/static/src/js/core/abstract_service.js b/addons/web/static/src/js/core/abstract_service.js index c907b28f7c8..f9ad859fef2 100644 --- a/addons/web/static/src/js/core/abstract_service.js +++ b/addons/web/static/src/js/core/abstract_service.js @@ -7,14 +7,39 @@ var ServicesMixin = require('web.ServicesMixin'); var AbstractService = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, { dependencies: [], - init: function (parent) { + init: function (env) { Mixins.EventDispatcherMixin.init.call(this, arguments); - this.setParent(parent); + this.env = env; }, /** * @abstract */ start: function () {}, + /** + * Directly calls the requested service, instead of triggering a + * 'call_service' event up, which wouldn't work as services have no parent + * + * @param {OdooEvent} ev + */ + _trigger_up: function (ev) { + Mixins.EventDispatcherMixin._trigger_up.apply(this, arguments); + if (ev.is_stopped()) { + return; + } + const payload = ev.data; + if (ev.name === 'call_service') { + let args = payload.args || []; + if (payload.service === 'ajax' && payload.method === 'rpc') { + // ajax service uses an extra 'target' argument for rpc + args = args.concat(ev.target); + } + const service = this.env.services[payload.service]; + const result = service[payload.method].apply(service, args); + payload.callback(result); + } else if (ev.name === 'do_action') { + this.env.bus.trigger('do-action', payload); + } + }, }); return AbstractService; diff --git a/addons/web/static/src/js/core/service_mixins.js b/addons/web/static/src/js/core/service_mixins.js index f191dba5c08..198d00993ed 100644 --- a/addons/web/static/src/js/core/service_mixins.js +++ b/addons/web/static/src/js/core/service_mixins.js @@ -3,6 +3,8 @@ odoo.define('web.ServiceProviderMixin', function (require) { var core = require('web.core'); +// ServiceProviderMixin is deprecated. It is only used by the ProjectTimesheet +// app. As soon as it no longer uses it, we can remove it. var ServiceProviderMixin = { services: {}, // dict containing deployed service instances UndeployedServices: {}, // dict containing classes of undeployed services |
