mirror of https://github.com/OCA/web.git
commit
9d9af6a077
|
@ -128,6 +128,8 @@ odoo.define("web_responsive", function (require) {
|
||||||
for (const n in this._apps) {
|
for (const n in this._apps) {
|
||||||
this._apps[n].web_icon_data = menuData.children[n].web_icon_data;
|
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
|
// Store menu data in a format searchable by fuzzy.js
|
||||||
this._searchableMenus = _.reduce(menuData.children, findNames, {});
|
this._searchableMenus = _.reduce(menuData.children, findNames, {});
|
||||||
// Search only after timeout, for fast typers
|
// 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
|
* Use chooses a search result, so we navigate to that menu
|
||||||
*
|
*
|
||||||
|
@ -234,10 +263,8 @@ odoo.define("web_responsive", function (require) {
|
||||||
_searchResultChosen: function (event) {
|
_searchResultChosen: function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const $result = $(event.currentTarget),
|
const $result = $(event.currentTarget);
|
||||||
text = $result.text().trim(),
|
const data = $result.data();
|
||||||
data = $result.data(),
|
|
||||||
suffix = ~text.indexOf("/") ? "/" : "";
|
|
||||||
// Load the menu view
|
// Load the menu view
|
||||||
this.trigger_up("menu_clicked", {
|
this.trigger_up("menu_clicked", {
|
||||||
action_id: data.actionId,
|
action_id: data.actionId,
|
||||||
|
@ -245,11 +272,14 @@ odoo.define("web_responsive", function (require) {
|
||||||
previous_menu_id: data.parentId,
|
previous_menu_id: data.parentId,
|
||||||
});
|
});
|
||||||
// Find app that owns the chosen menu
|
// Find app that owns the chosen menu
|
||||||
const app = _.find(this._apps, function (_app) {
|
const app = this.menuData.children.find((app_menu) => {
|
||||||
return text.indexOf(_app.name + suffix) === 0;
|
return this._isInMenuTree(app_menu, data.menuId);
|
||||||
});
|
});
|
||||||
|
if (!app) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Update navbar menus
|
// Update navbar menus
|
||||||
core.bus.trigger("change_menu_section", app.menuID);
|
core.bus.trigger("change_menu_section", app.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue