summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/chrome/abstract_web_client.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-01-30 12:36:05 +0000
committeraab-odoo <aab@odoo.com>2020-01-31 10:35:37 +0000
commit8641c46ccbd1259b5c551b97351df6876b8b5df5 (patch)
tree69d22076802b8f2b1e1151c485096097a4e6f44f /addons/web/static/src/js/chrome/abstract_web_client.js
parent2161d23d80e58bebca71e2cb799b4a3c9f9148e7 (diff)
[FIX] web: do not deploy services twice
Since 671a5471cd891, services are deployed twice in the backend: once by the webclient (as it is a ServiceProvider), and once by the env (which now deploys the services to make them directly available for each Owl component of the component tree). As a consequence, some services perform twice some operations (e.g. the mail service fetches twice the /mail/init_messaging route, the crash manager service displays twice the tracebacks...). This commit fixes the issue by making the webclient directly use services from the env, instead of deploying them a second time. Part of 2183810 closes odoo/odoo#44301 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/chrome/abstract_web_client.js')
-rw-r--r--addons/web/static/src/js/chrome/abstract_web_client.js43
1 files changed, 40 insertions, 3 deletions
diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js
index 71a8c363535..8837ffe813e 100644
--- a/addons/web/static/src/js/chrome/abstract_web_client.js
+++ b/addons/web/static/src/js/chrome/abstract_web_client.js
@@ -22,19 +22,21 @@ var KeyboardNavigationMixin = require('web.KeyboardNavigationMixin');
var Loading = require('web.Loading');
var local_storage = require('web.local_storage');
var RainbowMan = require('web.RainbowMan');
-var ServiceProviderMixin = require('web.ServiceProviderMixin');
var session = require('web.session');
var utils = require('web.utils');
var Widget = require('web.Widget');
+const env = require('web.env');
+
var _t = core._t;
-var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMixin, {
+var AbstractWebClient = Widget.extend(KeyboardNavigationMixin, {
dependencies: ['notification'],
events: _.extend({}, KeyboardNavigationMixin.events, {
'click .o_search_options .dropdown-menu': '_onClickDropDownMenu',
}),
custom_events: {
+ call_service: '_onCallService',
clear_uncommitted_changes: function (e) {
this.clear_uncommitted_changes().then(e.data.callback);
},
@@ -95,13 +97,14 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi
odoo.isReady = false;
this.client_options = {};
this._super(parent);
- ServiceProviderMixin.init.call(this);
KeyboardNavigationMixin.init.call(this);
this.origin = undefined;
this._current_state = null;
this.menu_dp = new concurrency.DropPrevious();
this.action_mutex = new concurrency.Mutex();
this.set('title_part', {"zopenerp": "Odoo"});
+ this.env = env;
+ core.bus.on('legacy_webclient_request', this, this._onLegacyWebclientRequest);
},
start: function () {
var self = this;
@@ -334,6 +337,26 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi
//--------------------------------------------------------------------------
/**
+ * Calls the requested service from the env.
+ *
+ * For the ajax service, the arguments are extended with the target so that
+ * it can call back the caller.
+ *
+ * @private
+ * @param {OdooEvent} event
+ */
+ _onCallService: function (ev) {
+ const payload = ev.data;
+ 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);
+ },
+ /**
* When clicking inside a dropdown to modify search options
* prevents the bootstrap dropdown to close on itself
*
@@ -430,6 +453,20 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi
ev.data.callback(this.getScrollPosition());
},
/**
+ * Services used to trigger_up some events (e.g. do_action, get_session,
+ * set_title_part) when the webclient was still instantiating them. Now that
+ * services have been moved to the env, the webclient is no longer their
+ * parent and they can thus no longer communicate with the webclient by
+ * trigger_up. Instead, they trigger those events on the bus, and we end up
+ * in this handler. Eventually, services should stop triggering events up.
+ *
+ * @private
+ * @param {CustomEvent} ev
+ */
+ _onLegacyWebclientRequest: function (ev) {
+ this._trigger_up(ev);
+ },
+ /**
* Loads an action from the database given its ID.
*
* @private