advance_nav.js 4.0 KB

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