From a58a115e40e298c2cc8aba27ba8bc45032e84ab3 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 15 Mar 2019 15:50:31 +0000 Subject: [FIX] website: restore broken promises in website Since the switch to jQuery 3, Odoo uses native promises in its JS. Some mistakes were made in the website app during conversion from old jQuery deferred to native promises. - `this` -> `self` when wrapping in a promise - `.always(fct)` -> `.then(fct).guardedCatch(fct)` - a function returned sometimes a jQuery deferred, sometimes a native promise. This made the caller fail when using `always` or fail when using `guardedCatch` closes odoo/odoo#31887 Signed-off-by: Quentin Smetz (qsm) --- addons/website/static/src/js/utils.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'addons/website/static/src/js/utils.js') diff --git a/addons/website/static/src/js/utils.js b/addons/website/static/src/js/utils.js index e93a52897c0..a78a914e7a5 100644 --- a/addons/website/static/src/js/utils.js +++ b/addons/website/static/src/js/utils.js @@ -13,13 +13,13 @@ var qweb = core.qweb; * @returns {Deferred} */ function loadAnchors(url) { - var def; - if (url !== window.location.pathname && url[0] !== '#') { - def = $.get(window.location.origin + url); - } else { - def = Promise.resolve(document.body.outerHTML); - } - return def.then(function (response) { + return new Promise(function (resolve, reject) { + if (url !== window.location.pathname && url[0] !== '#') { + $.get(window.location.origin + url).then(resolve, reject); + } else { + resolve(document.body.outerHTML); + } + }).then(function (response) { return _.map($(response).find('[id][data-anchor=true]'), function (el) { return '#' + el.id; }); -- cgit v1.2.3