mirror of https://github.com/OCA/web.git
[FIX] web_responsive: slashes in app names
When the app name had a slash ("/") on it we couldn't properly find it by name. This alternative doesn't depend on such weak rule. We'll find out the root app element for our submenu from the data already available in the widget. TT40970pull/2371/head
parent
32a028e2fe
commit
9e4abc1047
|
@ -128,6 +128,8 @@ odoo.define("web_responsive", function (require) {
|
|||
for (const n in this._apps) {
|
||||
this._apps[n].web_icon_data = menuData.children[n].web_icon_data;
|
||||
}
|
||||
// This is handy to be kept
|
||||
this.menuData = menuData;
|
||||
// Store menu data in a format searchable by fuzzy.js
|
||||
this._searchableMenus = _.reduce(menuData.children, findNames, {});
|
||||
// Search only after timeout, for fast typers
|
||||
|
@ -226,6 +228,33 @@ odoo.define("web_responsive", function (require) {
|
|||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Filters which menu tree object contains a given subelement
|
||||
*
|
||||
* @param {Array|Object} menu containing the tree to search for
|
||||
* @param {Number} id The id to find
|
||||
* @returns {Object}
|
||||
*/
|
||||
_isInMenuTree: function (menu, id) {
|
||||
let tree = menu;
|
||||
if (tree instanceof Object && tree.children) {
|
||||
tree = tree.children;
|
||||
}
|
||||
for (const node of tree) {
|
||||
if (node.id === id) {
|
||||
return node;
|
||||
} else if (node.children.length === 0) {
|
||||
continue;
|
||||
} else {
|
||||
const root = this._isInMenuTree(node.children, id);
|
||||
if (root !== null) {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Use chooses a search result, so we navigate to that menu
|
||||
*
|
||||
|
@ -234,10 +263,8 @@ odoo.define("web_responsive", function (require) {
|
|||
_searchResultChosen: function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const $result = $(event.currentTarget),
|
||||
text = $result.text().trim(),
|
||||
data = $result.data(),
|
||||
suffix = ~text.indexOf("/") ? "/" : "";
|
||||
const $result = $(event.currentTarget);
|
||||
const data = $result.data();
|
||||
// Load the menu view
|
||||
this.trigger_up("menu_clicked", {
|
||||
action_id: data.actionId,
|
||||
|
@ -245,11 +272,14 @@ odoo.define("web_responsive", function (require) {
|
|||
previous_menu_id: data.parentId,
|
||||
});
|
||||
// Find app that owns the chosen menu
|
||||
const app = _.find(this._apps, function (_app) {
|
||||
return text.indexOf(_app.name + suffix) === 0;
|
||||
const app = this.menuData.children.find((app_menu) => {
|
||||
return this._isInMenuTree(app_menu, data.menuId);
|
||||
});
|
||||
if (!app) {
|
||||
return;
|
||||
}
|
||||
// Update navbar menus
|
||||
core.bus.trigger("change_menu_section", app.menuID);
|
||||
core.bus.trigger("change_menu_section", app.id);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue