diff options
| author | qsm-odoo <qsm@odoo.com> | 2019-03-15 15:50:31 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2019-03-15 16:03:00 +0000 |
| commit | a58a115e40e298c2cc8aba27ba8bc45032e84ab3 (patch) | |
| tree | 846e88420bc6e9cd507290037ac0990caeed4589 /addons/website/static/src/js/utils.js | |
| parent | 31983e0c2e6a307032f6836107b162c4eefbed1b (diff) | |
[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) <qsm@odoo.com>
Diffstat (limited to 'addons/website/static/src/js/utils.js')
| -rw-r--r-- | addons/website/static/src/js/utils.js | 14 |
1 files changed, 7 insertions, 7 deletions
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<string[]>} */ 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; }); |
