summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2020-02-03 18:06:39 +0000
committerqsm-odoo <qsm@odoo.com>2020-02-05 10:48:44 +0000
commit6f4c60fe1bb6e460ec6da00c59a9825271893729 (patch)
tree1e1daccae6866dcceba5854a1f2dd26aacfd7777 /addons/web/static/src/js/core
parentd04ca05b2ee33ee270866ba9ac8eed61a251c1ed (diff)
[FIX] website, *: lazy load widget assets of the correct website
*: web Before this commit, when a widget declared assets to lazy load through the assetLibs key, the asset was loaded through a context-less call to the server through the base `rpc` function. This caused problems in website: the website ID was not given to the called route and the loaded assets were then stripped of their specific-website parts. This commit solves the problem by allowing the `loadLibs` and `loadAsset` functions to receive an extra argument: an extra `context` to use for the actual call to the server. The method is now available in the ajax service, so that website can add its custom context automatically, the same way it does it for normal `_rpc` calls. Part of https://github.com/odoo/odoo/pull/44596 closes odoo/odoo#44596 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/core')
-rw-r--r--addons/web/static/src/js/core/ajax.js13
-rw-r--r--addons/web/static/src/js/core/service_mixins.js9
-rw-r--r--addons/web/static/src/js/core/widget.js2
3 files changed, 19 insertions, 5 deletions
diff --git a/addons/web/static/src/js/core/ajax.js b/addons/web/static/src/js/core/ajax.js
index cf5fe87b2ae..67a46e29d55 100644
--- a/addons/web/static/src/js/core/ajax.js
+++ b/addons/web/static/src/js/core/ajax.js
@@ -428,6 +428,8 @@ var loadXML = (function () {
* Loads a template file according to the given xmlId.
*
* @param {string} [xmlId] - the template xmlId
+ * @param {Object} [context]
+ * additionnal rpc context to be merged with the default one
* @returns {Deferred} resolved with an object
* cssLibs: list of css files
* cssContents: list of style tag contents
@@ -437,16 +439,17 @@ var loadXML = (function () {
var loadAsset = (function () {
var cache = {};
- var load = function loadAsset(xmlId) {
+ var load = function loadAsset(xmlId, context) {
if (cache[xmlId]) {
return Promise.resolve(cache[xmlId]);
}
+ context = _.extend({}, odoo.session_info.user_context, context);
var params = {
args: [xmlId, {
debug: config.isDebug()
}],
kwargs: {
- context: odoo.session_info.user_context,
+ context: context,
},
method: 'render_template',
model: 'ir.ui.view',
@@ -499,10 +502,12 @@ var loadAsset = (function () {
* List of inline styles to add after loading the CSS files.
* @param {string[]} [libs.jsContents=[]]
* List of inline scripts to add after loading the JS files.
+ * @param {Object} [context]
+ * additionnal rpc context to be merged with the default one
*
* @returns {Promise}
*/
-function loadLibs(libs) {
+function loadLibs(libs, context) {
var mutex = new concurrency.Mutex();
mutex.exec(function () {
var defs = [];
@@ -525,7 +530,7 @@ function loadLibs(libs) {
});
mutex.exec(function () {
return _loadArray(libs.assetLibs || [], function (xmlID) {
- return ajax.loadAsset(xmlID).then(function (asset) {
+ return ajax.loadAsset(xmlID, context).then(function (asset) {
return ajax.loadLibs(asset);
});
});
diff --git a/addons/web/static/src/js/core/service_mixins.js b/addons/web/static/src/js/core/service_mixins.js
index 0576364fa7c..9e6a40b494c 100644
--- a/addons/web/static/src/js/core/service_mixins.js
+++ b/addons/web/static/src/js/core/service_mixins.js
@@ -124,6 +124,15 @@ var ServicesMixin = {
return result;
},
/**
+ * @private
+ * @param {Object} libs - @see ajax.loadLibs
+ * @param {Object} [context] - @see ajax.loadLibs
+ * @returns {Promise}
+ */
+ _loadLibs: function (libs, context) {
+ return this.call('ajax', 'loadLibs', libs, context);
+ },
+ /**
* Builds and executes RPC query. Returns a promise resolved with
* the RPC result.
*
diff --git a/addons/web/static/src/js/core/widget.js b/addons/web/static/src/js/core/widget.js
index c6530b7fb7a..a089f8876fe 100644
--- a/addons/web/static/src/js/core/widget.js
+++ b/addons/web/static/src/js/core/widget.js
@@ -148,7 +148,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, {
}));
}
if (this.jsLibs || this.cssLibs || this.assetLibs) {
- proms.push(ajax.loadLibs(this));
+ proms.push(this._loadLibs(this));
}
return Promise.all(proms);
},