do_search: function (domain, context, group_by) {
var self = this,
- col_groupby = context.col_group_by || []; // get_col_groupby('ColGroupBy');
+ col_groupby = context.col_group_by || [];
if (group_by.length || col_groupby.length) {
this.groupby_mode = 'manual';
}
this.pivot_table.set_domain(domain);
+
+ var options;
if (this.groupby_mode === 'manual') {
- this.pivot_table.set_row_groupby(group_by);
- this.pivot_table.set_col_groupby(col_groupby);
+ options = {row: group_by, col: col_groupby};
} else {
- this.pivot_table.set_row_groupby(_.toArray(this.default_row_groupby));
- this.pivot_table.set_col_groupby(_.toArray(this.default_col_groupby));
+ options = {
+ row: _.toArray(this.default_row_groupby),
+ col: _.toArray(this.default_col_groupby),
+ };
}
+ this.pivot_table.set_groupby(options);
this.display_data();
},
(function () {
'use strict';
-openerp.web_graph.PivotTable = openerp.web.Class.extend({
+openerp.web_graph.PivotTable = openerp.web.Class.extend(openerp.EventDispatcherMixin, {
init: function (model, domain) {
+ openerp.EventDispatcherMixin.init.call(this);
this.rows = { groupby: [], main: null, headers: null };
this.cols = { groupby: [], main: null, headers: null };
this.cells = [];
}
},
- set_row_groupby: function (groupby) {
- if ((!groupby.length) && (this.rows.main)) {
- this.fold(this.rows.main);
- }
- if (!_.isEqual(groupby, this.rows.groupby)) {
- this.rows.groupby = groupby;
- this.invalidate_data();
- }
- },
+ set_groupby: function (groupbys) {
+ var col_changed = !_.isEqual(groupbys.col, this.cols.groupby),
+ row_changed = !_.isEqual(groupbys.row, this.rows.groupby);
- set_col_groupby: function (groupby) {
- if ((!groupby.length) && (this.cols.main)) {
- this.fold(this.cols.main);
- }
- if (!_.isEqual(groupby, this.cols.groupby)) {
- this.cols.groupby = groupby;
- this.invalidate_data();
+ this.rows.groupby = groupbys.row;
+ this.cols.groupby = groupbys.col;
+
+ if (col_changed || row_changed) {
+ this.invalidate_data();
+ this.trigger('groupby_changed');
}
},
header.is_expanded = false;
var fold_lvls = _.map(header.root.headers, function(g) {return g.path.length;});
var new_groupby_length = _.max(fold_lvls);
+
+ if (new_groupby_length < header.root.groupby.length) {
+ this.trigger('groupby_changed');
+ }
+
header.root.groupby.splice(new_groupby_length);
header.children = [];
this.cells = _.reject(this.cells, function (cell) {
return (_.contains(ids_to_remove, cell.x) || _.contains(ids_to_remove, cell.y));
});
+ this.trigger('redraw_required');
},
expand: function (header_id, field_id) {
if (header.path.length == header.root.groupby.length) {
header.root.groupby.push(field_id);
+ this.trigger('groupby_changed');
}
var otherDim = (header.root === this.cols) ? this.rows : this.cols;
});
});
header.is_expanded = true;
+ self.trigger('redraw_required');
});
},
var temp = this.rows;
this.rows = this.cols;
this.cols = temp;
- },
-
- fold_rows: function () {
- this.fold(this.rows.main);
- },
-
- fold_cols: function () {
- this.fold(this.cols.main);
+ this.trigger('groupby_changed');
+ this.trigger('redraw_required');
},
get_total: function (header) {
} else {
self.no_data = true;
}
+ self.trigger('redraw_required');
});
},