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.

146 lines
3.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. odoo.define('galicea_environment_checkup', function (require) {
  2. "use strict";
  3. //var SystrayMenu = require('web.SystrayMenu');
  4. //var Model = require('web.Model');
  5. var AbstractAction = require('web.AbstractAction');
  6. var core = require('web.core');
  7. //var framework = require('web.framework');
  8. var session = require('web.session');
  9. //var Widget = require('web.Widget');
  10. //////////////////
  11. var QWeb = core.qweb;
  12. //var _t = core._t;
  13. /* SystrayIcon - nie działa poprawnie ???
  14. //https://www.odoo.com/documentation/12.0/reference/javascript_reference.html
  15. var Model = require('web.Model');
  16. var Users = new Model('res.users');
  17. var SystrayIcon = Widget.extend({
  18. tagName: 'li',
  19. events: {
  20. "click": "on_click",
  21. },
  22. start: function(){
  23. this.load(this.all_dashboards);
  24. return this._super();
  25. },
  26. load: function(dashboards){
  27. var self = this;
  28. var loading_done = new $.Deferred();
  29. Users.call('has_group', ['base.group_erp_manager']).then(function(is_admin) {
  30. if (is_admin) {
  31. session.rpc('/galicea_environment_checkup/data', {})
  32. .then(function (data) {
  33. var counts = { 'success': 0, 'warning': 0, 'fail': 0 };
  34. data.forEach(function (check) { ++counts[check.result]; });
  35. var result;
  36. if (counts['fail']) {
  37. result = 'fail';
  38. } else if (counts['warning']) {
  39. result = 'warning';
  40. } else {
  41. result = 'success';
  42. }
  43. self.replaceElement(QWeb.render('GaliceaEnvironmentCheckupIcon', {
  44. 'result': result,
  45. 'count': counts['warning'] + counts['fail']
  46. }));
  47. loading_done.resolve();
  48. });
  49. } else {
  50. loading_done.resolve();
  51. }
  52. });
  53. return loading_done;
  54. },
  55. on_click: function (event) {
  56. event.preventDefault();
  57. this.do_action('galicea_environment_checkup.dashboard_action', {clear_breadcrumbs: true});
  58. },
  59. });
  60. */
  61. /////////////////////////////
  62. var Dashboard = AbstractAction.extend({
  63. // v.10 var Dashboard = Widget.extend({
  64. start: function(){
  65. return this.load(this.all_dashboards);
  66. },
  67. load: function(dashboards) {
  68. var self = this;
  69. var loading_done = new $.Deferred();
  70. session.rpc('/galicea_environment_checkup/data', {})
  71. .then(function (data) {
  72. self._replaceElement(QWeb.render('GaliceaEnvironmentCheckupDashboard', {'data': data})); // v.10: self.replaceElement
  73. loading_done.resolve();
  74. });
  75. return loading_done;
  76. },
  77. });
  78. //!JW - nowa propozycja: core.action_registry.add('galicea_environment_checkup.environment_checkup', Dashboard);
  79. core.action_registry.add('galicea_environment_checkup.dashboard', Dashboard);
  80. ////////////////////
  81. /* v.10
  82. var FormWidget = form_common.AbstractField.extend({
  83. init: function() {
  84. this._super.apply(this, arguments);
  85. this.set("value", "[]");
  86. },
  87. render_value: function() {
  88. var data = JSON.parse(this.get('value'));
  89. if (data.length == 0) {
  90. this.replaceElement('<div />');
  91. return;
  92. }
  93. this.replaceElement(QWeb.render('GaliceaEnvironmentCheckupFormWidget', {'data': data}));
  94. },
  95. });
  96. core.form_widget_registry.add('environment_checks', FormWidget);
  97. */
  98. var FormView = require('web.FormView');
  99. var FormWidget = FormView.extend({
  100. template: "environment_checks",
  101. init: function() {
  102. this._super.apply(this, arguments);
  103. this.set("value", "[]");
  104. },
  105. events: {
  106. },
  107. render_value: function() {
  108. var data = JSON.parse(this.get('value'));
  109. if (data.length == 0) {
  110. this._replaceElement('<div />');
  111. return;
  112. }
  113. this._replaceElement(QWeb.render('GaliceaEnvironmentCheckupFormWidget', {'data': data}));
  114. }
  115. });
  116. ////////////////////
  117. return {
  118. //!! SystrayIcon: SystrayIcon,
  119. Dashboard: Dashboard,
  120. FormWidget: FormWidget
  121. };
  122. });