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.

67 lines
2.6 KiB

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