2011-04-15 06:42:41 +00:00
|
|
|
/*---------------------------------------------------------
|
2011-09-05 12:28:15 +00:00
|
|
|
* OpenERP web_graph
|
2011-04-15 06:42:41 +00:00
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_graph = function (openerp) {
|
2011-06-17 13:25:50 +00:00
|
|
|
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'];
|
|
|
|
|
2011-09-07 09:37:43 +00:00
|
|
|
var QWeb = openerp.web.qweb;
|
2011-09-05 12:28:15 +00:00
|
|
|
QWeb.add_template('/web_graph/static/src/xml/web_graph.xml');
|
|
|
|
openerp.web.views.add('graph', 'openerp.web_graph.GraphView');
|
|
|
|
openerp.web_graph.GraphView = openerp.web.View.extend({
|
2011-04-15 06:42:41 +00:00
|
|
|
|
2011-09-15 09:49:44 +00:00
|
|
|
init: function(parent, dataset, view_id) {
|
|
|
|
this._super(parent);
|
2011-04-15 06:42:41 +00:00
|
|
|
this.dataset = dataset;
|
|
|
|
this.view_id = view_id;
|
|
|
|
},
|
|
|
|
do_show: function () {
|
|
|
|
// TODO: re-trigger search
|
|
|
|
this.$element.show();
|
|
|
|
},
|
|
|
|
do_hide: function () {
|
|
|
|
this.$element.hide();
|
|
|
|
},
|
|
|
|
start: function() {
|
2011-09-26 14:02:41 +00:00
|
|
|
var self = this;
|
2011-09-15 09:42:46 +00:00
|
|
|
this._super();
|
2011-09-26 14:02:41 +00:00
|
|
|
return $.when(
|
2011-09-26 15:16:33 +00:00
|
|
|
this.dataset.call('fields_get', []),
|
2011-09-26 14:02:41 +00:00
|
|
|
this.rpc('/web/view/load', {
|
2011-09-26 15:16:33 +00:00
|
|
|
model: this.dataset.model,
|
2011-09-26 14:02:41 +00:00
|
|
|
view_id: this.view_id,
|
|
|
|
view_type: 'graph'
|
|
|
|
})).then(function (fields_result, view_result) {
|
2011-09-26 16:01:11 +00:00
|
|
|
self.fields = fields_result[0];
|
|
|
|
self.fields_view = view_result[0];
|
|
|
|
self.on_loaded();
|
2011-09-26 14:02:41 +00:00
|
|
|
});
|
2011-04-15 06:42:41 +00:00
|
|
|
},
|
2011-09-26 16:01:11 +00:00
|
|
|
on_loaded: function() {
|
2011-04-15 06:42:41 +00:00
|
|
|
this.chart = this.fields_view.arch.attrs.type || 'pie';
|
2011-09-26 16:01:11 +00:00
|
|
|
this.orientation = this.fields_view.arch.attrs.orientation || 'vertical';
|
|
|
|
|
2011-04-15 06:42:41 +00:00
|
|
|
this.chart_info_fields = [];
|
|
|
|
this.operator_field = '';
|
2011-05-25 06:09:00 +00:00
|
|
|
this.operator_field_one = '';
|
|
|
|
this.operator = [];
|
2011-07-01 06:39:56 +00:00
|
|
|
this.group_field = [];
|
2011-06-17 11:52:26 +00:00
|
|
|
_.each(this.fields_view.arch.children, function (field) {
|
|
|
|
if (field.attrs.operator) {
|
|
|
|
this.operator.push(field.attrs.name);
|
2011-04-15 06:42:41 +00:00
|
|
|
}
|
2011-06-17 11:52:26 +00:00
|
|
|
else if (field.attrs.group) {
|
2011-07-01 06:39:56 +00:00
|
|
|
this.group_field.push(field.attrs.name);
|
2011-04-15 06:42:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-06-17 11:52:26 +00:00
|
|
|
this.chart_info_fields.push(field.attrs.name);
|
2011-04-15 06:42:41 +00:00
|
|
|
}
|
2011-06-17 11:52:26 +00:00
|
|
|
}, this);
|
|
|
|
|
2011-05-25 06:09:00 +00:00
|
|
|
this.operator_field = this.operator[0];
|
|
|
|
if(this.operator.length > 1){
|
|
|
|
this.operator_field_one = this.operator[1];
|
|
|
|
}
|
|
|
|
if(this.operator == ''){
|
2011-05-06 12:41:08 +00:00
|
|
|
this.operator_field = this.chart_info_fields[1];
|
|
|
|
}
|
2011-09-26 15:16:33 +00:00
|
|
|
this.x_title = this.fields[this.chart_info_fields[0]].string;
|
2011-05-19 13:04:13 +00:00
|
|
|
this.y_title = this.fields[this.operator_field]['string'];
|
2011-04-21 09:05:52 +00:00
|
|
|
|
2011-09-26 15:16:33 +00:00
|
|
|
this.dataset.read_slice([], {}, $.proxy(this, 'schedule_chart'));
|
2011-04-15 06:42:41 +00:00
|
|
|
},
|
2011-06-17 11:52:26 +00:00
|
|
|
schedule_chart: function(results) {
|
2011-09-26 15:16:33 +00:00
|
|
|
this.$element.html(QWeb.render("GraphView", {
|
|
|
|
"fields_view": this.fields_view,
|
|
|
|
"chart": this.chart,
|
|
|
|
'element_id': this.element_id
|
|
|
|
}));
|
2011-07-07 11:28:22 +00:00
|
|
|
|
2011-06-17 13:31:56 +00:00
|
|
|
_.each(results, function (result) {
|
|
|
|
_.each(result, function (field_value, field_name) {
|
|
|
|
if (typeof field_value == 'object') {
|
|
|
|
result[field_name] = field_value[field_value.length - 1];
|
|
|
|
}
|
|
|
|
if (typeof field_value == 'string') {
|
2011-09-26 16:01:11 +00:00
|
|
|
var choices = this.fields[field_name]['selection'];
|
2011-06-17 13:31:56 +00:00
|
|
|
_.each(choices, function (choice) {
|
|
|
|
if (field_value == choice[0]) {
|
|
|
|
result[field_name] = choice;
|
|
|
|
}
|
|
|
|
});
|
2011-05-17 06:37:18 +00:00
|
|
|
}
|
2011-06-17 11:52:26 +00:00
|
|
|
}, this);
|
2011-06-17 13:31:56 +00:00
|
|
|
}, this);
|
2011-06-17 11:52:26 +00:00
|
|
|
|
2011-06-20 06:38:48 +00:00
|
|
|
var graph_data = {};
|
2011-06-17 13:31:56 +00:00
|
|
|
_.each(results, function (result) {
|
2011-07-01 06:39:56 +00:00
|
|
|
var group_key = [];
|
|
|
|
if(this.group_field.length){
|
|
|
|
_.each(this.group_field, function (res) {
|
|
|
|
result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res];
|
|
|
|
group_key.push(result[res]);
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
group_key.push(result[this.group_field]);
|
|
|
|
}
|
|
|
|
var column_key = result[this.chart_info_fields] + "_" + group_key;
|
2011-06-20 06:38:48 +00:00
|
|
|
var column_descriptor = {};
|
|
|
|
if (graph_data[column_key] == undefined) {
|
|
|
|
column_descriptor[this.operator_field] = result[this.operator_field];
|
2011-06-17 13:31:56 +00:00
|
|
|
if (this.operator.length > 1) {
|
2011-06-20 06:38:48 +00:00
|
|
|
column_descriptor[this.operator_field_one] = result[this.operator_field_one];
|
2011-06-17 13:31:56 +00:00
|
|
|
}
|
2011-06-20 06:38:48 +00:00
|
|
|
column_descriptor[this.chart_info_fields] = result[this.chart_info_fields];
|
2011-07-01 06:39:56 +00:00
|
|
|
if(this.group_field.length){
|
|
|
|
_.each(this.group_field, function (res) {
|
|
|
|
column_descriptor[res] = (typeof result[res] == 'object') ? result[res][1] : result[res];
|
|
|
|
});
|
2011-06-17 13:31:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-06-20 06:38:48 +00:00
|
|
|
column_descriptor = graph_data[column_key];
|
|
|
|
column_descriptor[this.operator_field] += result[this.operator_field];
|
2011-06-17 13:31:56 +00:00
|
|
|
if (this.operator.length > 1) {
|
2011-06-20 06:38:48 +00:00
|
|
|
column_descriptor[this.operator_field_one] += result[this.operator_field_one];
|
2011-06-17 13:31:56 +00:00
|
|
|
}
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-06-20 06:38:48 +00:00
|
|
|
graph_data[column_key] = column_descriptor;
|
2011-06-17 13:31:56 +00:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
if (this.chart == 'bar') {
|
2011-06-20 06:38:48 +00:00
|
|
|
return this.schedule_bar(_.values(graph_data));
|
2011-06-17 13:31:56 +00:00
|
|
|
} else if (this.chart == "pie") {
|
2011-06-20 06:38:48 +00:00
|
|
|
return this.schedule_pie(_.values(graph_data));
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-06-17 11:52:26 +00:00
|
|
|
schedule_bar: function(results) {
|
2011-05-06 12:41:08 +00:00
|
|
|
var self = this;
|
|
|
|
var view_chart = '';
|
2011-06-17 13:22:22 +00:00
|
|
|
var group_list = [];
|
2011-07-01 06:39:56 +00:00
|
|
|
var legend_list = [];
|
2011-06-17 11:52:26 +00:00
|
|
|
var newkey = '', newkey_one;
|
2011-07-01 06:39:56 +00:00
|
|
|
var string_legend = '';
|
2011-04-21 09:05:52 +00:00
|
|
|
|
2011-07-01 06:39:56 +00:00
|
|
|
if((self.group_field.length) && (this.operator.length <= 1)){
|
2011-05-17 06:37:18 +00:00
|
|
|
view_chart = self.orientation == 'horizontal'? 'stackedBarH' : 'stackedBar';
|
2011-05-06 12:41:08 +00:00
|
|
|
}else{
|
2011-05-17 06:37:18 +00:00
|
|
|
view_chart = self.orientation == 'horizontal'? 'barH' : 'bar';
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-04-21 09:05:52 +00:00
|
|
|
|
2011-06-17 11:52:26 +00:00
|
|
|
_.each(results, function (result) {
|
2011-07-01 06:39:56 +00:00
|
|
|
if ((self.group_field.length) && (this.operator.length <= 1)) {
|
|
|
|
var legend_key = '';
|
|
|
|
_.each(self.group_field, function (res) {
|
|
|
|
result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res];
|
2011-07-11 14:59:07 +00:00
|
|
|
legend_key += result[res];
|
2011-07-01 06:39:56 +00:00
|
|
|
});
|
|
|
|
newkey = legend_key.replace(/\s+/g,'_').replace(/[^a-zA-Z 0-9]+/g,'_');
|
|
|
|
string_legend = legend_key;
|
2011-06-17 11:52:26 +00:00
|
|
|
} else {
|
2011-07-01 06:39:56 +00:00
|
|
|
newkey = string_legend = "val";
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-06-13 05:28:46 +00:00
|
|
|
|
2011-07-01 06:39:56 +00:00
|
|
|
if (_.contains(group_list, newkey) && _.contains(legend_list, string_legend)) {
|
2011-06-17 13:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
group_list.push(newkey);
|
2011-07-01 06:39:56 +00:00
|
|
|
legend_list.push(string_legend);
|
|
|
|
|
2011-06-17 13:31:56 +00:00
|
|
|
if (this.operator.length > 1) {
|
|
|
|
newkey_one = "val1";
|
|
|
|
group_list.push(newkey_one);
|
2011-07-01 06:39:56 +00:00
|
|
|
legend_list.push(newkey_one);
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-06-17 11:52:26 +00:00
|
|
|
}, this);
|
2011-04-21 09:05:52 +00:00
|
|
|
|
2011-06-20 12:15:25 +00:00
|
|
|
if (group_list.length <=1){
|
|
|
|
group_list = [];
|
2011-07-01 06:39:56 +00:00
|
|
|
legend_list = [];
|
|
|
|
newkey = string_legend = "val";
|
|
|
|
group_list.push(newkey);
|
|
|
|
legend_list.push(string_legend);
|
2011-06-20 12:15:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-20 06:38:48 +00:00
|
|
|
var abscissa_data = {};
|
2011-06-17 11:52:26 +00:00
|
|
|
_.each(results, function (result) {
|
2011-06-20 06:38:48 +00:00
|
|
|
var label = result[self.chart_info_fields],
|
|
|
|
section = {};
|
2011-07-01 06:39:56 +00:00
|
|
|
if ((self.group_field.length) && (group_list.length > 1) && (self.operator.length <= 1)){
|
|
|
|
var legend_key_two = '';
|
|
|
|
_.each(self.group_field, function (res) {
|
|
|
|
result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res];
|
2011-07-11 14:59:07 +00:00
|
|
|
legend_key_two += result[res];
|
2011-07-01 06:39:56 +00:00
|
|
|
});
|
|
|
|
newkey = legend_key_two.replace(/\s+/g,'_').replace(/[^a-zA-Z 0-9]+/g,'_');
|
2011-05-06 12:41:08 +00:00
|
|
|
}else{
|
2011-05-25 06:09:00 +00:00
|
|
|
newkey = "val";
|
2011-04-15 06:42:41 +00:00
|
|
|
}
|
2011-06-20 06:38:48 +00:00
|
|
|
if (abscissa_data[label] == undefined){
|
|
|
|
section[self.chart_info_fields] = label;
|
2011-06-17 13:22:22 +00:00
|
|
|
_.each(group_list, function (group) {
|
2011-06-21 05:26:43 +00:00
|
|
|
section[group] = 0;
|
2011-06-17 11:52:26 +00:00
|
|
|
});
|
2011-06-17 13:22:22 +00:00
|
|
|
} else {
|
2011-06-20 06:38:48 +00:00
|
|
|
section = abscissa_data[label];
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-06-20 06:38:48 +00:00
|
|
|
section[newkey] = result[self.operator_field];
|
2011-06-17 13:22:22 +00:00
|
|
|
if (self.operator.length > 1){
|
2011-06-20 06:38:48 +00:00
|
|
|
section[newkey_one] = result[self.operator_field_one];
|
2011-06-17 13:22:22 +00:00
|
|
|
}
|
2011-06-20 06:38:48 +00:00
|
|
|
abscissa_data[label] = section;
|
2011-06-17 11:52:26 +00:00
|
|
|
});
|
2011-05-06 12:41:08 +00:00
|
|
|
|
|
|
|
//for legend color
|
2011-07-01 06:39:56 +00:00
|
|
|
var grp_color = _.map(legend_list, function (group_legend, index) {
|
2011-06-17 11:55:59 +00:00
|
|
|
var legend = {color: COLOR_PALETTE[index]};
|
2011-06-17 11:52:26 +00:00
|
|
|
if (group_legend == "val"){
|
2011-05-06 12:41:08 +00:00
|
|
|
legend['text'] = self.fields[self.operator_field]['string']
|
2011-06-17 11:52:26 +00:00
|
|
|
}else if(group_legend == "val1"){
|
2011-05-25 06:09:00 +00:00
|
|
|
legend['text'] = self.fields[self.operator_field_one]['string']
|
2011-05-06 12:41:08 +00:00
|
|
|
}else{
|
2011-06-17 11:52:26 +00:00
|
|
|
legend['text'] = group_legend;
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-06-17 13:22:22 +00:00
|
|
|
return legend;
|
2011-06-17 11:52:26 +00:00
|
|
|
});
|
2011-04-21 09:05:52 +00:00
|
|
|
|
2011-06-06 05:57:54 +00:00
|
|
|
//for axis's value and title
|
2011-07-01 06:39:56 +00:00
|
|
|
var max,min,step;
|
|
|
|
var maximum,minimum;
|
|
|
|
if(_.isEmpty(abscissa_data)){
|
|
|
|
max = 9;
|
|
|
|
min = 0;
|
|
|
|
step=1;
|
|
|
|
}else{
|
|
|
|
var max_min = [];
|
2011-06-20 12:15:25 +00:00
|
|
|
_.each(abscissa_data, function (abscissa_datas) {
|
2011-07-01 06:39:56 +00:00
|
|
|
_.each(group_list, function(res){
|
|
|
|
max_min.push(abscissa_datas[res]);
|
|
|
|
});
|
2011-06-20 12:15:25 +00:00
|
|
|
});
|
2011-07-01 06:39:56 +00:00
|
|
|
maximum = Math.max.apply(Math,max_min);
|
2011-06-20 12:15:25 +00:00
|
|
|
minimum = Math.min.apply(Math,max_min);
|
2011-07-01 06:39:56 +00:00
|
|
|
if (maximum == minimum){
|
|
|
|
if (maximum == 0){
|
|
|
|
max = 9;
|
|
|
|
min = 0;
|
|
|
|
step=1;
|
|
|
|
}else if(maximum > 0){
|
2011-07-11 14:59:07 +00:00
|
|
|
max = maximum + (10 - maximum % 10);
|
2011-07-01 06:39:56 +00:00
|
|
|
min = 0;
|
|
|
|
step = Math.round(max/10);
|
2011-06-20 12:15:25 +00:00
|
|
|
}else{
|
2011-07-01 06:39:56 +00:00
|
|
|
max = 0;
|
2011-07-11 14:59:07 +00:00
|
|
|
min = minimum - (10 + minimum % 10);
|
2011-07-01 06:39:56 +00:00
|
|
|
step = Math.round(Math.abs(min)/10);
|
2011-06-20 12:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-20 06:38:48 +00:00
|
|
|
var abscissa_description = {
|
2011-06-17 11:55:59 +00:00
|
|
|
template: self.chart_info_fields,
|
|
|
|
title: "<b>"+self.x_title+"</b>"
|
|
|
|
};
|
2011-06-20 12:15:25 +00:00
|
|
|
|
2011-06-20 06:38:48 +00:00
|
|
|
var ordinate_description = {
|
2011-06-17 11:55:59 +00:00
|
|
|
lines: true,
|
2011-06-20 12:15:25 +00:00
|
|
|
title: "<b>"+self.y_title+"</b>",
|
|
|
|
start: min,
|
|
|
|
step: step,
|
|
|
|
end: max
|
2011-06-17 11:55:59 +00:00
|
|
|
};
|
2011-04-21 09:05:52 +00:00
|
|
|
|
2011-07-01 06:39:56 +00:00
|
|
|
var x_axis, y_axis, tooltip;
|
2011-05-17 06:37:18 +00:00
|
|
|
if (self.orientation == 'horizontal'){
|
2011-06-20 06:38:48 +00:00
|
|
|
x_axis = ordinate_description;
|
|
|
|
y_axis = abscissa_description;
|
2011-05-06 12:41:08 +00:00
|
|
|
}else{
|
2011-06-20 06:38:48 +00:00
|
|
|
x_axis = abscissa_description;
|
|
|
|
y_axis = ordinate_description;
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-07-01 06:39:56 +00:00
|
|
|
tooltip = self.chart_info_fields;
|
2011-07-07 11:28:22 +00:00
|
|
|
|
2011-06-20 10:05:57 +00:00
|
|
|
var bar_chart = new dhtmlXChart({
|
2011-05-06 12:41:08 +00:00
|
|
|
view: view_chart,
|
2011-09-23 09:37:53 +00:00
|
|
|
container: self.element_id+"-barchart",
|
2011-06-17 13:22:22 +00:00
|
|
|
value:"#"+group_list[0]+"#",
|
2011-05-06 12:41:08 +00:00
|
|
|
gradient: "3d",
|
|
|
|
border: false,
|
2011-05-25 06:09:00 +00:00
|
|
|
width: 1024,
|
2011-06-21 10:50:31 +00:00
|
|
|
tooltip:{
|
2011-07-01 06:39:56 +00:00
|
|
|
template:"#"+tooltip+"#"+","+grp_color[0]['text']+"="+"#"+group_list[0]+"#"
|
2011-06-21 10:50:31 +00:00
|
|
|
},
|
2011-05-25 06:09:00 +00:00
|
|
|
radius: 0,
|
2011-05-06 12:41:08 +00:00
|
|
|
color:grp_color[0]['color'],
|
|
|
|
origin:0,
|
2011-06-06 05:57:54 +00:00
|
|
|
xAxis:{
|
|
|
|
template:function(obj){
|
2011-06-20 06:38:48 +00:00
|
|
|
if(x_axis['template']){
|
|
|
|
var val = obj[x_axis['template']];
|
2011-06-17 09:24:36 +00:00
|
|
|
val = (typeof val == 'object')?val[1]:(!val?'Undefined':val);
|
2011-07-01 06:39:56 +00:00
|
|
|
if(val.length > 12){
|
|
|
|
val = val.substring(0,12);
|
|
|
|
}
|
2011-06-06 05:57:54 +00:00
|
|
|
return val;
|
|
|
|
}else{
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
},
|
2011-06-20 06:38:48 +00:00
|
|
|
title:x_axis['title'],
|
|
|
|
lines:x_axis['lines']
|
2011-06-06 05:57:54 +00:00
|
|
|
},
|
|
|
|
yAxis:{
|
|
|
|
template:function(obj){
|
2011-06-20 06:38:48 +00:00
|
|
|
if(y_axis['template']){
|
|
|
|
var vals = obj[y_axis['template']];
|
2011-06-17 09:24:36 +00:00
|
|
|
vals = (typeof vals == 'object')?vals[1]:(!vals?'Undefined':vals);
|
2011-07-01 06:39:56 +00:00
|
|
|
if(vals.length > 12){
|
|
|
|
vals = vals.substring(0,12);
|
|
|
|
}
|
2011-06-06 05:57:54 +00:00
|
|
|
return vals;
|
|
|
|
}else{
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
},
|
2011-06-20 06:38:48 +00:00
|
|
|
title:y_axis['title'],
|
2011-06-20 12:15:25 +00:00
|
|
|
lines: y_axis['lines'],
|
|
|
|
start:y_axis['start'],
|
|
|
|
step:y_axis['step'],
|
|
|
|
end:y_axis['end']
|
2011-06-06 05:57:54 +00:00
|
|
|
},
|
2011-05-19 13:04:13 +00:00
|
|
|
padding: {
|
|
|
|
left: 75
|
|
|
|
},
|
2011-05-06 12:41:08 +00:00
|
|
|
legend: {
|
|
|
|
values: grp_color,
|
2011-05-19 13:04:13 +00:00
|
|
|
align:"left",
|
2011-05-06 12:41:08 +00:00
|
|
|
valign:"top",
|
2011-05-19 13:04:13 +00:00
|
|
|
layout: "x",
|
2011-05-06 12:41:08 +00:00
|
|
|
marker:{
|
|
|
|
type:"round",
|
|
|
|
width:12
|
2011-06-17 09:13:44 +00:00
|
|
|
}
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
|
|
|
});
|
2011-06-17 13:22:22 +00:00
|
|
|
for (var m = 1; m<group_list.length;m++){
|
2011-05-06 12:41:08 +00:00
|
|
|
bar_chart.addSeries({
|
2011-06-17 13:22:22 +00:00
|
|
|
value: "#"+group_list[m]+"#",
|
2011-06-21 10:50:31 +00:00
|
|
|
tooltip:{
|
2011-07-01 06:39:56 +00:00
|
|
|
template:"#"+tooltip+"#"+","+grp_color[m]['text']+"="+"#"+group_list[m]+"#"
|
2011-06-21 10:50:31 +00:00
|
|
|
},
|
2011-06-17 09:32:22 +00:00
|
|
|
color: grp_color[m]['color']
|
2011-05-06 12:41:08 +00:00
|
|
|
});
|
2011-04-15 06:42:41 +00:00
|
|
|
}
|
2011-06-20 06:38:48 +00:00
|
|
|
bar_chart.parse(_.values(abscissa_data), "json");
|
2011-09-23 09:37:53 +00:00
|
|
|
jQuery("#"+self.element_id+"-barchart").height(jQuery("#"+self.element_id+"-barchart").height()+50);
|
2011-06-06 05:57:54 +00:00
|
|
|
bar_chart.attachEvent("onItemClick", function(id) {
|
2011-06-17 09:32:22 +00:00
|
|
|
self.open_list_view(bar_chart.get(id));
|
2011-06-06 05:57:54 +00:00
|
|
|
});
|
2011-04-15 06:42:41 +00:00
|
|
|
},
|
2011-05-06 12:41:08 +00:00
|
|
|
schedule_pie: function(result) {
|
2011-05-17 06:37:18 +00:00
|
|
|
var self = this;
|
2011-06-20 10:05:57 +00:00
|
|
|
var chart = new dhtmlXChart({
|
2011-05-17 06:37:18 +00:00
|
|
|
view:"pie3D",
|
2011-09-23 09:37:53 +00:00
|
|
|
container:self.element_id+"-piechart",
|
2011-05-17 06:37:18 +00:00
|
|
|
value:"#"+self.operator_field+"#",
|
|
|
|
pieInnerText:function(obj) {
|
|
|
|
var sum = chart.sum("#"+self.operator_field+"#");
|
|
|
|
var val = obj[self.operator_field] / sum * 100 ;
|
2011-06-20 07:55:02 +00:00
|
|
|
return val.toFixed(1) + "%";
|
2011-05-17 06:37:18 +00:00
|
|
|
},
|
2011-07-01 06:39:56 +00:00
|
|
|
tooltip:{
|
|
|
|
template:"#"+self.chart_info_fields+"#"+"="+"#"+self.operator_field+"#"
|
|
|
|
},
|
2011-05-06 12:41:08 +00:00
|
|
|
gradient:"3d",
|
2011-05-18 05:55:11 +00:00
|
|
|
height: 20,
|
2011-05-19 13:04:13 +00:00
|
|
|
radius: 200,
|
2011-04-15 06:42:41 +00:00
|
|
|
legend: {
|
2011-05-17 06:37:18 +00:00
|
|
|
width: 300,
|
2011-05-19 13:04:13 +00:00
|
|
|
align:"left",
|
2011-05-06 12:41:08 +00:00
|
|
|
valign:"top",
|
2011-05-19 13:04:13 +00:00
|
|
|
layout: "x",
|
2011-05-06 12:41:08 +00:00
|
|
|
marker:{
|
|
|
|
type:"round",
|
|
|
|
width:12
|
|
|
|
},
|
2011-06-06 05:57:54 +00:00
|
|
|
template:function(obj){
|
|
|
|
var val = obj[self.chart_info_fields];
|
|
|
|
val = (typeof val == 'object')?val[1]:val;
|
|
|
|
return val;
|
|
|
|
}
|
2011-04-15 06:42:41 +00:00
|
|
|
}
|
2011-05-06 12:41:08 +00:00
|
|
|
});
|
|
|
|
chart.parse(result,"json");
|
2011-06-06 05:57:54 +00:00
|
|
|
chart.attachEvent("onItemClick", function(id) {
|
2011-06-17 09:32:22 +00:00
|
|
|
self.open_list_view(chart.get(id));
|
2011-06-06 05:57:54 +00:00
|
|
|
});
|
|
|
|
},
|
2011-06-13 05:28:46 +00:00
|
|
|
open_list_view : function (id){
|
2011-07-11 14:58:16 +00:00
|
|
|
var self = this;
|
|
|
|
if($(".dhx_tooltip").is(":visible")) {
|
2011-07-07 11:28:22 +00:00
|
|
|
$(".dhx_tooltip").remove('div');
|
|
|
|
}
|
2011-07-11 14:58:16 +00:00
|
|
|
id = id[this.chart_info_fields];
|
2011-06-06 05:57:54 +00:00
|
|
|
if (typeof id == 'object'){
|
|
|
|
id = id[0];
|
|
|
|
}
|
2011-07-07 11:28:22 +00:00
|
|
|
|
2011-09-26 15:16:33 +00:00
|
|
|
var record_id;
|
2011-07-11 14:58:16 +00:00
|
|
|
if (typeof this.chart_info_fields == 'object'){
|
|
|
|
record_id = this.chart_info_fields[0];
|
2011-07-07 11:28:22 +00:00
|
|
|
}else{
|
2011-07-11 14:58:16 +00:00
|
|
|
record_id = this.chart_info_fields;
|
2011-06-06 05:57:54 +00:00
|
|
|
}
|
2011-07-07 11:28:22 +00:00
|
|
|
var modes = !!modes ? modes.split(",") : ["list", "form", "graph"];
|
|
|
|
var views = [];
|
|
|
|
_.each(modes, function(mode) {
|
|
|
|
var view = [false, mode];
|
|
|
|
if (self.fields.views && self.fields.views[mode]) {
|
|
|
|
view.push(self.fields.views[mode]);
|
|
|
|
}
|
|
|
|
views.push(view);
|
|
|
|
});
|
2011-08-10 10:38:36 +00:00
|
|
|
this.do_action({
|
2011-07-11 14:58:16 +00:00
|
|
|
"res_model" : this.dataset.model,
|
2011-09-26 15:16:33 +00:00
|
|
|
"domain" : [[record_id, '=', id], ['id','in',this.dataset.ids]],
|
2011-07-07 11:28:22 +00:00
|
|
|
"views" : views,
|
|
|
|
"type" : "ir.actions.act_window",
|
|
|
|
"auto_search" : true,
|
|
|
|
"view_type" : "list",
|
|
|
|
"view_mode" : "list"
|
2011-07-11 14:58:16 +00:00
|
|
|
});
|
2011-04-15 06:42:41 +00:00
|
|
|
},
|
2011-07-07 11:28:22 +00:00
|
|
|
|
2011-04-18 05:52:28 +00:00
|
|
|
do_search: function(domains, contexts, groupbys) {
|
|
|
|
var self = this;
|
2011-09-05 12:28:15 +00:00
|
|
|
this.rpc('/web/session/eval_domain_and_context', {
|
2011-04-18 05:52:28 +00:00
|
|
|
domains: domains,
|
|
|
|
contexts: contexts,
|
|
|
|
group_by_seq: groupbys
|
|
|
|
}, function (results) {
|
|
|
|
// TODO: handle non-empty results.group_by with read_group
|
2011-09-26 15:16:33 +00:00
|
|
|
if(!_(results.group_by).isEmpty()){
|
|
|
|
self.x_title = results.group_by[0];
|
|
|
|
} else {
|
|
|
|
self.x_title = self.chart_info_fields[0].string;
|
2011-05-06 12:41:08 +00:00
|
|
|
}
|
2011-09-26 15:16:33 +00:00
|
|
|
self.dataset.read_slice([],{
|
|
|
|
context: results.context,
|
|
|
|
domain: results.domain
|
|
|
|
}, $.proxy(self, 'schedule_chart'));
|
2011-04-18 05:52:28 +00:00
|
|
|
});
|
2011-06-17 09:13:44 +00:00
|
|
|
}
|
2011-04-15 06:42:41 +00:00
|
|
|
});
|
|
|
|
};
|
2011-07-11 14:58:16 +00:00
|
|
|
// vim:et fdc=0 fdl=0:
|