advance_nav.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. openerp.eiru_base_menu = function(instance) {
  2. var _t = instance.web._t,
  3. _lt = instance.web._lt,
  4. QWeb = instance.web.qweb;
  5. instance.web.Menu.include({
  6. bind_menu: function() {
  7. var self = this;
  8. if($('nav ul li.tnav ul').closest("li").children("ul").length) {
  9. $('nav ul li.tnav ul').closest("li").children("ul li a").append('<b class="caret"></b>');
  10. }
  11. this.$secondary_menus = this.$el.parents().find('.oe_secondary_menus_container')
  12. this.$secondary_menus.on('click', 'a[data-menu]', this.on_menu_click);
  13. this.$el.on('click', 'a[data-menu]', this.on_top_menu_click);
  14. // Hide second level submenus
  15. this.$secondary_menus.find('.oe_menu_toggler').siblings('.oe_secondary_submenu').hide();
  16. if (self.current_menu) {
  17. self.open_menu(self.current_menu);
  18. }
  19. this.trigger('menu_bound');
  20. var lazyreflow = _.debounce(this.reflow.bind(this), 200);
  21. instance.web.bus.on('resize', this, function() {
  22. if (parseInt(self.$el.parent().css('width')) <= 768 ) {
  23. lazyreflow('all_outside');
  24. } else {
  25. lazyreflow();
  26. }
  27. });
  28. instance.web.bus.trigger('resize');
  29. $('nav#oe_main_menu_navbar ul li ul.oe_secondary_submenu').addClass("tnav");
  30. $('.oe_leftbar_open').toggle(
  31. function(){
  32. $(this).removeClass("show1");
  33. $(".oe_leftbar").fadeIn(500).removeClass("leftbarhide")},
  34. function(){
  35. $(this).addClass("show1");
  36. $(".oe_leftbar").fadeOut(500).addClass("leftbarhide");
  37. });
  38. this.is_bound.resolve();
  39. },
  40. reflow: function(behavior) {
  41. var self = this;
  42. var $more_container = this.$('#menu_more_container').hide();
  43. var $more = this.$('#menu_more');
  44. var $systray = this.$el.parents().find('.oe_systray');
  45. $more.children('li').insertBefore($more_container); // Pull all the items out of the more menu
  46. // 'all_outside' beahavior should display all the items, so hide the more menu and exit
  47. if (behavior === 'all_outside') {
  48. this.$el.find('li').show();
  49. $more_container.hide();
  50. return;
  51. }
  52. var $toplevel_items = this.$el.find('li.tnav').not($more_container).not($systray.find('li')).hide();
  53. $toplevel_items.each(function() {
  54. // In all inside mode, we do not compute to know if we must hide the items, we hide them all
  55. if (behavior === 'all_inside') {
  56. return false;
  57. }
  58. var remaining_space = self.$el.parent().width() - $more_container.outerWidth();
  59. self.$el.parent().children(':visible').each(function() {
  60. remaining_space -= $(this).outerWidth() + 55;
  61. });
  62. if ($(this).width() > remaining_space) {
  63. return false;
  64. }
  65. $(this).show();
  66. });
  67. $more.append($toplevel_items.filter(':hidden').show());
  68. $more_container.toggle(!!$more.children().length || behavior === 'all_inside');
  69. // Hide toplevel item if there is only one
  70. var $toplevel = this.$el.children("li.tnav:visible");
  71. if ($toplevel.length === 1 && behavior != 'all_inside') {
  72. $toplevel.hide();
  73. }
  74. },
  75. });
  76. };