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.

62 lines
2.5 KiB

  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 config = require('web.config');
  22. var session = require('web.session');
  23. var WebClient = require('web.WebClient');
  24. var BusService = require('bus.BusService');
  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_delay = result.refresh_delay;
  32. self._reload = _.throttle(self._reload, self.refresh_delay || 1000);
  33. });
  34. return $.when(this._super.apply(this, arguments), load_config);
  35. },
  36. show_application: function() {
  37. this.bus_declare_channel('refresh', this.refresh.bind(this));
  38. return this._super.apply(this, arguments);
  39. },
  40. refresh: function(message) {
  41. var action = this.action_manager.getCurrentAction();
  42. var controller = this.action_manager.getCurrentController();
  43. if (!this.call('bus_service', 'isMasterTab') || session.uid !== message.uid &&
  44. action && controller && controller.widget.modelName === message.model &&
  45. controller.widget.mode === "readonly") {
  46. if(controller.widget.isMultiRecord && (message.create || _.intersection(message.ids, action.env.ids) >= 1)) {
  47. this._reload(message, controller);
  48. } else if(!controller.widget.isMultiRecord && message.ids.includes(action.env.currentId)) {
  49. this._reload(message, controller);
  50. }
  51. }
  52. },
  53. _reload: function(message, controller) {
  54. controller.widget.reload();
  55. },
  56. });
  57. });