From f1ef4732502f8c1a6032b39128851fd39cf18251 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 22 Dec 2011 16:34:49 +0100 Subject: [PATCH] [IMP] reselect right menu item after reloading the menu, open sub-menu after installing a module bzr revid: xmo@openerp.com-20111222153449-8vdzb4wubwlqw7td --- addons/web/static/src/js/chrome.js | 48 +++++++++++++++++++++++++++++- addons/web/static/src/js/views.js | 6 ++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 71b64daa04c..015281a7a09 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -835,7 +835,12 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ this.$secondary_menu.addClass(this.folded ? 'oe_folded' : 'oe_unfolded'); }, do_reload: function() { - return this.rpc("/web/menu/load", {}, this.on_loaded); + var self = this; + return this.rpc("/web/menu/load", {}, this.on_loaded).then(function () { + if (self.current_menu) { + self.open_menu(self.current_menu); + } + }); }, on_loaded: function(data) { this.data = data; @@ -856,6 +861,46 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ localStorage.setItem('oe_menu_folded', this.folded.toString()); } }, + /** + * Opens a given menu by id, as if a user had browsed to that menu by hand + * except does not trigger any event on the way + * + * @param {Number} menu_id database id of the terminal menu to select + */ + open_menu: function (menu_id) { + this.$element.add(this.$secondary_menu).find('.active') + .removeClass('active'); + this.$secondary_menu.find('> .oe_secondary_menu').hide(); + + var $primary_menu; + var $secondary_submenu = this.$secondary_menu.find( + 'a[data-menu=' + menu_id +']'); + if ($secondary_submenu.length) { + for(;;) { + if ($secondary_submenu.hasClass('leaf')) { + $secondary_submenu.addClass('active'); + } else if ($secondary_submenu.hasClass('submenu')) { + $secondary_submenu.addClass('opened') + } + var $parent = $secondary_submenu.parent().show(); + if ($parent.hasClass('oe_secondary_menu')) { + var primary_id = $parent.data('menu-parent'); + $primary_menu = this.$element.find( + 'a[data-menu=' + primary_id + ']'); + break; + } + $secondary_submenu = $parent.prev(); + } + } else { + $primary_menu = this.$element.find('a[data-menu=' + menu_id + ']'); + } + if (!$primary_menu.length) { + return; + } + $primary_menu.addClass('active'); + this.$secondary_menu.find( + 'div[data-menu-parent=' + $primary_menu.data('menu') + ']').show(); + }, on_menu_click: function(ev, id) { id = id || 0; var $clicked_menu, manual = false; @@ -873,6 +918,7 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ } if (this.do_menu_click($clicked_menu, manual) && id) { + this.current_menu = id; this.session.active_id = id; this.rpc('/web/menu/action', {'menu_id': id}, this.on_menu_action_loaded); } diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 42298c5c363..90617344bee 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -72,7 +72,7 @@ session.web.ActionManager = session.web.Widget.extend({ else if (state.model && state.id) { // TODO handle context & domain ? this.null_action(); - action = { + var action = { res_model: state.model, res_id: state.id, type: 'ir.actions.act_window', @@ -145,7 +145,9 @@ session.web.ActionManager = session.web.Widget.extend({ this.dialog.open(); } else { if(action.menu_id) { - return this.widget_parent.do_action(action); + return this.widget_parent.do_action(action, function () { + session.webclient.menu.open_menu(action.menu_id); + }); } this.dialog_stop(); this.content_stop();