From 3460bda5203ce365bdc56a79ef906217219acb6d Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Tue, 16 May 2017 11:35:23 +0200 Subject: [FIX] web: disable stat buttons until action resolution Previously, it was possible to click multiple times on stat buttons while still waiting for the result of a previous button click. This could end up with the web client in strange states or, worse, lead to tracebacks. Because of this, we decided to disable the buttons once one of them is clicked and restore them afterwards. By doing this, we encovered a place in the code where a failed deferred would not be properly forwarded back to the caller, which meant, in our case, that the buttons would not be enabled back in case the action failed. This is now fixed. Initial methods to fix this issue used to break the test below. Because the label of the assertion this used to break was contradictory with the value it was actually expecting, we decided to fix it as well. --- addons/web/static/src/js/views/basic/basic_controller.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_controller.js') diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 3b24df19e3e..8d35e7f8fcd 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -248,9 +248,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var self = this; var def = $.Deferred(); var reload = function () { - if (!self.isDestroyed()) { - self.reload(); - } + return self.isDestroyed() ? $.when() : self.reload(); }; record = record || this.model.get(this.handle); var recordID = record.data.id; @@ -262,10 +260,14 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { res_ids: [recordID], on_closed: function (reason) { if (!_.isObject(reason)) { - reload(); + reload(reason); } }, - on_fail: reload, + on_fail: function (reason) { + reload().always(function() { + def.reject(reason); + }) + }, on_success: def.resolve.bind(def), }); return this.alive(def); -- cgit v1.2.3