summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/content
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2019-02-04 14:45:16 +0000
committerqsm-odoo <qsm@odoo.com>2019-02-05 11:39:11 +0000
commitb6db6b878c5d329c19262d829e13726c3a3a1d25 (patch)
treefd49fff13e186b91f88b287a99e114adaa8a406d /addons/website/static/src/js/content
parent99499589eafb9c05236eb47553c1d723573c1b70 (diff)
[REF] website, *: remove 'website.context' module
* website_forum, website_gengo, website_mail_channel, website_sale Retrieving the global context is now the root's job, this will prevent problems when trying to extend the values the context has. See upcoming improvements with https://github.com/odoo/odoo/pull/29442 closes odoo/odoo#30816
Diffstat (limited to 'addons/website/static/src/js/content')
-rw-r--r--addons/website/static/src/js/content/context.js25
-rw-r--r--addons/website/static/src/js/content/snippets.animation.js17
-rw-r--r--addons/website/static/src/js/content/website_root.js55
3 files changed, 69 insertions, 28 deletions
diff --git a/addons/website/static/src/js/content/context.js b/addons/website/static/src/js/content/context.js
deleted file mode 100644
index 671ad345e65..00000000000
--- a/addons/website/static/src/js/content/context.js
+++ /dev/null
@@ -1,25 +0,0 @@
-odoo.define('website.context', function (require) {
-'use strict';
-
-function getContext(context) {
- var html = document.documentElement;
- return _.extend({
- lang: (html.getAttribute('lang') || 'en_US').replace('-', '_'),
- website_id: html.getAttribute('data-website-id') | 0,
- }, context || {});
-}
-
-function getExtraContext(context) {
- var html = document.documentElement;
- return _.extend(getContext(), {
- editable: !!(html.dataset.editable || $('[data-oe-model]').length), // temporary hack, this should be done in python
- translatable: !!html.dataset.translatable,
- edit_translations: !!html.dataset.edit_translations,
- }, context || {});
-}
-
-return {
- get: getContext,
- getExtra: getExtraContext,
-};
-});
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js
index d2a653b0837..2c322012d1c 100644
--- a/addons/website/static/src/js/content/snippets.animation.js
+++ b/addons/website/static/src/js/content/snippets.animation.js
@@ -487,6 +487,23 @@ var Animation = Widget.extend({
new AnimationEffect(this, updateCallback, startEvents, $startTarget, options)
);
},
+ /**
+ * @private
+ * @param {boolean} [extra=false]
+ * @param {Object} [extraContext]
+ * @returns {Object}
+ */
+ _getContext: function (extra, extraContext) {
+ var context;
+ this.trigger_up('context_get', {
+ extra: extra || false,
+ context: extraContext,
+ callback: function (ctx) {
+ context = ctx;
+ },
+ });
+ return context;
+ },
});
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js
index 0d89ae528a9..a665d4eba99 100644
--- a/addons/website/static/src/js/content/website_root.js
+++ b/addons/website/static/src/js/content/website_root.js
@@ -22,7 +22,6 @@ var ServiceProviderMixin = require('web.ServiceProviderMixin');
var session = require('web.session');
var utils = require('web.utils');
var rootWidget = require('web_editor.root_widget');
-var wContext = require('website.context');
var sAnimation = require('website.content.snippets.animation');
require("website.content.zoomodoo");
@@ -32,7 +31,11 @@ var websiteRootRegistry = new rootWidget.RootWidgetRegistry();
// Load localizations outside the WebsiteRoot to not wait for DOM ready (but
// wait for them in WebsiteRoot)
-var lang = utils.get_cookie('frontend_lang') || wContext.get().lang; // FIXME the cookie value should maybe be in the ctx?
+function getLang() {
+ var html = document.documentElement;
+ return (html.getAttribute('lang') || 'en_US').replace('-', '_');
+}
+var lang = utils.get_cookie('frontend_lang') || getLang(); // FIXME the cookie value should maybe be in the ctx?
var localeDef = ajax.loadJS('/web/webclient/locale/' + lang.replace('-', '_'));
/**
@@ -53,6 +56,7 @@ var WebsiteRoot = rootWidget.RootWidget.extend(ServiceProviderMixin, {
custom_events: _.extend({}, rootWidget.RootWidget.prototype.custom_events || {}, {
animation_start_demand: '_onAnimationStartDemand',
animation_stop_demand: '_onAnimationStopDemand',
+ context_get: '_onContextGet',
main_object_request: '_onMainObjectRequest',
ready_to_clean_for_save: '_onAnimationStopDemand',
}),
@@ -138,7 +142,7 @@ var WebsiteRoot = rootWidget.RootWidget.extend(ServiceProviderMixin, {
if (_.str.startsWith(route, '/web/dataset/call_kw/')) {
var params = ev.data.args[1];
var options = ev.data.args[2];
- params.kwargs.context = _.extend({}, wContext.get(), params.kwargs.context || {});
+ params.kwargs.context = _.extend({}, this._getContext(), params.kwargs.context || {});
if (options) {
params.kwargs.context = _.omit(params.kwargs.context, options.noContextKeys);
ev.data.args[2] = _.omit(options, 'noContextKeys');
@@ -149,6 +153,38 @@ var WebsiteRoot = rootWidget.RootWidget.extend(ServiceProviderMixin, {
return ServiceProviderMixin._call_service.apply(this, arguments);
},
/**
+ * Retrieves the global context of the public environment. This is the
+ * context which is automatically added to each RPC.
+ *
+ * @private
+ * @param {Object} [context]
+ * @returns {Object}
+ */
+ _getContext: function (context) {
+ var html = document.documentElement;
+ return _.extend({
+ 'lang': getLang(),
+ 'website_id': html.getAttribute('data-website-id') | 0,
+ }, context || {});
+ },
+ /**
+ * Retrieves the global context of the public environment (as
+ * @see _getContext) but with extra informations that would be useless to
+ * send with each RPC.
+ *
+ * @private
+ * @param {Object} [context]
+ * @returns {Object}
+ */
+ _getExtraContext: function (context) {
+ var html = document.documentElement;
+ return _.extend(this._getContext(), {
+ 'editable': !!(html.dataset.editable || $('[data-oe-model]').length), // temporary hack, this should be done in python
+ 'translatable': !!html.dataset.translatable,
+ 'edit_translations': !!html.dataset.edit_translations,
+ }, context || {});
+ },
+ /**
* As the WebsiteRoot instance is designed to be unique, the associated
* registry has been instantiated outside of the class and is simply
* returned here.
@@ -243,6 +279,19 @@ var WebsiteRoot = rootWidget.RootWidget.extend(ServiceProviderMixin, {
this._stopAnimations(ev.data.$target);
},
/**
+ * Called when someone asked for the global public context.
+ *
+ * @private
+ * @param {OdooEvent} ev
+ */
+ _onContextGet: function (ev) {
+ if (ev.data.extra) {
+ ev.data.callback(this._getExtraContext(ev.data.context));
+ } else {
+ ev.data.callback(this._getContext(ev.data.context));
+ }
+ },
+ /**
* @todo review
* @private
*/