diff --git a/addons/web_graph/static/src/js/graph_view.js b/addons/web_graph/static/src/js/graph_view.js index c2b3979199f..91fcefaf1b8 100644 --- a/addons/web_graph/static/src/js/graph_view.js +++ b/addons/web_graph/static/src/js/graph_view.js @@ -78,17 +78,23 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config); this.graph_widget.appendTo(this.$el); this.graph_widget.on('groupby_changed', this, this.proxy('register_groupby')); + this.graph_widget.on('groupby_swapped', this, this.proxy('swap_groupby')); this.ViewManager.on('switch_mode', this, function (e) { if (e === 'graph') this.graph_widget.reload(); }); return; } + if (this.swapped) { + this.swapped = false; + return; + } + this.graph_widget.set(domain, group_by, col_group_by); }, get_col_groupbys_from_searchview: function () { var facet = this.search_view.query.findWhere({category:'ColGroupBy'}), - groupby_list = facet ? facet.attributes.values : []; - return _.map(groupby_list, function (g) { return g.value.attrs.context.col_group_by; }); + groupby_list = facet ? facet.values.models : []; + return _.map(groupby_list, function (g) { return g.attributes.value.attrs.context.col_group_by; }); }, do_show: function () { @@ -132,6 +138,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }, + swap_groupby: function () { + this.swap = true; + this.register_groupby(); + }, + make_row_groupby_facets: function(groupbys) { return { category:'GroupBy', diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index d84c8d794f4..e9e3b4acb12 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -41,6 +41,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend(openerp.EventDispatcherMixin self.pivot = new openerp.web_graph.PivotTable(self.model, self.domain, self.fields, self.pivot_options); self.pivot.on('redraw_required', self, self.proxy('display_data')); self.pivot.on('groupby_changed', self, function () { self.trigger('groupby_changed'); }); + self.pivot.on('groupby_swapped', self, function () { self.trigger('groupby_swapped'); }); openerp.web.bus.on('click', self, function () { if (self.dropdown) { self.dropdown.remove(); diff --git a/addons/web_graph/static/src/js/pivot_table.js b/addons/web_graph/static/src/js/pivot_table.js index 79d351ce315..d7a836d98b8 100644 --- a/addons/web_graph/static/src/js/pivot_table.js +++ b/addons/web_graph/static/src/js/pivot_table.js @@ -4,7 +4,7 @@ (function () { 'use strict'; -// Pivot Table emits the events 'groupby_changed' and 'redraw_required' when necessary. +// Pivot Table emits the events 'groupby_changed', 'groupby_swapped' and 'redraw_required' when necessary. // PivotTable is initialized by default 'inactive', and require a call to activate() // after init to load initial data and start triggering events. openerp.web_graph.PivotTable = openerp.web.Class.extend(openerp.EventDispatcherMixin, { @@ -318,7 +318,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend(openerp.EventDispatcherM var temp = this.rows; this.rows = this.cols; this.cols = temp; - this.trigger('groupby_changed'); + this.trigger('groupby_swapped'); this.trigger('redraw_required'); },