From ab56e637b7f97ddcdbcc9baea99ae097e342409c Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Wed, 6 Mar 2019 14:02:32 +0100 Subject: [REF] web: adapt code after jQuery update Part of task 1896658 Co-authored-by: Aaron Bohy Co-authored-by: Christophe Matthieu Co-authored-by: Mathieu Duckerts-Antoine Co-authored-by: David Monjoie Co-authored-by: Martin Geubelle Co-authored-by: svs-odoo Co-authored-by: Vincent Schippefilt --- addons/web/static/src/js/core/dom.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'addons/web/static/src/js/core/dom.js') diff --git a/addons/web/static/src/js/core/dom.js b/addons/web/static/src/js/core/dom.js index b8a5b8be3a4..3faa5977c8c 100644 --- a/addons/web/static/src/js/core/dom.js +++ b/addons/web/static/src/js/core/dom.js @@ -1,11 +1,10 @@ odoo.define('web.dom_ready', function (require) { 'use strict'; -var def = $.Deferred(); -$(def.resolve.bind(def)); -return def; + return new Promise(function (resolve, reject) { + $(resolve); + }); }); - //============================================================================== odoo.define('web.dom', function (require) { @@ -33,7 +32,7 @@ var _t = core._t; * that on_attach_callback() will be called on each w with arguments args */ function _notify(content, callbacks) { - _.each(callbacks, function (c) { + callbacks.forEach(function (c) { if (c.widget && c.widget.on_attach_callback) { c.widget.on_attach_callback(c.callback_args); } @@ -170,14 +169,14 @@ var dom = { * @return {jQuery} the detached elements */ detach: function (to_detach, options) { - _.each(to_detach, function (d) { + to_detach.forEach( function (d) { if (d.widget.on_detach_callback) { d.widget.on_detach_callback(d.callback_args); } }); var $to_detach = options && options.$to_detach; if (!$to_detach) { - $to_detach = $(_.map(to_detach, function (d) { + $to_detach = $(to_detach.map(function (d) { return d.widget.el; })); } @@ -229,7 +228,7 @@ var dom = { * @param {function|boolean} stopPropagation */ makeAsyncHandler: function (fct, preventDefault, stopPropagation) { - // Create a deferred indicating if a previous call to this handler is + // Create a promise indicating if a previous call to this handler is // still pending. var def = $.when(); @@ -284,11 +283,13 @@ var dom = { // a 'real' debounce creation useless. Also, during the debouncing // part, the button is disabled without any visual effect. $button.addClass('o_debounce_disabled'); - $.when(dom.DEBOUNCE && concurrency.delay(dom.DEBOUNCE)).then(function () { + Promise.resolve(dom.DEBOUNCE && concurrency.delay(dom.DEBOUNCE)).then(function () { $button.addClass('disabled').prop('disabled', true); $button.removeClass('o_debounce_disabled'); - return $.when(result).always(function () { + return Promise.resolve(result).then(function () { + $button.removeClass('disabled').prop('disabled', false); + }).guardedCatch(function () { $button.removeClass('disabled').prop('disabled', false); }); }); -- cgit v1.2.3