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.

63 lines
2.6 KiB

7 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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. WebClient.include({
  26. start: function () {
  27. var self = this;
  28. var load_config = this._rpc({
  29. route: '/config/muk_web_client_refresh.refresh_delay',
  30. }).done(function(result) {
  31. self.refresh = _.throttle(self.refresh.bind(self), result.refresh_delay || 1000, true);
  32. });
  33. return $.when(this._super.apply(this, arguments), load_config);
  34. },
  35. show_application: function() {
  36. var channel = 'refresh';
  37. this.bus_declare_channel(channel, this.refresh);
  38. return this._super.apply(this, arguments);
  39. },
  40. refresh: function(message) {
  41. var widget = this.action_manager && this.action_manager.inner_widget;
  42. var active_view = widget ? widget.active_view : false;
  43. if (active_view && session.uid !== message.uid) {
  44. var controller = this.action_manager.inner_widget.active_view.controller;
  45. if(controller && controller.modelName === message.model && controller.mode === "readonly") {
  46. if(active_view.type === "form" && message.ids.includes(widget.env.currentId)) {
  47. controller.reload();
  48. } else if(active_view.type === "list" &&
  49. (message.create || _.intersection(message.ids, widget.env.ids) >= 1)) {
  50. controller.reload();
  51. } else if(active_view.type === "kanban" &&
  52. (message.create || _.intersection(message.ids, widget.env.ids) >= 1)) {
  53. controller.reload();
  54. }
  55. }
  56. }
  57. },
  58. });
  59. });