summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
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 11:28:03 +0000
commitf15c0699062ad41a325fb94a1862502f36d21a7d (patch)
tree3f84f7bccd49ebb9fc50fa66bc809c1487256848 /addons/web/static/src/js
parent2cdd46b566d00aa6c8e6bb9452c3edde120ce2a3 (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/js')
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js28
1 files changed, 27 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 cf911ef5398..96f3f1cd556 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -108,6 +108,7 @@ var ListController = BasicController.extend({
this.noLeaf = params.noLeaf;
this.selectedRecords = params.selectedRecords || [];
this.multipleRecordsSavingPromise = null;
+ this.fieldChangedPrevented = false;
this.activeActions = _.extend({}, this.activeActions, {
download: this.renderer.arch.attrs.download ? !!JSON.parse(this.renderer.arch.attrs.download) : true,
});
@@ -195,6 +196,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);
}
@@ -674,6 +676,28 @@ 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;
+ window.addEventListener('mouseup', function (mouseupEvent) {
+ 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);
+ }
+ }, { capture: true, once: true });
+ },
+ /**
* Called when the user asks to edit a row -> Updates the controller buttons
*
* @param {OdooEvent} ev
@@ -738,7 +762,9 @@ var ListController = BasicController.extend({
ev.stopPropagation();
const 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
const _onSuccess = ev.data.onSuccess;
ev.data.onSuccess = () => {