1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
odoo.define('web.PieChart', function (require) {
"use strict";
/**
* This widget render a Pie Chart. It is used in the dashboard view.
*/
var core = require('web.core');
var Domain = require('web.Domain');
var viewRegistry = require('web.view_registry');
var Widget = require('web.Widget');
var widgetRegistry = require('web.widget_registry');
var qweb = core.qweb;
var PieChart = Widget.extend({
className: 'o_pie_chart',
xmlDependencies: ['/web/static/src/xml/chart.xml'],
/**
* @override
* @param {Widget} parent
* @param {Object} record
* @param {Object} node node from arch
*/
init: function (parent, record, node) {
this._super.apply(this, arguments);
var modifiers = node.attrs.modifiers;
var domain = record.domain.concat(
Domain.prototype.stringToArray(modifiers.domain || '[]'));
var arch = qweb.render('web.PieChart', {
modifiers: modifiers,
title: node.attrs.title || modifiers.title || modifiers.measure,
});
var pieChartContext = JSON.parse(JSON.stringify(record.context));
delete pieChartContext.graph_mode;
delete pieChartContext.graph_measure;
delete pieChartContext.graph_groupbys;
this.subViewParams = {
modelName: record.model,
withButtons: false,
withControlPanel: false,
withSearchPanel: false,
isEmbedded: true,
useSampleModel: record.isSample,
mode: 'pie',
};
this.subViewParams.searchQuery = {
context: pieChartContext,
domain: domain,
groupBy: [],
timeRanges: {},
};
this.viewInfo = {
arch: arch,
fields: record.fields,
viewFields: record.fieldsInfo.dashboard,
};
},
/**
* Instantiates the pie chart view and starts the graph controller.
*
* @override
*/
willStart: function () {
var self = this;
var def1 = this._super.apply(this, arguments);
var SubView = viewRegistry.get('graph');
var subView = new SubView(this.viewInfo, this.subViewParams);
var def2 = subView.getController(this).then(function (controller) {
self.controller = controller;
return self.controller.appendTo(document.createDocumentFragment());
});
return Promise.all([def1, def2]);
},
/**
* @override
*/
start: function () {
this.$el.append(this.controller.$el);
return this._super.apply(this, arguments);
},
/**
* Call `on_attach_callback` for each subview
*
* @override
*/
on_attach_callback: function () {
this.controller.on_attach_callback();
},
});
widgetRegistry.add('pie_chart', PieChart);
return PieChart;
});
|