support reference fields in many2one_clickable widget

pull/1438/head
Holger Brunn 2016-08-30 11:14:41 +02:00 committed by Simone
parent 4a960adc51
commit 07d93f11fa
2 changed files with 21 additions and 10 deletions

View File

@ -1,8 +1,8 @@
Clickable many2one fields for tree views
========================================
This addon provides a separate widget to allow many2one fields in a tree view
open the linked resource when clicking on their name.
This addon provides a separate widget to allow many2one or reference fields in
a tree view open the linked resource when clicking on their name.
You can also define a system parameter to have this behaviour for all the
existing many2one fields in tree views.
@ -15,9 +15,9 @@ Install it the regular way.
Configuration
=============
If you want to have all many2one fields clickable by default, you have to
define in *Configuration > Technical > Parameters > System parameters*, a new
parameter with name `web_tree_many2one_clickable.default` and with value
If you want to have all many2one and reference fields clickable by default, you
have to define in *Configuration > Technical > Parameters > System parameters*,
a new parameter with name `web_tree_many2one_clickable.default` and with value
`true`.
Usage

View File

@ -59,11 +59,22 @@ openerp.web_tree_many2one_clickable = function(instance, local)
_format: function (row_data, options)
{
if (this.use_many2one_clickable) {
return _.str.sprintf('<a class="oe_form_uri" data-many2one-clickable-model="%s" data-many2one-clickable-id="%s">%s</a>',
this.relation,
row_data[this.id].value[0],
_.escape(row_data[this.id].value[1] || options.value_if_empty));
if (this.use_many2one_clickable && !!row_data[this.id]) {
var values = {
model: this.relation,
id: row_data[this.id].value[0],
name: _.escape(row_data[this.id].value[1] || options.value_if_empty),
}
if(this.type == 'reference' && !!row_data[this.id + '__display'])
{
values.model = row_data[this.id].value.split(',', 1)[0];
values.id = row_data[this.id].value.split(',', 2)[1];
values.name = _.escape(row_data[this.id + '__display'].value || options.value_if_empty);
}
return _.str.sprintf(
'<a class="oe_form_uri" data-many2one-clickable-model="%(model)s" data-many2one-clickable-id="%(id)s">%(name)s</a>',
values
);
}
else {
return this._super(row_data, options);