diff --git a/addons/web/static/src/js/framework/core.js b/addons/web/static/src/js/framework/core.js index 9e2dfd964d0..8f0453151e8 100644 --- a/addons/web/static/src/js/framework/core.js +++ b/addons/web/static/src/js/framework/core.js @@ -129,32 +129,6 @@ qweb.preprocess_node = function() { _t('%d years ago'); } -$.async_when = function() { - var async = false; - var def = $.Deferred(); - $.when.apply($, arguments).done(function() { - var args = arguments; - var action = function() { - def.resolve.apply(def, args); - }; - if (async) - action(); - else - setTimeout(action, 0); - }).fail(function() { - var args = arguments; - var action = function() { - def.reject.apply(def, args); - }; - if (async) - action(); - else - setTimeout(action, 0); - }); - async = true; - return def; -}; - return { debug: debug, qweb: qweb, diff --git a/addons/web/static/src/js/framework/data.js b/addons/web/static/src/js/framework/data.js index e969616e7b6..98c9aacc82a 100644 --- a/addons/web/static/src/js/framework/data.js +++ b/addons/web/static/src/js/framework/data.js @@ -816,7 +816,7 @@ var BufferedDataSet = DataSetStatic.extend({ }); this.set_ids(_.difference(this.ids, _.pluck(_.filter(this.cache, function (c) {return c.to_delete;}), 'id'))); this.trigger("dataset_changed", ids, callback, error_callback); - return $.async_when({result: true}).done(callback); + return utils.async_when({result: true}).done(callback); }, reset_ids: function(ids, options) { var self = this; diff --git a/addons/web/static/src/js/framework/utils.js b/addons/web/static/src/js/framework/utils.js index edf7355dc29..e19246823c5 100644 --- a/addons/web/static/src/js/framework/utils.js +++ b/addons/web/static/src/js/framework/utils.js @@ -470,6 +470,31 @@ function toBoolElse (str, elseValues, trueValues, falseValues) { return ret; } +function async_when() { + var async = false; + var def = $.Deferred(); + $.when.apply($, arguments).done(function() { + var args = arguments; + var action = function() { + def.resolve.apply(def, args); + }; + if (async) + action(); + else + setTimeout(action, 0); + }).fail(function() { + var args = arguments; + var action = function() { + def.reject.apply(def, args); + }; + if (async) + action(); + else + setTimeout(action, 0); + }); + async = true; + return def; +} return { divmod: divmod, @@ -501,6 +526,7 @@ return { delay: delay, swap: swap, toBoolElse: toBoolElse, + async_when: async_when, }; }); diff --git a/addons/web/static/src/js/views/form_relational_widgets.js b/addons/web/static/src/js/views/form_relational_widgets.js index d4c67db5218..4c7b84b6dfc 100644 --- a/addons/web/static/src/js/views/form_relational_widgets.js +++ b/addons/web/static/src/js/views/form_relational_widgets.js @@ -802,13 +802,13 @@ var FieldX2Many = AbstractManyField.extend({ this.viewmanager.on("switch_mode", self, function(n_mode) { $.when(self.commit_value()).done(function() { if (n_mode === "list") { - $.async_when().done(function() { + utils.async_when().done(function() { self.reload_current_view(); }); } }); }); - $.async_when().done(function () { + utils.async_when().done(function () { self.$el.addClass('o_view_manager_content'); self.alive(self.viewmanager.attachTo(self.$el)); }); diff --git a/addons/web/static/src/js/views/form_view.js b/addons/web/static/src/js/views/form_view.js index a9da2e40304..f517a94c819 100644 --- a/addons/web/static/src/js/views/form_view.js +++ b/addons/web/static/src/js/views/form_view.js @@ -717,7 +717,7 @@ var FormView = View.extend(common.FieldManagerMixin, { def.resolve(); }); } else { - $.async_when().done(function () { + utils.async_when().done(function () { def.reject(); }); } diff --git a/addons/web/static/src/js/views/list_view.js b/addons/web/static/src/js/views/list_view.js index b0ed903bdb5..d905dfdadfd 100644 --- a/addons/web/static/src/js/views/list_view.js +++ b/addons/web/static/src/js/views/list_view.js @@ -1459,7 +1459,7 @@ ListView.Groups = Class.extend({ var fields = _.pluck(_.select(this.columns, function(x) {return x.tag == "field";}), 'name'); var options = { offset: current_min - 1, limit: view._limit, context: {bin_size: true} }; - return $.async_when().then(function() { + return utils.async_when().then(function() { return dataset.read_slice(fields, options).then(function (records) { // FIXME: ignominious hacks, parents (aka form view) should not send two ListView#reload_content concurrently if (self.records.length) { @@ -1525,7 +1525,7 @@ ListView.Groups = Class.extend({ seq = to ? list.records.at(to - 1).get(seqname) : 0; var defs = []; var fct = function (dataset, id, seq) { - defs.push($.async_when().then(function () { + defs.push(utils.async_when().then(function () { var attrs = {}; attrs[seqname] = seq; return dataset.write(id, attrs, {internal_dataset_changed: true}); @@ -2047,5 +2047,3 @@ function for_ (id, field, node) { return ListView; }); - - diff --git a/addons/web/static/test/framework.js b/addons/web/static/test/framework.js index 70cc016fbcc..f3add74d7c5 100644 --- a/addons/web/static/test/framework.js +++ b/addons/web/static/test/framework.js @@ -433,30 +433,30 @@ odoo.define_section('Widget.events', ['web.Widget', 'web.core'], function (test) }); }); -odoo.define_section('Widget.async', ['web.Widget'], function (test) { - test("alive(alive)", function (assert, Widget) { +odoo.define_section('Widget.async', ['web.Widget', 'web.utils'], function (test) { + test("alive(alive)", function (assert, Widget, utils) { assert.expect(1); var widget = new (Widget.extend({})); - return $.async_when(widget.start()) - .then(function () { return widget.alive($.async_when()) }) + return utils.async_when(widget.start()) + .then(function () { return widget.alive(utils.async_when()) }) .then(function () { assert.ok(true); }); }); - test("alive(dead)", function (assert, Widget) { + test("alive(dead)", function (assert, Widget, utils) { assert.expect(1); var widget = new (Widget.extend({})); return $.Deferred(function (d) { - $.async_when(widget.start()) + utils.async_when(widget.start()) .then(function () { // destroy widget widget.destroy(); - var promise = $.async_when(); + var promise = utils.async_when(); // leave time for alive() to do its stuff promise.then(function () { - return $.async_when(); + return utils.async_when(); }).then(function () { assert.ok(true); d.resolve(); @@ -470,26 +470,26 @@ odoo.define_section('Widget.async', ['web.Widget'], function (test) { }); }); - test("alive(alive, true)", function (assert, Widget) { + test("alive(alive, true)", function (assert, Widget, utils) { assert.expect(1); var widget = new (Widget.extend({})); - return $.async_when(widget.start()) - .then(function () { return widget.alive($.async_when(), true) }) + return utils.async_when(widget.start()) + .then(function () { return widget.alive(utils.async_when(), true) }) .then(function () { assert.ok(true); }); }); - test("alive(dead, true)", function (assert, Widget) { + test("alive(dead, true)", function (assert, Widget, utils) { assert.expect(1); var done = assert.async(); var widget = new (Widget.extend({})); - $.async_when(widget.start()) + utils.async_when(widget.start()) .then(function () { // destroy widget widget.destroy(); console.log('destroyed'); - return widget.alive($.async_when().done(function () { console.log('when'); }), true); + return widget.alive(utils.async_when().done(function () { console.log('when'); }), true); }).then(function () { console.log('unfailed') assert.ok(false, "alive(p, true) should fail its promise"); @@ -630,4 +630,3 @@ odoo.define_section('server-formats', ['web.time'], function (test) { }); }); -