summaryrefslogtreecommitdiff
path: root/addons/base_graph/static/src/js/graph.js
diff options
context:
space:
mode:
authorKunal Chavda (OpenERP) <kch@tinyerp.com>2011-04-21 14:35:52 +0530
committerKunal Chavda (OpenERP) <kch@tinyerp.com>2011-04-21 14:35:52 +0530
commit6b56e10d11b518e4b036e93ddd89ede2e2325c42 (patch)
treef84e33479b427929d3cf9f7a4795ecb27b74f0f3 /addons/base_graph/static/src/js/graph.js
parent7b37f593173193452347cb12e4c3c241ba3b1c55 (diff)
[IMP]Improved code for search and group record.
bzr revid: kch@tinyerp.com-20110421090552-ynzfrg2nvduseov3
Diffstat (limited to 'addons/base_graph/static/src/js/graph.js')
-rw-r--r--addons/base_graph/static/src/js/graph.js76
1 files changed, 47 insertions, 29 deletions
diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js
index 86ce064acbc..56bf784a02f 100644
--- a/addons/base_graph/static/src/js/graph.js
+++ b/addons/base_graph/static/src/js/graph.js
@@ -37,22 +37,23 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
this.group_field = '';
this.orientation = this.fields_view.arch.attrs.orientation || '';
for(fld in this.fields_view.arch.children) {
- if (this.fields_view.arch.children[fld].attrs.operator) {
+ if (this.fields_view.arch.children[fld].attrs.operator) {
this.operator_field = this.fields_view.arch.children[fld].attrs.name;
}
else if (this.fields_view.arch.children[fld].attrs.group) {
- this.group_field = this.fields_view.arch.children[fld].attrs.name
+ this.group_field = this.fields_view.arch.children[fld].attrs.name;
}
else {
- this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name)
+ this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name);
}
}
-
+
this.load_chart();
},
-
+
load_chart: function() {
var self = this;
+
this.dataset.read_ids(
this.dataset.ids,
this.fields,
@@ -61,80 +62,96 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
}
)
},
-
+
schedule_chart: function(result) {
-
this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart}));
-
+
for(res in result) {
for(fld in result[res]) {
if (fld != 'state') {
if (typeof result[res][fld] == 'object') {
result[res][fld] = result[res][fld][result[res][fld].length - 1];
}
-
+
}
}
}
+
if(this.chart == 'bar') {
- return this.schedule_bar(result, "barchart")
+ return this.schedule_bar(result, "barchart")
} else if(this.chart == "pie") {
return this.schedule_pie(result, "piechart");
}
-
+
},
-
+
schedule_bar: function(result, container) {
var self = this;
- this.chart = this.orientation == 'horizontal'? 'barH' : this.chart || 'bar';
-
+ var view_chart = this.orientation == 'horizontal'? 'barH' : this.chart || 'bar';
+
var bar_chart = new dhtmlxchartChart({
- view: this.chart,
+ view: view_chart,
container: container,
gradient: "3d",
border: false,
- value: "#"+this.operator_field+"#",
- label: self.orientation == 'horizontal' ? '#'+this.operator_field+'#' : "#"+this.chart_info_fields[0]+'#',
width: 30,
- tooltip: self.orientation == 'horizontal' ? "#"+this.chart_info_fields[0]+'#': "#"+this.operator_field+"#",
origin:0,
- legend: {
+ legend: {
align:"right",
valign:"top",
marker:{
type:"round",
width:12
},
- template: self.fields[this.operator_field]['string']
+ template: self.fields[self.operator_field]['string']
+
}
});
-
- if(this.chart == 'barH') {
+
+ if(self.group_field) {
+ bar_chart.define("group",{
+ by:"#"+self.chart_info_fields[0]+"#",
+ map:{
+ map_fld:["#"+self.operator_field+"#", "sum"]
+ }
+ });
+ bar_chart.define("value","#map_fld#");
+ bar_chart.define("label","#map_fld#");
+ }
+ else{
+ bar_chart.define("value","#"+self.operator_field+"#");
+ bar_chart.define("label","#"+self.chart_info_fields[0]+"#");
+ }
+
+ if(view_chart == 'barH') {
bar_chart.define("xAxis",{
title: this.fields[this.operator_field]['string'],
lines: true
});
-
+
bar_chart.define("yAxis",{
- template: "#"+this.chart_info_fields[0]+'#',
+ template: "#id#",
title: this.fields[this.chart_info_fields[0]]['string'],
lines: true
});
+
} else {
bar_chart.define("xAxis",{
template:"#"+this.chart_info_fields[0]+"#",
title: this.fields[this.chart_info_fields[0]]['string'],
lines: true
});
-
+
bar_chart.define("yAxis",{
title: this.fields[this.operator_field]['string'],
lines: true,
});
+
}
- bar_chart.parse(result,"json");
+ bar_chart.parse(result,"json");
+
},
-
+
schedule_pie: function(result, container) {
var chart = new dhtmlxchartChart({
view:"pie",
@@ -157,9 +174,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
});
chart.parse(result,"json");
},
-
+
do_search: function(domains, contexts, groupbys) {
var self = this;
+
this.rpc('/base/session/eval_domain_and_context', {
domains: domains,
contexts: contexts,
@@ -172,8 +190,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
self.schedule_chart(result)
});
});
- },
+ },
});