diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-12-12 18:39:43 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-12-12 18:39:43 +0100 |
| commit | b37cc1f9b7897759a86cdccfa1b06d58361a97da (patch) | |
| tree | f43246fae635fe7c33114c02ef437756f6387ae4 /addons/web/static/src/js/fields | |
| parent | 9d2d9a3528c7cf595c5f1d040ebf13748497add8 (diff) | |
| parent | a2ea4ba095cd82adae4cac917aa2485d30c8071e (diff) | |
[MERGE] forward port branch saas-16 up to a2ea4ba095c
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 6f775e789d4..9cdadb1051a 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -95,6 +95,7 @@ var FieldMany2One = AbstractField.extend({ template: 'FieldMany2One', custom_events: _.extend({}, AbstractField.prototype.custom_events, { 'closed_unset': '_onDialogClosedUnset', + 'field_changed': '_onFieldChanged', 'quick_create': '_onQuickCreate', 'search_create_popup': '_onSearchCreatePopup', }), @@ -124,6 +125,12 @@ var FieldMany2One = AbstractField.extend({ // 'recordParams' is a dict of params used when calling functions // 'getDomain' and 'getContext' on this.record this.recordParams = {fieldName: this.name, viewType: this.viewType}; + // We need to know if the widget is dirty (i.e. if the user has changed + // the value, and those changes haven't been acknowledged yet by the + // environment), to prevent erasing that new value on a reset (e.g. + // coming by an onchange on another field) + this.isDirty = false; + this.lastChangeEvent = undefined; }, start: function () { // booleean indicating that the content of the input isn't synchronized @@ -151,9 +158,31 @@ var FieldMany2One = AbstractField.extend({ * TODO */ reinitialize: function (value) { + this.isDirty = false; this.floating = false; this._setValue(value); }, + /** + * Re-renders the widget if it isn't dirty. The widget is dirty if the user + * changed the value, and that change hasn't been acknowledged yet by the + * environment. For example, another field with an onchange has been updated + * and this field is updated before the onchange returns. Two '_setValue' + * are done (this is sequential), the first one returns and this widget is + * reset. However, it has pending changes, so we don't re-render. + * + * @override + */ + reset: function (record, event) { + this._reset(record, event); + if (!event || event === this.lastChangeEvent) { + this.isDirty = false; + } + if (this.isDirty) { + return $.when(); + } else { + return this._render(); + } + }, //-------------------------------------------------------------------------- // Private @@ -238,6 +267,16 @@ var FieldMany2One = AbstractField.extend({ return value.split('\n')[0]; }, /** + * Listens to events 'field_changed' to keep track of the last event that + * has been trigerred. This allows to detect that all changes have been + * acknowledged by the environment. + * + * @param {OdooEvent} event 'field_changed' event + */ + _onFieldChanged: function (event) { + this.lastChangeEvent = event; + }, + /** * @private * @param {string} name * @returns {Deferred} resolved after the name_create or when the slowcreate @@ -476,6 +515,7 @@ var FieldMany2One = AbstractField.extend({ * @private */ _onDialogClosedUnset: function () { + this.isDirty = false; this.floating = false; this._render(); }, @@ -544,6 +584,7 @@ var FieldMany2One = AbstractField.extend({ // confirmation that the many2one is not properly set. return; } + this.isDirty = true; if (this.$input.val() === "") { this.reinitialize(false); } else if (this._getDisplayName(this.m2o_value) !== this.$input.val()) { |
