[IMP] puts everything into openerp.web_graph namespace, to avoid polluting global namespace (addon web_graph)

bzr revid: ged@openerp.com-20131127094718-boii5ncxfq8agfv9
This commit is contained in:
Gery Debongnie 2013-11-27 10:47:18 +01:00
parent 1f8b8165e8
commit 22162b5a10
4 changed files with 24 additions and 24 deletions

View File

@ -18,9 +18,9 @@ Graph Views for Web Client.
'static/lib/nvd3/d3.v3.js',
'static/lib/nvd3/nv.d3.js',
'static/lib/bootstrap/bootstrap.js',
'static/src/js/graph.js',
'static/src/js/pivot.js',
'static/src/js/charts.js',
'static/src/js/graph.js',
],
'css': [
'static/src/css/*.css',

View File

@ -1,5 +1,5 @@
function draw_chart (mode, pivot) {
openerp.web_graph.draw_chart = function (mode, pivot) {
var values = _.map(pivot.rows.main.children, function (pt) {
var val = pivot.get_value(pt.id, pivot.cols.main.id);
return {x: pt.title, y: val};
@ -7,18 +7,18 @@ function draw_chart (mode, pivot) {
switch (mode) {
case 'bar_chart':
bar_chart(values);
openerp.web_graph.bar_chart(values);
break;
case 'line_chart':
line_chart(values);
openerp.web_graph.line_chart(values);
break;
case 'pie_chart':
pie_chart(values);
openerp.web_graph.pie_chart(values);
break;
}
}
function bar_chart (data) {
openerp.web_graph.bar_chart = function (data) {
nv.addGraph(function () {
var chart = nv.models.discreteBarChart()
.tooltips(false)
@ -38,7 +38,7 @@ function bar_chart (data) {
});
};
function line_chart (data) {
openerp.web_graph.line_chart = function (data) {
nv.addGraph(function () {
var chart = nv.models.lineChart()
.x(function (d,u) { return u; })
@ -56,7 +56,7 @@ function line_chart (data) {
});
};
function pie_chart(data) {
openerp.web_graph.pie_chart = function(data) {
nv.addGraph(function () {
var chart = nv.models.pieChart()
.color(d3.scale.category10().range())

View File

@ -162,7 +162,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
this.data.domain = new instance.web.CompoundDomain(domain);
if (!this.pivot_table) {
self.pivot_table = new PivotTable(self.data);
self.pivot_table = new openerp.web_graph.PivotTable(self.data);
self.pivot_table.start().then(self.proxy('draw_table'));
} else {
this.pivot_table.domain = domain;
@ -189,7 +189,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
this.svg.remove();
this.svg = $('<div><svg></svg></div>');
this.$el.filter('.graph_main_content').append(this.svg);
draw_chart(mode, this.pivot_table);
openerp.web_graph.draw_chart(mode, this.pivot_table);
}
},

View File

@ -1,5 +1,5 @@
var PivotTable = openerp.web.Class.extend({
openerp.web_graph.PivotTable = openerp.web.Class.extend({
id_seed: 0,
init: function (options) {
@ -49,7 +49,7 @@ var PivotTable = openerp.web.Class.extend({
start: function () {
var self = this,
initial_group = this.expand(this.rows.main.id, this.rows.groupby[0]),
total = query_groups(this.model, this.measure, this.domain, [])
total = openerp.web_graph.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 +125,7 @@ var PivotTable = openerp.web.Class.extend({
}
var otherDim = (row.root === this.cols) ? this.rows : this.cols;
return query_groups_data(this.model, this.visible_fields(), row.domain, otherDim.groupby, field_id)
return openerp.web_graph.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 +159,7 @@ var PivotTable = openerp.web.Class.extend({
root: parent.root,
};
parent.children.splice(0,0, new_header);
insertAfter(parent.root.headers, parent, new_header);
openerp.web_graph.insertAfter(parent.root.headers, parent, new_header);
return new_header.id;
},
@ -319,7 +319,7 @@ var PivotTable = openerp.web.Class.extend({
groupbys = [rows, []];
}
def_array = _.map(groupbys, function (groupby) {
return query_groups(self.model, self.visible_fields(), self.domain, groupby);
return openerp.web_graph.query_groups(self.model, self.visible_fields(), self.domain, groupby);
});
return $.when.apply(null, def_array).then(function () {
@ -434,14 +434,14 @@ var PivotTable = openerp.web.Class.extend({
});
function removeFromArray(array, element) {
openerp.web_graph.removeFromArray = function (array, element) {
var index = array.indexOf(element);
if (index > -1) {
array.splice(index, 1);
}
}
function insertAfter(array, after, elem) {
openerp.web_graph.insertAfter = function (array, after, elem) {
array.splice(array.indexOf(after) + 1, 0, elem);
}
@ -450,7 +450,7 @@ function insertAfter(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
*/
function query_groups (model, fields, domain, groupbys) {
openerp.web_graph.query_groups = function (model, fields, domain, groupbys) {
return model.query(fields)
.filter(domain)
.group_by(groupbys)
@ -464,7 +464,7 @@ function query_groups (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 query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) {
return openerp.web_graph.query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) {
result.subgroups_data = subgroups;
});
}));
@ -475,19 +475,19 @@ function query_groups (model, fields, domain, groupbys) {
});
}
function query_groups_data(model, fields, domain, row_groupbys, col_groupby) {
return query_groups(model, fields, domain, [col_groupby].concat(row_groupbys)).then(function (groups) {
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) {
return _.map(groups, function (group) {
return format_group(group, []);
return openerp.web_graph.format_group(group, []);
});
});
}
function format_group (group, path) {
openerp.web_graph.format_group = function (group, path) {
group.path = path.concat(group.attributes.value[1]);
result = [group];
_.each(group.subgroups_data, function (subgroup) {
result = result.concat(format_group (subgroup, group.path));
result = result.concat(openerp.web_graph.format_group (subgroup, group.path));
});
return result;
}