summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src/js/pivot.js
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2013-11-27 12:19:53 +0100
committerGery Debongnie <ged@openerp.com>2013-11-27 12:19:53 +0100
commit76216fd3f33fca6461bc96caf525cbcdc0f24d6a (patch)
treeb5702ba91af6c0745c0e9a1cc95fac3d90f071d7 /addons/web_graph/static/src/js/pivot.js
parente0744a7427be939c1c9ac4a1629d67c40817795e (diff)
[REF] puts helper functions inside a closure to simplify the calls to these functions (addon web_graph)
bzr revid: ged@openerp.com-20131127111953-yfzdyllt1ty70xtu
Diffstat (limited to 'addons/web_graph/static/src/js/pivot.js')
-rw-r--r--addons/web_graph/static/src/js/pivot.js29
1 files changed, 16 insertions, 13 deletions
diff --git a/addons/web_graph/static/src/js/pivot.js b/addons/web_graph/static/src/js/pivot.js
index 2359ed30601..08b406661cd 100644
--- a/addons/web_graph/static/src/js/pivot.js
+++ b/addons/web_graph/static/src/js/pivot.js
@@ -1,4 +1,6 @@
+(function () {
+
openerp.web_graph.PivotTable = openerp.web.Class.extend({
id_seed: 0,
@@ -49,7 +51,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
start: function () {
var self = this,
initial_group = this.expand(this.rows.main.id, this.rows.groupby[0]),
- total = openerp.web_graph.query_groups(this.model, this.measure, this.domain, [])
+ total = query_groups(this.model, this.measure, this.domain, [])
.then(function (total) {
var val = total[0].attributes.aggregates[self.measure];
self.set_value(self.rows.main.id, self.cols.main.id, val);
@@ -125,7 +127,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
}
var otherDim = (row.root === this.cols) ? this.rows : this.cols;
- return openerp.web_graph.query_groups_data(this.model, this.visible_fields(), row.domain, otherDim.groupby, field_id)
+ return query_groups_data(this.model, this.visible_fields(), row.domain, otherDim.groupby, field_id)
.then(function (groups) {
_.each(groups.reverse(), function (group) {
var new_row_id = self.make_header(group, row);
@@ -159,7 +161,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
root: parent.root,
};
parent.children.splice(0,0, new_header);
- openerp.web_graph.insertAfter(parent.root.headers, parent, new_header);
+ insertAfter(parent.root.headers, parent, new_header);
return new_header.id;
},
@@ -319,7 +321,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
groupbys = [rows, []];
}
def_array = _.map(groupbys, function (groupby) {
- return openerp.web_graph.query_groups(self.model, self.visible_fields(), self.domain, groupby);
+ return query_groups(self.model, self.visible_fields(), self.domain, groupby);
});
return $.when.apply(null, def_array).then(function () {
@@ -434,14 +436,14 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
});
-openerp.web_graph.removeFromArray = function (array, element) {
+removeFromArray = function (array, element) {
var index = array.indexOf(element);
if (index > -1) {
array.splice(index, 1);
}
}
-openerp.web_graph.insertAfter = function (array, after, elem) {
+insertAfter = function (array, after, elem) {
array.splice(array.indexOf(after) + 1, 0, elem);
}
@@ -450,7 +452,7 @@ openerp.web_graph.insertAfter = function (array, after, elem) {
* with all the groupbys applied (this is done for now, but the goal
* is to modify read_group in order to allow eager and lazy groupbys
*/
-openerp.web_graph.query_groups = function (model, fields, domain, groupbys) {
+query_groups = function (model, fields, domain, groupbys) {
return model.query(fields)
.filter(domain)
.group_by(groupbys)
@@ -464,7 +466,7 @@ openerp.web_graph.query_groups = function (model, fields, domain, groupbys) {
var get_subgroups = $.when.apply(null, _.map(non_empty_results, function (result) {
var new_domain = result.model._domain;
var new_groupings = groupbys.slice(1);
- return openerp.web_graph.query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) {
+ return query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) {
result.subgroups_data = subgroups;
});
}));
@@ -475,20 +477,21 @@ openerp.web_graph.query_groups = function (model, fields, domain, groupbys) {
});
}
-openerp.web_graph.query_groups_data = function (model, fields, domain, row_groupbys, col_groupby) {
- return openerp.web_graph.query_groups(model, fields, domain, [col_groupby].concat(row_groupbys)).then(function (groups) {
+query_groups_data = function (model, fields, domain, row_groupbys, col_groupby) {
+ return query_groups(model, fields, domain, [col_groupby].concat(row_groupbys)).then(function (groups) {
return _.map(groups, function (group) {
- return openerp.web_graph.format_group(group, []);
+ return format_group(group, []);
});
});
}
-openerp.web_graph.format_group = function (group, path) {
+format_group = function (group, path) {
group.path = path.concat(group.attributes.value[1]);
result = [group];
_.each(group.subgroups_data, function (subgroup) {
- result = result.concat(openerp.web_graph.format_group (subgroup, group.path));
+ result = result.concat(format_group (subgroup, group.path));
});
return result;
}
+})(); \ No newline at end of file