[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
This commit is contained in:
Gery Debongnie 2014-01-17 17:19:40 +01:00
parent 5aade330c2
commit ba9999c28a
3 changed files with 21 additions and 6 deletions

View File

@ -66,7 +66,8 @@ instance.web_graph.GraphView = instance.web.View.extend({
}, },
do_search: function (domain, context, group_by) { 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 (!this.graph_widget) {
if (group_by.length) { 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.appendTo(this.$el);
this.graph_widget.on('groupby_changed', this, this.proxy('register_groupby')); this.graph_widget.on('groupby_changed', this, this.proxy('register_groupby'));
this.graph_widget.on('groupby_swapped', this, this.proxy('swap_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; 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; }); 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 () { do_show: function () {
this.do_push_state({}); this.do_push_state({});
return this._super(); return this._super();

View File

@ -62,6 +62,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend(openerp.EventDispatcherMixin
}); });
self.pivot.activate(); self.pivot.activate();
self.put_measure_checkmarks(); 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 // returns the row groupbys as a list of fields (not the representation used
// internally by pivot table) // internally by pivot table)
get_row_groupby: function () { 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 () { get_col_groupby: function () {
return this.pivot.cols.groupby; return (this.pivot) ? this.pivot.cols.groupby : this.pivot_options.col_groupby;
}, },
reload: function () { get_domain: function () {
this.pivot.update_data(); return (this.pivot) ? this.pivot.domain : this.pivot_options.domain;
}, },
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View File

@ -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) { set: function (domain, row_groupby, col_groupby) {
var row_gbs = this.create_field_values(row_groupby), var row_gbs = this.create_field_values(row_groupby),
col_gbs = this.create_field_values(col_groupby), col_gbs = this.create_field_values(col_groupby),