From 3535e2dce0a2d2c87abdf27744f1bf30d7c66958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 14 Feb 2021 14:28:55 +0100 Subject: [PATCH] Add help for each value to selection and multiselection issue9649 review320021002 --- CHANGELOG | 1 + src/common.js | 29 +++++++++++++++++------ src/view.js | 3 ++- src/view/form.js | 61 +++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 75 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9e47794fb1..522d297068 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Manage help for each selection * Display revision on dialog * Support empty value for timedelta converter * Unify PYSON string format diff --git a/src/common.js b/src/common.js index b24f75b443..b05e128909 100644 --- a/src/common.js +++ b/src/common.js @@ -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)); } diff --git a/src/view.js b/src/view.js index 8e6d85a51c..84eb4e35aa 100644 --- a/src/view.js +++ b/src/view.js @@ -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]; } diff --git a/src/view/form.js b/src/view/form.js index e4646fafa2..a4f6962930 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -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('