Do not set selection after asynchronous call if parameters have changed
And do not store the current selection nor help but only pass them to the callback. Closes #15029 (grafted from 917de1b3e12443c919b90ba7cac9497bca047ef9) --HG-- branch : 8.0
This commit is contained in:
+37
-34
@@ -766,10 +766,7 @@
|
||||
|
||||
Sao.common.selection_mixin = {};
|
||||
Sao.common.selection_mixin.init = function() {
|
||||
this.selection = null;
|
||||
this.help = null;
|
||||
this.inactive_selection = [];
|
||||
this._last_domain = null;
|
||||
this._values2selection = {};
|
||||
this._domain_cache = {};
|
||||
if (this.nullable_widget === undefined) {
|
||||
@@ -793,9 +790,8 @@
|
||||
return a[1].localeCompare(b[1]);
|
||||
});
|
||||
}
|
||||
this.selection = jQuery.extend([], selection);
|
||||
this.help = this.attributes.help_selection || {};
|
||||
if (callback) callback(this.selection, this.help);
|
||||
let help = this.attributes.help_selection || {};
|
||||
if (callback) callback(selection, help);
|
||||
};
|
||||
if (!(selection instanceof Array) &&
|
||||
!(key in this._values2selection)) {
|
||||
@@ -826,7 +822,7 @@
|
||||
const _update_selection = () => {
|
||||
if (!field) {
|
||||
if (callback) {
|
||||
callback(this.selection, this.help);
|
||||
callback([], {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -836,26 +832,25 @@
|
||||
var value = record._get_on_change_args(change_with);
|
||||
delete value.id;
|
||||
Sao.common.selection_mixin.init_selection.call(
|
||||
this, value, () => {
|
||||
Sao.common.selection_mixin.filter_selection.call(
|
||||
this, domain, record, field);
|
||||
if (callback) {
|
||||
callback(this.selection, this.help);
|
||||
this, value, (selection, help) => {
|
||||
let cur_value = record._get_on_change_args(change_with);
|
||||
delete cur_value.id;
|
||||
if (JSON.stringify(value) == JSON.stringify(cur_value)) {
|
||||
selection = Sao.common.selection_mixin
|
||||
.filter_selection.call(
|
||||
this, domain, record, field, selection);
|
||||
if (callback) {
|
||||
callback(selection, help);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var context = field.get_context(record);
|
||||
var jdomain = JSON.stringify([domain, context]);
|
||||
if (jdomain in this._domain_cache) {
|
||||
this.selection = this._domain_cache[jdomain];
|
||||
this._last_domain = [domain, context];
|
||||
}
|
||||
if ((this._last_domain !== null) &&
|
||||
Sao.common.compare(domain, this._last_domain[0]) &&
|
||||
(JSON.stringify(context) ==
|
||||
JSON.stringify(this._last_domain[1]))) {
|
||||
let selection = this._domain_cache[jdomain];
|
||||
if (callback) {
|
||||
callback(this.selection, this.help);
|
||||
callback(selection, {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -883,23 +878,31 @@
|
||||
help[x.id] = x[help_field];
|
||||
}
|
||||
}
|
||||
this._last_domain = [domain, context];
|
||||
this._domain_cache[jdomain] = selection;
|
||||
this.selection = jQuery.extend([], selection);
|
||||
this.help = help;
|
||||
if (callback) {
|
||||
callback(this.selection, this.help);
|
||||
|
||||
let cur_domain = field.get_domain(record);
|
||||
let cur_context = field.get_context(record);
|
||||
if (Sao.common.compare(domain, cur_domain)
|
||||
&& (JSON.stringify(context) ==
|
||||
JSON.stringify(cur_context))) {
|
||||
if (callback) {
|
||||
callback(selection, help);
|
||||
}
|
||||
}
|
||||
});
|
||||
prm.fail(() => {
|
||||
var selection = [];
|
||||
var selection = [], help = {};
|
||||
if (this.nullable_widget) {
|
||||
selection.push([null, '']);
|
||||
}
|
||||
this._last_domain = null;
|
||||
this.selection = selection;
|
||||
if (callback) {
|
||||
callback(this.selection, this.help);
|
||||
let cur_domain = field.get_domain(record);
|
||||
let cur_context = field.get_context(record);
|
||||
if (Sao.common.compare(domain, cur_domain)
|
||||
&& (JSON.stringify(context) ==
|
||||
JSON.stringify(cur_context))) {
|
||||
if (callback) {
|
||||
callback(selection, help);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -907,9 +910,9 @@
|
||||
this._selection_prm.always(_update_selection);
|
||||
};
|
||||
Sao.common.selection_mixin.filter_selection = function(
|
||||
domain, record, field) {
|
||||
domain, record, field, selection) {
|
||||
if (jQuery.isEmptyObject(domain)) {
|
||||
return;
|
||||
return selection;
|
||||
}
|
||||
|
||||
var inversion = new Sao.common.DomainInversion();
|
||||
@@ -932,12 +935,12 @@
|
||||
var allowed_models = field.get_models(record);
|
||||
evaluator = _model_evaluator(allowed_models);
|
||||
} else if (type_ == 'multiselection') {
|
||||
return;
|
||||
return selection;
|
||||
} else {
|
||||
evaluator = _value_evaluator;
|
||||
}
|
||||
|
||||
this.selection = this.selection.filter(evaluator);
|
||||
return selection.filter(evaluator);
|
||||
};
|
||||
Sao.common.selection_mixin.get_inactive_selection = function(value) {
|
||||
if (!this.attributes.relation) {
|
||||
|
||||
@@ -2283,7 +2283,7 @@ function eval_pyson(value){
|
||||
field, (selection, help) => {
|
||||
this.set_selection(selection, help);
|
||||
if (callbak) {
|
||||
callbak(help);
|
||||
callbak(selection, help);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2301,14 +2301,14 @@ function eval_pyson(value){
|
||||
display_update_selection: function() {
|
||||
var record = this.record;
|
||||
var field = this.field;
|
||||
this.update_selection(record, field, help => {
|
||||
this.update_selection(record, field, (selection, help) => {
|
||||
if (!field) {
|
||||
this.select.val('');
|
||||
return;
|
||||
}
|
||||
var value = field.get(record);
|
||||
var prm, found = false;
|
||||
for (const option of this.selection) {
|
||||
for (const option of selection) {
|
||||
if (option[0] === value) {
|
||||
found = true;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user