summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2013-12-17 16:32:04 +0100
committerGery Debongnie <ged@openerp.com>2013-12-17 16:32:04 +0100
commit79250f0c077e3c463fd2d644b5fe398f82048a3f (patch)
treef90bcf1e51ae4b86cc72f3cdd79d1f43e63a3e4d /addons/web_graph/static/src
parent9596340bc52235e1a835e30a2e1e02b7a92fceed (diff)
[REF] adds event handling to pivot table class (triggers 'redraw_required' and 'groupby_changed' event when necessary (addon web_graph)
bzr revid: ged@openerp.com-20131217153204-43la1m8eqw632j05
Diffstat (limited to 'addons/web_graph/static/src')
-rw-r--r--addons/web_graph/static/src/js/graph.js14
-rw-r--r--addons/web_graph/static/src/js/pivot.js47
2 files changed, 31 insertions, 30 deletions
diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js
index 912f56e79fc..6805bce1793 100644
--- a/addons/web_graph/static/src/js/graph.js
+++ b/addons/web_graph/static/src/js/graph.js
@@ -138,20 +138,24 @@ instance.web_graph.GraphView = instance.web.View.extend({
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();
},
diff --git a/addons/web_graph/static/src/js/pivot.js b/addons/web_graph/static/src/js/pivot.js
index dd675270132..3938acb501e 100644
--- a/addons/web_graph/static/src/js/pivot.js
+++ b/addons/web_graph/static/src/js/pivot.js
@@ -4,8 +4,9 @@
(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 = [];
@@ -40,23 +41,16 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
}
},
- 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');
}
},
@@ -141,11 +135,17 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
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) {
@@ -154,6 +154,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
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;
@@ -179,6 +180,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
});
});
header.is_expanded = true;
+ self.trigger('redraw_required');
});
},
@@ -203,14 +205,8 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
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) {
@@ -255,6 +251,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
} else {
self.no_data = true;
}
+ self.trigger('redraw_required');
});
},