Browse Source

[ADD] allow to open linked record

of one of the axes is a many2one field
pull/1106/head
Holger Brunn 10 years ago
committed by Jairo Llopis
parent
commit
346cef95a4
  1. 4
      web_widget_x2many_2d_matrix/static/src/css/web_widget_x2many_2d_matrix.css
  2. 47
      web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js
  3. 8
      web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml

4
web_widget_x2many_2d_matrix/static/src/css/web_widget_x2many_2d_matrix.css

@ -0,0 +1,4 @@
.oe_form_field_x2many_2d_matrix th.oe_link
{
cursor: pointer;
}

47
web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js

@ -166,18 +166,12 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
return _.keys(this.by_y_axis);
},
// get x axis labels
get_x_axis_labels: function()
// get the label for a value on the x axis
get_x_axis_label: function(x)
{
var self = this;
return _.map(
this.get_x_axis_values(),
function(val)
{
return self.get_field_value(
_.first(_.values(self.by_x_axis[val])),
self.field_label_x_axis, true);
});
return this.get_field_value(
_.first(_.values(this.by_x_axis[x])),
this.field_label_x_axis, true);
},
// get the label for a value on the y axis
@ -264,6 +258,36 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
});
},
setup_many2one_axes: function()
{
if(this.fields[this.field_x_axis].type == 'many2one')
{
this.$el.find('th[data-x]').addClass('oe_link')
.click(_.partial(
this.proxy(this.many2one_axis_click),
this.field_x_axis, 'x'));
}
if(this.fields[this.field_y_axis].type == 'many2one')
{
this.$el.find('tr[data-y] th').addClass('oe_link')
.click(_.partial(
this.proxy(this.many2one_axis_click),
this.field_y_axis, 'y'));
}
},
many2one_axis_click: function(field, id_attribute, e)
{
this.do_action({
type: 'ir.actions.act_window',
name: this.fields[field].string,
res_model: this.fields[field].relation,
res_id: jQuery(e.currentTarget).data(id_attribute),
views: [[false, 'form']],
target: 'current',
})
},
start: function()
{
var self = this;
@ -288,6 +312,7 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
});
this.compute_totals();
this.setup_many2one_axes();
return this._super.apply(this, arguments);
},

8
web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml

@ -1,18 +1,18 @@
<templates>
<t t-name="FieldX2Many2dMatrix">
<div>
<div t-att-class="widget.widget_class">
<table class="oe_list_content">
<thead>
<tr class="oe_list_header_columns">
<th />
<th t-foreach="widget.get_x_axis_labels()" t-as="label">
<t t-esc="label" />
<th t-foreach="widget.get_x_axis_values()" t-as="x" t-att-data-x="x">
<t t-esc="widget.get_x_axis_label(x)" />
</th>
<th t-if="widget.show_row_totals">Total</th>
</tr>
</thead>
<tbody>
<tr t-foreach="widget.get_y_axis_values()" t-as="y">
<tr t-foreach="widget.get_y_axis_values()" t-as="y" t-att-data-y="y">
<th><t t-esc="widget.get_y_axis_label(y)" /></th>
<td t-foreach="widget.get_x_axis_values()" t-as="x" class="oe_list_field_cell">
<span t-att-class="widget.get_xy_value_class()">

Loading…
Cancel
Save