From ba9999c28aa0e821924e5792a672eb429467ab6c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 17 Jan 2014 17:19:40 +0100 Subject: [PATCH] [FIX] fix crash happening when user goes to graph view, switch to other view, changes groupby and goes back to graph view. (addon web_graph) bzr revid: ged@openerp.com-20140117161940-3ojz17luxtsb9qfa --- addons/web_graph/static/src/js/graph_view.js | 17 +++++++++++++++-- addons/web_graph/static/src/js/graph_widget.js | 9 +++++---- addons/web_graph/static/src/js/pivot_table.js | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/addons/web_graph/static/src/js/graph_view.js b/addons/web_graph/static/src/js/graph_view.js index a192952ab5c..0af32c8af7d 100644 --- a/addons/web_graph/static/src/js/graph_view.js +++ b/addons/web_graph/static/src/js/graph_view.js @@ -66,7 +66,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, do_search: function (domain, context, group_by) { - var col_group_by = this.get_col_groupbys_from_searchview(); + var self = this, + col_group_by = this.get_col_groupbys_from_searchview(); if (!this.graph_widget) { if (group_by.length) { @@ -79,7 +80,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ 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(); }); + this.ViewManager.on('switch_mode', this, function (e) { + var domain = self.graph_widget.get_domain(), + col_gb = self.get_col_groupbys_from_searchview(), + row_gb = self.get_row_groupbys_from_searchview(); + + if (e === 'graph') this.graph_widget.set(domain, row_gb, col_gb); + }); return; } @@ -97,6 +104,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ return _.map(groupby_list, function (g) { return g.attributes.value.attrs.context.col_group_by; }); }, + get_row_groupbys_from_searchview: function () { + var facet = this.search_view.query.findWhere({category:'GroupBy'}), + groupby_list = facet ? facet.values.models : []; + return _.map(groupby_list, function (g) { return g.attributes.value.attrs.context.group_by; }); + }, + do_show: function () { this.do_push_state({}); return this._super(); diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index d774b66727e..1dc4510c5b6 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -62,6 +62,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend(openerp.EventDispatcherMixin }); self.pivot.activate(); self.put_measure_checkmarks(); + self.trigger('groupby_changed'); }); }, @@ -150,15 +151,15 @@ openerp.web_graph.Graph = openerp.web.Widget.extend(openerp.EventDispatcherMixin // returns the row groupbys as a list of fields (not the representation used // internally by pivot table) get_row_groupby: function () { - return this.pivot.rows.groupby; + return (this.pivot) ? this.pivot.rows.groupby : this.pivot_options.row_groupby; }, get_col_groupby: function () { - return this.pivot.cols.groupby; + return (this.pivot) ? this.pivot.cols.groupby : this.pivot_options.col_groupby; }, - reload: function () { - this.pivot.update_data(); + get_domain: function () { + return (this.pivot) ? this.pivot.domain : this.pivot_options.domain; }, // ---------------------------------------------------------------------- diff --git a/addons/web_graph/static/src/js/pivot_table.js b/addons/web_graph/static/src/js/pivot_table.js index 476891644d7..26c1395dff6 100644 --- a/addons/web_graph/static/src/js/pivot_table.js +++ b/addons/web_graph/static/src/js/pivot_table.js @@ -82,6 +82,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend(openerp.EventDispatcherM } }, + // return true if an update is triggered, false otherwise set: function (domain, row_groupby, col_groupby) { var row_gbs = this.create_field_values(row_groupby), col_gbs = this.create_field_values(col_groupby),