summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_controller.js
diff options
context:
space:
mode:
authorDavid Monjoie <dmo@odoo.com>2017-05-16 11:35:23 +0200
committerDavid Monjoie <dmo@odoo.com>2017-05-23 11:41:15 +0200
commit3460bda5203ce365bdc56a79ef906217219acb6d (patch)
treeefa9cc5482db354743c2189ad082fe40d48b6c34 /addons/web/static/src/js/views/basic/basic_controller.js
parente783844f5b66acfc298a98f331bf432420fdbbf7 (diff)
[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.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_controller.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js12
1 files changed, 7 insertions, 5 deletions
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);