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.

76 lines
2.5 KiB

  1. odoo.define('kpi_dashboard.DashboardController', function (require) {
  2. "use strict";
  3. var BasicController = require('web.BasicController');
  4. var core = require('web.core');
  5. var qweb = core.qweb;
  6. var _t = core._t;
  7. var DashboardController = BasicController.extend({
  8. custom_events: _.extend({}, BasicController.prototype.custom_events, {
  9. addDashboard: '_addDashboard',
  10. }),
  11. renderPager: function ($node, options) {
  12. options = _.extend({}, options, {
  13. validate: this.canBeDiscarded.bind(this),
  14. });
  15. this._super($node, options);
  16. },
  17. _pushState: function (state) {
  18. state = state || {};
  19. var env = this.model.get(this.handle, {env: true});
  20. state.id = env.currentId;
  21. this._super(state);
  22. },
  23. _addDashboard: function () {
  24. var self = this;
  25. var action = self.initialState.specialData.action_id;
  26. var name = self.initialState.specialData.name;
  27. if (! action) {
  28. self.do_warn(_t("First you must create the Menu"));
  29. }
  30. return self._rpc({
  31. route: '/board/add_to_dashboard',
  32. params: {
  33. action_id: action,
  34. context_to_save: {'res_id': self.initialState.res_id},
  35. domain: [('id', '=', self.initialState.res_id)],
  36. view_mode: 'dashboard',
  37. name: name,
  38. },
  39. })
  40. .then(function (r) {
  41. if (r) {
  42. self.do_notify(
  43. _.str.sprintf(_t("'%s' added to dashboard"), name),
  44. _t('Please refresh your browser for the changes to take effect.')
  45. );
  46. } else {
  47. self.do_warn(_t("Could not add KPI dashboard to dashboard"));
  48. }
  49. });
  50. },
  51. _updateButtons: function () {
  52. // HOOK Function
  53. this.$buttons.on(
  54. 'click', '.o_dashboard_button_add',
  55. this._addDashboard.bind(this));
  56. },
  57. renderButtons: function ($node) {
  58. if (! $node) {
  59. return;
  60. }
  61. this.$buttons = $('<div/>');
  62. this.$buttons.append(qweb.render(
  63. "kpi_dashboard.buttons", {widget: this}));
  64. this._updateButtons();
  65. this.$buttons.appendTo($node);
  66. },
  67. });
  68. return DashboardController;
  69. });