diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-03-19 14:18:55 +0100 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-03-19 15:17:56 +0100 |
| commit | 71616e8d4f9a5bf92487dc6cc89d4945d29b4343 (patch) | |
| tree | ddd27ccfc4e8b6f3aed7436210c44c6b7e5f55fc /addons/web/static/src | |
| parent | e2dd31cd7bb51f3908c8737f6d474312afa948f4 (diff) | |
[FIX] web: pick correct menu item on hashchange
Before this commit, we had the following issue:
1. install CRM and Sales
2. Sales > Customers > (open any form)
3. Click on browser's "back" button
We are redirected to the contact kanban view in CRM
instead of Sales.
This is due to the fact that both menu items share the
same action. When the user uses the browser's "back" button
(AKA. it triggers an hashchange event), the web_client opens
the first menu_item that matches the action.
This commit fixes the issue by allowing us to open an action
by providing a menu ID:
1. If it matches the action, then it opens this menu
instead of the first match.
2. If we do not provide any menuID, or this menuID does
not match with the action, it falls back to the first
menu matching this action.
Fixes #23639
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/chrome/menu.js | 17 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/web_client.js | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/addons/web/static/src/js/chrome/menu.js b/addons/web/static/src/js/chrome/menu.js index c9d58d89c81..35e57f1c562 100644 --- a/addons/web/static/src/js/chrome/menu.js +++ b/addons/web/static/src/js/chrome/menu.js @@ -145,15 +145,22 @@ var Menu = Widget.extend({ }); }, /** - * Call open_menu with the first menu_item matching an action_id + * Call open_menu on a menu_item that matches the action_id + * + * If `menuID` is a match on this action, open this menu_item. + * Otherwise open the first menu_item that matches the action_id. * * @param {Number} id the action_id to match + * @param {Number} [menuID] a menu ID that may match with provided action */ - open_action: function (id) { + open_action: function (id, menuID) { var $menu = this.$el.add(this.$secondary_menus).find('a[data-action-id="' + id + '"]'); - var menu_id = $menu.data('menu'); - if (menu_id) { - this.open_menu(menu_id); + if (!(menuID && $menu.filter("[data-menu='" + menuID + "']").length)) { + // menuID doesn't match action, so pick first menu_item + menuID = $menu.data('menu'); + } + if (menuID) { + this.open_menu(menuID); } }, /** diff --git a/addons/web/static/src/js/chrome/web_client.js b/addons/web/static/src/js/chrome/web_client.js index ebbc0bb3143..dbdaedfddf2 100644 --- a/addons/web/static/src/js/chrome/web_client.js +++ b/addons/web/static/src/js/chrome/web_client.js @@ -139,7 +139,7 @@ return AbstractWebClient.extend({ self.action_manager.do_load_state(state, !!self._current_state).then(function () { var action = self.action_manager.get_inner_action(); if (action) { - self.menu.open_action(action.action_descr.id); + self.menu.open_action(action.action_descr.id, state.menu_id); } }); } |
