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.

66 lines
2.5 KiB

7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_web_client_refresh.channel', function (require) {
  20. "use strict";
  21. var WebClient = require('web.WebClient');
  22. var session = require('web.session');
  23. var config = require('web.config');
  24. var bus = require('bus.bus');
  25. var utils = require('muk_web_utils.common');
  26. WebClient.include({
  27. start: function () {
  28. var self = this;
  29. var load_config = this._rpc({
  30. route: '/config/muk_web_client_refresh.refresh_delay',
  31. }).done(function(result) {
  32. self.refresh_delay = result.refresh_delay;
  33. });
  34. return $.when(this._super.apply(this, arguments), load_config);
  35. },
  36. show_application: function() {
  37. var channel = 'refresh';
  38. this.bus_declare_channel(channel, this.refresh);
  39. return this._super.apply(this, arguments);
  40. },
  41. refresh: function(message) {
  42. var self = this;
  43. utils.delay(function() {
  44. var widget = self.action_manager && self.action_manager.inner_widget;
  45. var active_view = widget ? widget.active_view : false;
  46. if (active_view && message.uid && session.uid !== message.uid) {
  47. var controller = self.action_manager.inner_widget.active_view.controller;
  48. if(controller.modelName === message.model && controller.mode === "readonly") {
  49. if(active_view.type === "form" && message.ids.includes(widget.env.currentId)) {
  50. controller.reload();
  51. } else if(active_view.type === "list") {
  52. controller.reload();
  53. } else if(active_view.type === "kanban") {
  54. controller.reload();
  55. }
  56. }
  57. }
  58. }, self.refresh_delay || 1000);
  59. },
  60. });
  61. });