Add help for each value to selection and multiselection

issue9649
review320021002
This commit is contained in:
Cédric Krier
2021-02-14 14:28:55 +01:00
parent cc4b356936
commit 3535e2dce0
4 changed files with 75 additions and 19 deletions
+1
View File
@@ -1,3 +1,4 @@
* Manage help for each selection
* Display revision on dialog
* Support empty value for timedelta converter
* Unify PYSON string format
+22 -7
View File
@@ -625,6 +625,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 = {};
@@ -642,6 +643,7 @@
}
var key = JSON.stringify(value);
var selection = this.attributes.selection || [];
var help = this.attributes.help_selection || {};
var prm;
var prepare_selection = function(selection) {
selection = jQuery.extend([], selection);
@@ -651,7 +653,8 @@
});
}
this.selection = jQuery.extend([], selection);
if (callback) callback(this.selection);
this.help = this.attributes.help_selection || {};
if (callback) callback(this.selection, this.help);
};
if (!(selection instanceof Array) &&
!(key in this._values2selection)) {
@@ -680,7 +683,7 @@
var _update_selection = function() {
if (!field) {
if (callback) {
callback(this.selection);
callback(this.selection, this.help);
}
return;
}
@@ -694,7 +697,7 @@
Sao.common.selection_mixin.filter_selection.call(
this, domain, record, field);
if (callback) {
callback(this.selection);
callback(this.selection, this.help);
}
}.bind(this));
} else {
@@ -709,14 +712,19 @@
(JSON.stringify(context) ==
JSON.stringify(this._last_domain[1]))) {
if (callback) {
callback(this.selection);
callback(this.selection, this.help);
}
return;
}
var fields = ['rec_name'];
var help_field = this.attributes.help_field;
if (help_field) {
fields.push(help_field);
}
var prm = Sao.rpc({
'method': 'model.' + this.attributes.relation +
'.search_read',
'params': [domain, 0, null, null, ['rec_name'], context]
'params': [domain, 0, null, null, fields, context]
}, record.model.session);
prm.done(function(result) {
var selection = [];
@@ -726,18 +734,25 @@
if (this.nullable_widget) {
selection.push([null, '']);
}
var help = {};
if (help_field){
result.forEach(function(x) {
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);
callback(this.selection, this.help);
}
}.bind(this));
prm.fail(function() {
this._last_domain = null;
this.selection = [];
if (callback) {
callback(this.selection);
callback(this.selection, this.help);
}
}.bind(this));
}
+2 -1
View File
@@ -144,7 +144,8 @@
'relation_field', 'views', 'invisible', 'add_remove',
'sort', 'context', 'size', 'filename', 'autocomplete',
'translate', 'create', 'delete', 'selection_change_with',
'schema_model', 'required'].forEach(function(name) {
'schema_model', 'required', 'help_selection', 'help_field',
].forEach(function(name) {
if ((name in field) && (!(name in node_attrs))) {
node_attrs[name] = field[name];
}
+50 -11
View File
@@ -1945,27 +1945,28 @@ function eval_pyson(value){
},
update_selection: function(record, field, callbak) {
Sao.common.selection_mixin.update_selection.call(this, record,
field, function(selection) {
this.set_selection(selection);
field, function(selection, help) {
this.set_selection(selection, help);
if (callbak) {
callbak();
callbak(help);
}
}.bind(this));
},
set_selection: function(selection) {
set_selection: function(selection, help) {
var select = this.select;
select.empty();
selection.forEach(function(e) {
select.append(jQuery('<option/>', {
'value': JSON.stringify(e[0]),
'text': e[1]
'text': e[1],
'title': help[e[0]],
}));
});
},
display_update_selection: function() {
var record = this.record;
var field = this.field;
this.update_selection(record, field, function() {
this.update_selection(record, field, function(help) {
if (!field) {
this.select.val('');
return;
@@ -1993,6 +1994,11 @@ function eval_pyson(value){
}
prm.done(function() {
this.select.val(JSON.stringify(value));
var title = help[value] || null;
if (this.attributes.help && title) {
title = this.attributes.help + '\n' + title;
}
this.select.attr('title', title);
}.bind(this));
}.bind(this));
},
@@ -2715,20 +2721,21 @@ function eval_pyson(value){
},
update_selection: function(record, field, callback) {
Sao.common.selection_mixin.update_selection.call(this, record,
field, function(selection) {
this.set_selection(selection);
field, function(selection, help) {
this.set_selection(selection, help);
if (callback) {
callback();
}
}.bind(this));
},
set_selection: function(selection) {
set_selection: function(selection, help) {
var select = this.select;
select.empty();
selection.forEach(function(e) {
select.append(jQuery('<option/>', {
'value': e[0],
'text': e[1]
'text': e[1],
'title': help[e[0]],
}));
});
},
@@ -3905,6 +3912,21 @@ function eval_pyson(value){
this, view, attributes);
this.select.prop('multiple', true);
},
set_selection: function(selection, help) {
Sao.View.Form.MultiSelection._super.set_selection.call(
this, selection, help);
var widget_help = this.attributes.help;
if (widget_help) {
this.select.children().each(function() {
var option = jQuery(this);
var help = option.attr('title');
if (help) {
help = widget_help + '\n' + help;
option.attr('title', help);
}
});
}
},
get modified() {
if (this.record && this.field) {
var group = new Set(this.field.get_eval(this.record));
@@ -4568,8 +4590,9 @@ function eval_pyson(value){
select.append(jQuery('<option/>', {
'value': JSON.stringify(e[0]),
'text': e[1],
'title': this.definition.help_selection[e[0]],
}));
});
}.bind(this));
},
set_readonly: function(readonly) {
this._readonly = readonly;
@@ -4592,6 +4615,11 @@ function eval_pyson(value){
},
set_value: function(value) {
this.input.val(JSON.stringify(value));
var title = this.definition.help_selection[value] || null;
if (this.definition.help && title) {
title = this.definition.help + '\n' + title;
}
this.input.attr('title', title);
},
});
@@ -4602,6 +4630,17 @@ function eval_pyson(value){
Sao.View.Form.Dict.MultiSelection._super
.create_widget.call(this);
this.input.prop('multiple', true);
var widget_help = this.definition.help;
if (widget_help) {
this.input.children().each(function() {
var option = jQuery(this);
var help = option.attr('title');
if (help) {
help = widget_help + '\n' + help;
option.attr('title', help);
}
});
}
},
get_value: function() {
var value = this.input.val();