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.

78 lines
3.1 KiB

  1. //-*- coding: utf-8 -*-
  2. //############################################################################
  3. //
  4. // This module copyright (C) 2015 Therp BV <http://therp.nl>.
  5. //
  6. // This program is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as
  8. // published by the Free Software Foundation, either version 3 of the
  9. // License, or (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. //
  19. //############################################################################
  20. openerp.web_menu_navbar_needaction = function(instance)
  21. {
  22. instance.web.Menu.include({
  23. init: function()
  24. {
  25. var self = this,
  26. result = this._super.apply(this, arguments);
  27. this.on('menu_bound', this, function()
  28. {
  29. new instance.web.Model('ir.config_parameter')
  30. .call('get_param',
  31. ['web_menu_navbar_needaction.refresh_timeout'])
  32. .then(self.proxy(self.refresh_navbar_needaction))
  33. });
  34. return result;
  35. },
  36. refresh_navbar_needaction: function(timeout)
  37. {
  38. if(timeout)
  39. {
  40. setTimeout(this.proxy(this.refresh_navbar_needaction), timeout, timeout);
  41. }
  42. return this.load_navbar_needaction();
  43. },
  44. load_navbar_needaction: function()
  45. {
  46. this.navbar_menu_ids = this.$el.parents('body')
  47. .find('#oe_main_menu_navbar a[data-menu]')
  48. .filter(function() { return parseInt(jQuery(this).attr('data-menu')); })
  49. .map(function() { return parseInt(jQuery(this).attr('data-menu')); })
  50. .get();
  51. return new instance.web.Model('ir.ui.menu')
  52. .call('get_navbar_needaction_data', [this.navbar_menu_ids])
  53. .then(this.proxy(this.process_navbar_needaction));
  54. },
  55. process_navbar_needaction: function(data)
  56. {
  57. var self = this;
  58. _.each(data, function (needaction_count, menu_id)
  59. {
  60. var $item = self.$el.parents('body').find(
  61. _.str.sprintf('#oe_main_menu_navbar a[data-menu="%s"]',
  62. menu_id));
  63. if(!$item.length)
  64. {
  65. return;
  66. }
  67. $item.find('.badge').remove();
  68. if(needaction_count)
  69. {
  70. $item.append(
  71. instance.web.qweb.render("Menu.needaction_counter",
  72. {widget : {needaction_counter: needaction_count}}));
  73. }
  74. });
  75. },
  76. })
  77. }