From 346cef95a4e0a9c5c03b0653313121c45670a250 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 12 Mar 2015 15:27:25 +0100 Subject: [PATCH] [ADD] allow to open linked record of one of the axes is a many2one field --- .../src/css/web_widget_x2many_2d_matrix.css | 4 ++ .../src/js/web_widget_x2many_2d_matrix.js | 47 ++++++++++++++----- .../src/xml/web_widget_x2many_2d_matrix.xml | 8 ++-- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/web_widget_x2many_2d_matrix/static/src/css/web_widget_x2many_2d_matrix.css b/web_widget_x2many_2d_matrix/static/src/css/web_widget_x2many_2d_matrix.css index e69de29b..2992579d 100644 --- a/web_widget_x2many_2d_matrix/static/src/css/web_widget_x2many_2d_matrix.css +++ b/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; +} diff --git a/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js b/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js index b157a679..f9ebeb25 100644 --- a/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js +++ b/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); }, diff --git a/web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml b/web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml index fe3f82d3..625a2d20 100644 --- a/web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml +++ b/web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml @@ -1,18 +1,18 @@ -
+
- +
- - + + Total