summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_controller.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2019-01-11 07:42:05 +0000
committerAaron Bohy <aab@odoo.com>2019-01-14 11:31:55 +0000
commitb3f1081082ce33afe2513c2712bd0204fc5d8a22 (patch)
treeebcf20712edd86bd0dac6540e0be214aaebc2b2e /addons/web/static/src/js/views/basic/basic_controller.js
parent141c9a0ced5280aa9d6a7068c880f1e949e52fee (diff)
[FIX] web: form: call discardChanges while saving
Before this rev., there was a race condition when the user did some changes on a form view (triggering an onchange), saved and clicked on the breadcrumbs to leave the form view (before the onchange returned). As a consequence, the dialog telling the user that there are pending changes was displayed. This mostly occured on the main_flow_tour since the removal of an unnecessary check, and could be reproduced manually on a slow network. Basically, the check if there were pending changes was done too early (before the view was actually saved).
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, 9 insertions, 3 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 76adef0a154..01bbd9cd2fe 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -38,6 +38,10 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
FieldManagerMixin.init.call(this, this.model);
this.handle = params.initialState.id;
this.mode = params.mode || 'readonly';
+ // savingDef is used to ensure that we always wait for pending save
+ // operations to complete before checking if there are changes to
+ // discard when discardChanges is called
+ this.savingDef = $.when();
},
/**
* @override
@@ -102,14 +106,15 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
return true;
},
/**
- * Waits for the mutex to be unlocked and then calls _.discardChanges.
+ * Waits for the mutex to be unlocked and for changes to be saved, then
+ * calls _.discardChanges.
* This ensures that the confirm dialog isn't displayed directly if there is
* a pending 'write' rpc.
*
* @see _.discardChanges
*/
discardChanges: function (recordID, options) {
- return this.mutex.exec(function () {})
+ return $.when(this.mutex.getUnlockedDef(), this.savingDef)
.then(this._discardChanges.bind(this, recordID || this.handle, options));
},
/**
@@ -183,11 +188,12 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
// mutex-protected as commitChanges function of x2m has to be aware of
// all final changes made to a row.
var self = this;
- return this.mutex.getUnlockedDef().then(function () {
+ this.savingDef = this.mutex.getUnlockedDef().then(function () {
return self.renderer.commitChanges(recordID || self.handle).then(function () {
return self.mutex.exec(self._saveRecord.bind(self, recordID, options));
});
});
+ return this.savingDef;
},
/**
* @override