From 809cdbb153e9d9211fccaff47895524c93c2c635 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 7 Jul 2015 09:41:43 +0200 Subject: [PATCH] [IMP] web: use a mutex on the object instead of create one in the send_commands method: no crossed change values, keep internal_dataset_changed for other widgets (like editable list) --- .../src/js/views/form_relational_widgets.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/js/views/form_relational_widgets.js b/addons/web/static/src/js/views/form_relational_widgets.js index d6702ca9082..65fb75fe34f 100644 --- a/addons/web/static/src/js/views/form_relational_widgets.js +++ b/addons/web/static/src/js/views/form_relational_widgets.js @@ -448,12 +448,14 @@ var AbstractManyField = common.AbstractField.extend({ this.dataset.child_name = this.name; this.set('value', []); this.starting_ids = []; + this.mutex = new utils.Mutex(); this.has_not_committed_changes = false; this.view.on("load_record", this, this._on_load_record); this.dataset.on('dataset_changed', this, function() { self.has_not_committed_changes = true; + // don't trigger changes if all commands are not resolved // the editable lists change the dataset without call AbstractManyField methods - if (!self.internal_dataset_changed) { + if (self.mutex.def.state() === "resolved" && !self.internal_dataset_changed) { self.trigger("change:commands"); } }); @@ -575,15 +577,12 @@ var AbstractManyField = common.AbstractField.extend({ send_commands: function (command_list, options) { var self = this; var def = $.Deferred(); - var mutex = new utils.Mutex(); var dataset = this.dataset; var res = true; options = options || {}; - var tmp = this.internal_dataset_changed; - this.internal_dataset_changed = true; _.each(command_list, function(command) { - mutex.exec(function() { + self.mutex.exec(function() { var id = command[1]; switch (command[0]) { case COMMANDS.CREATE: @@ -621,10 +620,9 @@ var AbstractManyField = common.AbstractField.extend({ }); }); - mutex.exec(function () { - def.resolve(res); - self.internal_dataset_changed = tmp; + this.mutex.def.then(function () { self.trigger("change:commands"); + def.resolve(res); }); return def; }, @@ -681,7 +679,7 @@ var AbstractManyField = common.AbstractField.extend({ }, is_valid: function () { - return !this.has_not_committed_changes && this._super(); + return this.mutex.def.state() === "resolved" && !this.has_not_committed_changes && this._super(); }, is_false: function() {