[FIX] website, *: use generic code for "edit event menu"

*: website_event

The 'website_event.menu_edit_menu' menuitem was added on 'website_event'
module to the 'custom menus' registry so it can be displayed by the
'website_custom_menus' service if the event page has menus to edit.

The goal of this commit is to move this code to 'website' by using a
generic 'custom_menu_edit_menu' menuitem that will be cloned to edit
every content menu on the current page with the corresponding
'EditMenuDialog'. This is needed as a fix as it would be a regression
to not have this in 16.0 since it was possible to edit any menu on a
page in previous versions.

task-2973149

closes odoo/odoo#102997

X-original-commit: 6af5ad67c9657c7dcaf4afa1ecb4561e9c72270a
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
xO-Tx
2022-10-11 16:56:58 +02:00
committed by qsm-odoo
parent d4eb7afcf1
commit 2dc82504e0
8 changed files with 50 additions and 33 deletions
@@ -40,7 +40,7 @@ patch(BurgerMenu.prototype, 'website_burger_menu', {
async _onMenuClicked(menu) {
const websiteMenu = this.websiteCustomMenus.get(menu.xmlid);
if (websiteMenu) {
this.websiteCustomMenus.open(menu.xmlid);
this.websiteCustomMenus.open(menu);
this._closeBurger();
} else {
this._super(menu);
@@ -56,8 +56,7 @@ patch(NavBar.prototype, 'website_navbar', {
onNavBarDropdownItemSelection(menu) {
const websiteMenu = this.websiteCustomMenus.get(menu.xmlid);
if (websiteMenu) {
return this.websiteCustomMenus.open(menu.xmlid);
return this.websiteCustomMenus.open(menu);
}
return this._super(menu);
},
@@ -4,6 +4,7 @@ import { registry } from "@web/core/registry";
import { EditMenuDialog } from '@website/components/dialog/edit_menu';
import { OptimizeSEODialog } from '@website/components/dialog/seo';
import {PagePropertiesDialog} from '@website/components/dialog/page_properties';
import {sprintf} from '@web/core/utils/strings';
/**
* This service displays contextual menus, depending of the state of the
@@ -19,14 +20,20 @@ export const websiteCustomMenus = {
get(xmlId) {
return registry.category('website_custom_menus').get(xmlId, null);
},
open(xmlId) {
const menu = this.get(xmlId);
if (menu.openWidget) {
return menu.openWidget(services);
open(customMenu) {
const menuConfig = this.get(customMenu.xmlid);
if (menuConfig.openWidget) {
return menuConfig.openWidget(services);
}
const menuProps = {
...(menuConfig.getProps && menuConfig.getProps(services)),
// Values on 'dynamicProps' are retrieved after the content is loaded (e.g. id of
// the content menu to be edited).
...customMenu.dynamicProps,
};
return dialog.add(
menu.Component,
menu.getProps && menu.getProps(services),
menuConfig.Component,
menuProps,
);
},
addCustomMenus(sections) {
@@ -39,7 +46,21 @@ export const websiteCustomMenus = {
if (section.childrenTree.length) {
subSections = this.addCustomMenus(section.childrenTree);
}
filteredSections.push(Object.assign({}, section, {childrenTree: subSections}));
if (section.xmlid === 'website.custom_menu_edit_menu') {
// Hack: this code will simulate an XML pre-configured navbar menuitem to edit each
// content menu found on the current page by duplicating one menuitem with
// different data (name, dialog props...). this will prevent breaking the current
// 'navbar menus' display system.
filteredSections.push(...website.currentWebsite.metadata.contentMenus.map((menu, index) => ({
...section,
name: sprintf(env._t("Edit %s"), menu[0]),
dynamicProps: {rootID: parseInt(menu[1], 10)},
// Prevent a 't-foreach' duplicate key on menus template.
id: `${section.id}-${index}`,
})));
} else {
filteredSections.push(Object.assign({}, section, {childrenTree: subSections}));
}
}
}
return filteredSections;
@@ -84,3 +105,12 @@ registry.category('website_custom_menus').add('website.menu_page_properties', {
},
})
});
registry.category('website_custom_menus').add('website.custom_menu_edit_menu', {
Component: EditMenuDialog,
// 'isDisplayed' === true => at least 1 content menu was found on the page. This
// menuitem will be cloned (in 'addCustomMenus()') to edit every content menu using
// the 'EditMenuDialog' component.
isDisplayed: (env) => env.services.website.currentWebsite
&& env.services.website.currentWebsite.metadata.contentMenus.length
&& !env.services.ui.isSmall,
});
@@ -114,7 +114,10 @@ export const websiteService = {
currentMetadata = {};
} else {
const { mainObject, seoObject, isPublished, canPublish, editableInBackend, translatable, viewXmlid } = document.documentElement.dataset;
const contentMenuEl = document.querySelector('[data-content_menu_id]');
const contentMenus = [...document.querySelectorAll('[data-content_menu_id]')].map(menu => [
menu.dataset.menu_name,
menu.dataset.content_menu_id,
]);
currentMetadata = {
path: document.location.href,
mainObject: unslugHtmlDataObject(mainObject),
@@ -124,7 +127,7 @@ export const websiteService = {
editableInBackend: editableInBackend === 'True',
title: document.title,
translatable: !!translatable,
contentMenuId: contentMenuEl && contentMenuEl.dataset.content_menu_id,
contentMenus,
// TODO: Find a better way to figure out if
// a page is editable or not. For now, we use
// the editable selector because it's the common
+6
View File
@@ -447,6 +447,12 @@
name="HTML / CSS Editor"
action="website.website_preview"/>
<menuitem id="custom_menu_edit_menu"
parent="menu_current_page"
name="Edit Menu"
sequence="40"
action="website.website_preview"/>
<menuitem id="menu_reporting"
name="Reporting"
sequence="30"
-1
View File
@@ -67,7 +67,6 @@
],
'website.assets_editor': [
'website_event/static/src/js/systray_items/*.js',
'website_event/static/src/js/services/website_custom_menus.js',
],
},
'license': 'LGPL-3',
@@ -1,14 +0,0 @@
/** @odoo-module */
import { registry } from '@web/core/registry';
import { EditMenuDialog } from '@website/components/dialog/edit_menu';
registry.category('website_custom_menus').add('website_event.menu_edit_menu', {
Component: EditMenuDialog,
isDisplayed: (env) => env.services.website.currentWebsite
&& env.services.website.currentWebsite.metadata.contentMenuId
&& !env.services.ui.isSmall,
getProps: (services) => ({
rootID: parseInt(services.website.currentWebsite.metadata.contentMenuId, 10),
}),
});
@@ -8,10 +8,4 @@
groups="base.group_no_one"
sequence="99"/>
<menuitem id="menu_edit_menu"
name="Edit Event Menu"
sequence="90"
parent="website.menu_current_page"
action="website.website_preview"/>
</data></odoo>