OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.9 KiB

  1. odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
  2. "use strict";
  3. var BasicRenderer = require('web.BasicRenderer');
  4. var core = require('web.core');
  5. var registry = require('kpi_dashboard.widget_registry');
  6. var BusService = require('bus.BusService');
  7. var qweb = core.qweb;
  8. var DashboardRenderer= BasicRenderer.extend({
  9. className: "o_dashboard_view",
  10. _getDashboardWidget: function (kpi) {
  11. var Widget = registry.getAny([
  12. kpi.widget, 'abstract',
  13. ]);
  14. var widget = new Widget(this, kpi);
  15. return widget;
  16. },
  17. _renderView: function () {
  18. this.$el.html($(qweb.render('dashboard_kpi.dashboard')));
  19. this.$el.css(
  20. 'background-color', this.state.specialData.background_color);
  21. this.$el.find('.gridster')
  22. .css('width', this.state.specialData.width);
  23. this.$grid = this.$el.find('.gridster ul');
  24. var self = this;
  25. this.kpi_widget = {};
  26. _.each(this.state.specialData.item_ids, function (kpi) {
  27. var element = $(qweb.render(
  28. 'kpi_dashboard.kpi', {widget: kpi}));
  29. element.css('background-color', kpi.color);
  30. element.css('color', kpi.font_color);
  31. self.$grid.append(element);
  32. self.kpi_widget[kpi.id] = self._getDashboardWidget(kpi);
  33. self.kpi_widget[kpi.id].appendTo(element);
  34. });
  35. this.$grid.gridster({
  36. widget_margins: [
  37. this.state.specialData.margin_x,
  38. this.state.specialData.margin_y,
  39. ],
  40. widget_base_dimensions: [
  41. this.state.specialData.widget_dimension_x,
  42. this.state.specialData.widget_dimension_y,
  43. ],
  44. cols: this.state.specialData.max_cols,
  45. }).data('gridster').disable();
  46. this.channel = 'kpi_dashboard_' + this.state.res_id;
  47. this.call(
  48. 'bus_service', 'addChannel', this.channel);
  49. this.call('bus_service', 'startPolling');
  50. this.call(
  51. 'bus_service', 'onNotification',
  52. this, this._onNotification
  53. );
  54. return $.when();
  55. },
  56. _onNotification: function (notifications) {
  57. var self = this;
  58. _.each(notifications, function (notification) {
  59. var channel = notification[0];
  60. var message = notification[1];
  61. if (channel === self.channel && message) {
  62. var widget = self.kpi_widget[message.id];
  63. if (widget !== undefined) {
  64. widget._fillWidget(message);
  65. }
  66. }
  67. });
  68. },
  69. });
  70. return DashboardRenderer;
  71. });