diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/web/static/src/js/widgets/pie_chart.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/web/static/src/js/widgets/pie_chart.js')
| -rw-r--r-- | addons/web/static/src/js/widgets/pie_chart.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/addons/web/static/src/js/widgets/pie_chart.js b/addons/web/static/src/js/widgets/pie_chart.js new file mode 100644 index 00000000..f4254ff3 --- /dev/null +++ b/addons/web/static/src/js/widgets/pie_chart.js @@ -0,0 +1,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; + +}); |
