54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
/** @odoo-module **/
|
|
|
|
// In Odoo 19, Dropdown uses an inline xml`` template (no QWeb template named web.Dropdown).
|
|
// MenuTranslationButton is injected into DropdownItem via JS patch + XML template inheritance
|
|
// of web.DropdownItem (NOT web.NavBar.DropdownItem which is unused as a component template).
|
|
// NavBar is also patched to support translate buttons on section buttons with children.
|
|
|
|
import {DropdownItem} from "@web/core/dropdown/dropdown_item";
|
|
import {NavBar} from "@web/webclient/navbar/navbar";
|
|
import {MenuTranslationButton} from "./menu_translation_button";
|
|
import {patch} from "@web/core/utils/patch";
|
|
|
|
// Patch DropdownItem — for leaf menu items (no children)
|
|
patch(DropdownItem, {
|
|
components: {
|
|
...DropdownItem.components,
|
|
MenuTranslationButton,
|
|
},
|
|
});
|
|
|
|
patch(DropdownItem.prototype, {
|
|
setup() {
|
|
super.setup(...arguments);
|
|
this.hasTranslation = this.getHasTranslation();
|
|
},
|
|
|
|
onClick(ev) {
|
|
if (ev.target.classList.contains("translate-middle-y")) {
|
|
return;
|
|
}
|
|
super.onClick(ev);
|
|
},
|
|
|
|
getHasTranslation() {
|
|
return Boolean(odoo.translate);
|
|
},
|
|
});
|
|
|
|
// Patch NavBar — for section buttons with children (Dropdown-based)
|
|
patch(NavBar, {
|
|
components: {
|
|
...NavBar.components,
|
|
MenuTranslationButton,
|
|
},
|
|
});
|
|
|
|
patch(NavBar.prototype, {
|
|
setup() {
|
|
super.setup(...arguments);
|
|
// expose to template via __translate__ variable
|
|
this.__translate__ = Boolean(odoo.translate);
|
|
},
|
|
});
|