summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2019-09-06 09:58:34 +0000
committerAaron Bohy <aab@odoo.com>2019-09-18 06:11:03 +0000
commit8c6de8c452804094da17ac9e77c6f2b7b047dc29 (patch)
tree8b1fc62dc9492ead5bbe9b227dcacd107727f292 /addons/web/static/src
parentfc52cae0349ae660cd5313710f918494efda0322 (diff)
[FIX] web: list: clicking discard doesn't trigger an onFieldChange
Fixes the way records are discarded in list views Before this commit, clicking the "Discard changes" button in a list view after editing a record triggered both the "field changed" and the "discard changes" methods (resulting in 2 modals opening). Now, all fieldChanges are prevented when trying to click "Discard changes", and are re-applied if the click was unsuccessful (lifted left mouse button somewhere else). Task 2068280
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js
index a4d9de71907..bbe57cbf49d 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -52,6 +52,20 @@ var ListController = BasicController.extend({
this.noLeaf = params.noLeaf;
this.selectedRecords = params.selectedRecords || [];
this.multipleRecordsSavingPromise = null;
+ this.fieldChangedPrevented = false;
+ this._onMouseupWindowDiscard = null;
+ },
+
+ /**
+ * Overriden to properly unbind any mouseup listeners still bound to the window
+ *
+ * @override
+ */
+ destroy: function () {
+ if (this._onMouseupWindowDiscard) {
+ window.removeEventListener('mouseup', this._onMouseupWindowDiscard, true);
+ }
+ return this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
@@ -136,6 +150,7 @@ var ListController = BasicController.extend({
},
trigger: 'manual',
});
+ this.$buttons.on('mousedown', '.o_list_button_discard', this._onDiscardMousedown.bind(this));
this.$buttons.on('click', '.o_list_button_discard', this._onDiscard.bind(this));
this.$buttons.appendTo($node);
}
@@ -584,6 +599,31 @@ var ListController = BasicController.extend({
this._discardChanges();
},
/**
+ * Used to detect if the discard button is about to be clicked.
+ * Some focusout events might occur and trigger a save which
+ * is not always wanted when clicking "Discard".
+ *
+ * @param {MouseEvent} ev
+ * @private
+ */
+ _onDiscardMousedown: function (ev) {
+ var self = this;
+ this.fieldChangedPrevented = true;
+ this._onMouseupWindowDiscard = (function (mouseupEvent) {
+ window.removeEventListener('mouseup', self._onMouseupWindowDiscard, true);
+ self._onMouseupWindowDiscard = null;
+ var preventedEvent = self.fieldChangedPrevented;
+ self.fieldChangedPrevented = false;
+ // If the user starts clicking (mousedown) on the button and stops clicking
+ // (mouseup) outside of the button, we want to trigger the original onFieldChanged
+ // Event that was prevented in the meantime.
+ if (ev.target !== mouseupEvent.target && preventedEvent.constructor.name === 'OdooEvent') {
+ self._onFieldChanged(preventedEvent);
+ }
+ }).bind(this);
+ window.addEventListener('mouseup', this._onMouseupWindowDiscard, true);
+ },
+ /**
* Called when the user asks to edit a row -> Updates the controller buttons
*
* @param {OdooEvent} ev
@@ -641,7 +681,9 @@ var ListController = BasicController.extend({
var self = this;
var recordId = ev.data.dataPointID;
- if (this.renderer.inMultipleRecordEdition(recordId)) {
+ if (this.fieldChangedPrevented) {
+ this.fieldChangedPrevented = ev;
+ } else if (this.renderer.inMultipleRecordEdition(recordId)) {
// deal with edition of multiple lines
var _onSuccess = ev.data.onSuccess;
ev.data.onSuccess = function () {