[IMP]Improved code for two operator fields are in view.

bzr revid: kch@tinyerp.com-20110525060900-n85m7ezzjhww5bw3
This commit is contained in:
Kunal Chavda (OpenERP) 2011-05-25 11:39:00 +05:30
parent 5ebaf91cb1
commit 47b14bddc5
1 changed files with 53 additions and 32 deletions

View File

@ -7,8 +7,7 @@ QWeb.add_template('/base_graph/static/src/xml/base_graph.xml');
openerp.base.views.add('graph', 'openerp.base_graph.GraphView');
openerp.base_graph.GraphView = openerp.base.Controller.extend({
init: function(view_manager, session, element_id, dataset, view_id) {
init: function(view_manager, session, element_id, dataset, view_id) {
this._super(session, element_id);
this.view_manager = view_manager;
this.dataset = dataset;
@ -35,12 +34,14 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
this.fields = this.fields_view.fields;
this.chart_info_fields = [];
this.operator_field = '';
this.operator_field_one = '';
this.operator = [];
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) {
this.operator_field = this.fields_view.arch.children[fld].attrs.name;
this.operator.push(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;
@ -49,36 +50,39 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name);
}
}
if(this.operator_field == ''){
this.operator_field = this.operator[0];
if(this.operator.length > 1){
this.operator_field_one = this.operator[1];
}
if(this.operator == ''){
this.operator_field = this.chart_info_fields[1];
}
this.chart_info = this.chart_info_fields[0];
this.x_title = this.fields[this.chart_info_fields[0]]['string'];
this.y_title = this.fields[this.operator_field]['string'];
this.load_chart();
self.load_chart();
},
load_chart: function(result) {
load_chart: function(data) {
var self = this;
if(result){
if(data){
this.x_title = this.all_fields[this.chart_info_fields[0]]['string'];
this.y_title = this.all_fields[this.operator_field]['string'];
self.schedule_chart(result);
self.schedule_chart(data);
}else{
this.dataset.read_ids(
this.dataset.ids,
{},
function(result) {
self.schedule_chart(result);
function(res) {
self.schedule_chart(res);
}
)
);
}
},
schedule_chart: function(result) {
this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart}));
this.opration_fld = {};
this.group_list = [];
if (result.length){
for(res in result) {
@ -88,26 +92,28 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
}
}
}
for (i in result){
var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field]
if (this.opration_fld[gen_key] == undefined){
var map_val = {}
map_val[this.operator_field] = result[i][this.operator_field];
if (this.operator.length > 1){
map_val[this.operator_field_one] = result[i][this.operator_field_one];
}
map_val[this.chart_info_fields] = result[i][this.chart_info_fields];
if (this.group_field){
map_val[this.group_field] = result[i][this.group_field].replace(" ", "_");
}else{
map_val[this.group_field] = result[i][this.group_field];
map_val[this.group_field] = result[i][this.group_field].split(' ').join('_');
}
this.opration_fld[gen_key] = map_val;
}else{
map_val = this.opration_fld[gen_key];
map_val[this.operator_field] = map_val[this.operator_field] + result[i][this.operator_field];
if (this.operator.length > 1){
map_val[this.operator_field_one] = map_val[this.operator_field_one] + result[i][this.operator_field_one];
}
this.opration_fld[gen_key] = map_val;
}
}
result = []
for (i in this.opration_fld){
result.push(this.opration_fld[i]);
@ -127,9 +133,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
var xystr = {};
var xyname = {};
var res = [];
this.group_list = [];
var newkey = '';
var COLOR_PALETTE = ['#cc99ff', '#75507b', '#ccccff', '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00',
var COLOR_PALETTE = ['#cc99ff', '#ccccff', '#48D1CC', '#CFD784', '#8B7B8B', '#75507b', '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00',
'#905000', '#9b0000', '#840067', '#9abe00', '#ffc900', '#510090', '#0000c9', '#009b00',
'#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', '#fcaf3e', '#ef2929', '#ff00c9',
'#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', '#f57900', '#cc0000', '#d400a8'];
@ -142,21 +149,25 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
for (i in result){
if (self.group_field){
var newkey =result[i][self.group_field].replace(" ", "_");
newkey =result[i][self.group_field].split(' ').join('_');
}else{
var newkey =result[i][self.group_field];
newkey = "val";
}
if (jQuery.inArray(newkey, self.group_list) == -1){
self.group_list.push(newkey);
if(this.operator.length > 1){
var newkey_one = "val1";
self.group_list.push(newkey_one);
}
}
}
for (i in result){
var xystring = result[i][self.chart_info_fields];
if (self.group_field){
var newkey =result[i][self.group_field].replace(" ", "_");
newkey =result[i][self.group_field].split(' ').join('_');
}else{
var newkey =result[i][self.group_field];
newkey = "val";
}
if (xystr[xystring] == undefined){
xyname = {};
@ -165,12 +176,18 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
xyname[self.group_list[j]] = 0.0001;
}
xyname[newkey] = result[i][self.operator_field];
if (self.operator.length > 1){
xyname[newkey_one] = result[i][self.operator_field_one];
}
xystr[xystring] = xyname;
}
else{
xyname = {};
xyname = xystr[xystring];
xyname[newkey] = result[i][self.operator_field];
if (self.operator.length > 1){
xyname[newkey_one] = result[i][self.operator_field_one];
}
xystr[xystring] = xyname;
}
}
@ -183,8 +200,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
var grp_color = [];
for (i in self.group_list){
var legend = {};
if (self.group_list[i] == undefined){
if (self.group_list[i] == "val"){
legend['text'] = self.fields[self.operator_field]['string']
}else if(self.group_list[i] == "val1"){
legend['text'] = self.fields[self.operator_field_one]['string']
}else{
legend['text'] = self.group_list[i];
}
@ -214,7 +233,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
value:"#"+self.group_list[0]+"#",
gradient: "3d",
border: false,
width: 50,
width: 1024,
radius: 0,
color:grp_color[0]['color'],
origin:0,
xAxis: x_ax,
@ -235,12 +255,11 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
});
for (var i = 1; i<self.group_list.length;i++){
bar_chart.addSeries({
value: "#"+grp_color[i]['text']+"#",
value: "#"+self.group_list[i]+"#",
color: grp_color[i]['color']
});
}
bar_chart.parse(res,"json");
},
schedule_pie: function(result) {
@ -271,11 +290,14 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
}
});
chart.parse(result,"json");
/* chart.attachEvent("onItemClick", function(id) {
var event_list = new openerp.base.ListView(self.view_manager, self.session, self.element_id, self.dataset, false, false);
event_list.start();
});*/
},
do_search: function(domains, contexts, groupbys) {
var self = this;
this.rpc('/base/session/eval_domain_and_context', {
domains: domains,
contexts: contexts,
@ -290,11 +312,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
}
self.dataset.context = self.context = results.context;
self.dataset.domain = self.domain = results.domain;
self.dataset.read_slice({}, 0, self.limit,function(result){
self.load_chart(result);
self.dataset.read_slice({}, 0, self.limit,function(response){
self.load_chart(response);
});
});
},
});
@ -303,4 +324,4 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
};
// vim:et fdc=0 fdl=0:
// vim:et fdc=0 fdl=0: