Fabien Meghazi (OpenERP) has proposed merging lp:~openerp-dev/openerp-web/trunk-menu-reflow-fme into lp:openerp-web.
Requested reviews: OpenERP R&D Team (openerp-dev) For more details, see: https://code.launchpad.net/~openerp-dev/openerp-web/trunk-menu-reflow-fme/+merge/139688 Dynamically reflow the top menu items. openerp.web.Menu#reflow() can be called at any time. It is currently called when menu_loaded event is triggered and on window resize. While resizing, I could not set overflow hidden because of table layout so I hide the menu during resizing. -- https://code.launchpad.net/~openerp-dev/openerp-web/trunk-menu-reflow-fme/+merge/139688 Your team OpenERP R&D Team is requested to review the proposed merge of lp:~openerp-dev/openerp-web/trunk-menu-reflow-fme into lp:openerp-web.
=== modified file 'addons/web/static/src/js/chrome.js' --- addons/web/static/src/js/chrome.js 2012-12-12 20:51:20 +0000 +++ addons/web/static/src/js/chrome.js 2012-12-13 12:37:36 +0000 @@ -804,6 +804,7 @@ this.maximum_visible_links = 'auto'; // # of menu to show. 0 = do not crop, 'auto' = algo this.data = {data:{children:[]}}; this.on("menu_loaded", this, function (menu_data) { + self.reflow(); // launch the fetch of needaction counters, asynchronous if (!_.isEmpty(menu_data.all_menu_ids)) { this.rpc("/web/menu/load_needaction", {menu_ids: menu_data.all_menu_ids}).done(function(r) { @@ -811,7 +812,18 @@ }); } }); - + var resizing_timer = null; + instance.web.bus.on('resize', this, function(ev) { + if (resizing_timer) { + clearTimeout(resizing_timer); + } else { + self.$el.hide(); + } + resizing_timer = setTimeout(function() { + self.reflow(); + resizing_timer = null; + }, 300); + }); }, start: function() { this._super.apply(this, arguments); @@ -829,7 +841,6 @@ var self = this; this.data = {data: data}; this.renderElement(); - this.limit_entries(); // Hide toplevel item if there is only one var $toplevel = this.$("li"); if($toplevel.length == 1) { @@ -856,23 +867,30 @@ } }); }, - limit_entries: function() { - var maximum_visible_links = this.maximum_visible_links; - if (maximum_visible_links === 'auto') { - maximum_visible_links = this.auto_limit_entries(); - } - if (maximum_visible_links < this.data.data.children.length) { - var $more = $(QWeb.render('Menu.more')), - $index = this.$el.find('li').eq(maximum_visible_links - 1); - $index.after($more); - //$('.oe_topbar').append($more); - $more.find('.oe_menu_more').append($index.next().nextAll()); - } - }, - auto_limit_entries: function() { - // TODO: auto detect overflow and bind window on resize - var width = $(window).width(); - return Math.floor(width / 125); + reflow: function() { + var self = this; + this.$el.show(); + var $more_container = $('.oe_menu_more_container').hide(); + var $more = $('.oe_menu_more'); + $more.find('> li').insertBefore($more_container); + var $li = this.$('> li').not($more_container).hide(); + $li.each(function() { + var remaining_space = self.$el.parent().width() - $more_container.outerWidth(); + self.$el.parent().children(':visible').each(function() { + remaining_space -= $(this).outerWidth(); + }); + if ($(this).width() > remaining_space) { + return false; + } + $(this).show(); + }); + $more.append($li.filter(':hidden').show()); + $more_container.toggle(!!$more.children().length); + // Hide toplevel item if there is only one + var $toplevel = this.$("> li:visible"); + if ($toplevel.length === 1) { + $toplevel.hide(); + } }, /** * Opens a given menu by id, as if a user had browsed to that menu by hand === modified file 'addons/web/static/src/xml/base.xml' --- addons/web/static/src/xml/base.xml 2012-12-11 15:24:55 +0000 +++ addons/web/static/src/xml/base.xml 2012-12-13 12:37:36 +0000 @@ -348,16 +348,14 @@ <li t-foreach="widget.data.data.children" t-as="menu"> <t t-call="Menu.link"/> </li> + <li class="oe_menu_more_container" style="display: none;"> + <span class="oe_topbar_item oe_menu_more_link oe_dropdown_toggle oe_dropdown_arrow"> + More + <ul class="oe_menu_more oe_dropdown_menu"/> + </span> + </li> </ul> </t> -<t t-name="Menu.more"> - <li class="oe_menu_more_container"> - <span class="oe_topbar_item oe_menu_more_link oe_dropdown_toggle oe_dropdown_arrow"> - More - <ul class="oe_menu_more oe_dropdown_menu"/> - </span> - </li> -</t> <t t-name="Menu.secondary"> <div t-foreach="widget.data.data.children" t-as="menu" style="display: none" class="oe_secondary_menu" t-att-data-menu-parent="menu.id"> <t t-foreach="menu.children" t-as="menu">
_______________________________________________ Mailing list: https://launchpad.net/~openerp-dev-gtk Post to : openerp-dev-gtk@lists.launchpad.net Unsubscribe : https://launchpad.net/~openerp-dev-gtk More help : https://help.launchpad.net/ListHelp