summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-06-02 15:35:29 +0200
committerAaron Bohy <aab@odoo.com>2017-06-07 08:08:49 +0200
commit67747e6fa5f4c1b27eed5dfd7231001e98fb34c1 (patch)
tree3f4a909e71b380da3bd4935496ce6b944d140efb /addons/web/static/src/js/fields
parente9de309511d64897444645f8a9ea4bf701709bb8 (diff)
[FIX] web: FieldOne2Many: re-activate 'Add an item'
The 'Add an item' button of one2many editable lists is deactivated once clicked (since rev. f9a1241) to prevent concurrent record creation. It is re-activated when the record has been created. Unfortunately, it might happen that the record is actually not created, so in this case the button is never re-activated. This happens for example on the customer invoice form view, if the user tries to add a line before selecting a partner.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js11
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js5
2 files changed, 11 insertions, 5 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 5908f7f5a8b..137d2954993 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -351,12 +351,13 @@ var AbstractField = Widget.extend({
* @param {Object} [options]
* @param {boolean} [options.forceChange=false] if true, the change event will be
* triggered even if the new value is the same as the old one
+ * @returns {Deferred}
*/
_setValue: function (value, options) {
// we try to avoid doing useless work, if the value given has not
// changed. Note that we compare the unparsed values.
if (this.lastSetValue === value || (this.value === false && value === '')) {
- return;
+ return $.when();
}
this.lastSetValue = value;
try {
@@ -364,18 +365,22 @@ var AbstractField = Widget.extend({
this._isValid = true;
} catch (e) {
this._isValid = false;
- return;
+ return $.Deferred().reject();
}
if (!(options && options.forceChange) && this._isSameValue(value)) {
- return;
+ return $.when();
}
+ var def = $.Deferred();
var changes = {};
changes[this.name] = value;
this.trigger_up('field_changed', {
dataPointID: this.dataPointID,
changes: changes,
viewType: this.viewType,
+ onSuccess: def.resolve.bind(def),
+ onFailure: def.reject.bind(def),
});
+ return def;
},
//--------------------------------------------------------------------------
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index e13c3d29004..e9af73c1343 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -964,7 +964,6 @@ var FieldOne2Many = FieldX2Many.extend({
var index = self.editable === 'top' ? 0 : self.value.data.length - 1;
var newID = self.value.data[index].id;
self.renderer.editRecord(newID);
- self.creatingRecord = false;
}
}
});
@@ -1014,6 +1013,7 @@ var FieldOne2Many = FieldX2Many.extend({
* in the kanban view
*/
_onAddRecord: function (ev) {
+ var self = this;
// we don't want interference with the components upstream.
ev.stopPropagation();
@@ -1023,10 +1023,11 @@ var FieldOne2Many = FieldX2Many.extend({
this._setValue({
operation: 'CREATE',
position: this.editable,
+ }).always(function () {
+ self.creatingRecord = false;
});
}
} else {
- var self = this;
this._openFormDialog({
on_saved: function (record) {
self._setValue({ operation: 'ADD', id: record.id });