summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/content
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2018-09-28 14:50:18 +0200
committerqsm-odoo <qsm@odoo.com>2018-09-30 19:55:17 +0200
commit55131b8f5becdd3d4776f4c3e7e4288a0b185706 (patch)
tree4eca54d0cd14a2180227ad2b155e3380d37fb9a6 /addons/web_editor/static/src/js/content
parentfeae553b98c88282695c77382f4a52c78b3f8f70 (diff)
[REF] website, *: add automatic context for call_kw rpc
* web_editor, website_blog, website_crm_partner_assign, website_links, website_livechat, website_mail_channel, website_mass_mailing, website_slides Calling a model's method thanks to an RPC will now always send the web_editor context automatically, making sure the method gets the website_id all the time, removing the need to guess the current website (now the get_current_website method uses the context website_id if any). Note: other routes already have the website_id via request.env.context if they correctly set website=True (this commit also adds website=True for scss files customization routes).
Diffstat (limited to 'addons/web_editor/static/src/js/content')
-rw-r--r--addons/web_editor/static/src/js/content/body_manager.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/addons/web_editor/static/src/js/content/body_manager.js b/addons/web_editor/static/src/js/content/body_manager.js
index 2291aa1d4db..85ace262fc5 100644
--- a/addons/web_editor/static/src/js/content/body_manager.js
+++ b/addons/web_editor/static/src/js/content/body_manager.js
@@ -1,6 +1,7 @@
odoo.define('web_editor.BodyManager', function (require) {
'use strict';
+var weContext = require('web_editor.context');
var rootWidget = require('web_editor.root_widget');
var ServiceProviderMixin = require('web.ServiceProviderMixin');
var session = require('web.session');
@@ -28,6 +29,27 @@ var BodyManager = rootWidget.RootWidget.extend(ServiceProviderMixin, {
session.is_bound
);
},
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * Automatically add the web_editor context.
+ *
+ * @override
+ */
+ _call_service: function (event) {
+ if (event.data.service === 'ajax' && event.data.method === 'rpc') {
+ var route = event.data.args[0];
+ if (_.str.startsWith(route, '/web/dataset/call_kw/')) {
+ var params = event.data.args[1];
+ params.kwargs.context = _.extend({}, weContext.get(), params.kwargs.context || {});
+ params.kwargs.context = JSON.parse(JSON.stringify(params.kwargs.context));
+ }
+ }
+ return ServiceProviderMixin._call_service.apply(this, arguments);
+ },
});
return BodyManager;
});