Browse Source

support reference fields in many2one_clickable widget

pull/1162/head
Holger Brunn 8 years ago
committed by Anand Kansagra
parent
commit
8f6287b74d
  1. 10
      web_tree_many2one_clickable/README.rst
  2. 21
      web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js

10
web_tree_many2one_clickable/README.rst

@ -1,8 +1,8 @@
Clickable many2one fields for tree views 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 You can also define a system parameter to have this behaviour for all the
existing many2one fields in tree views. existing many2one fields in tree views.
@ -15,9 +15,9 @@ Install it the regular way.
Configuration 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`. `true`.
Usage Usage

21
web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js

@ -59,11 +59,22 @@ openerp.web_tree_many2one_clickable = function(instance, local)
_format: function (row_data, options) _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 { else {
return this._super(row_data, options); return this._super(row_data, options);

Loading…
Cancel
Save