[FIX] website: fix website-specific content on page list

The goal of this commit is to:

- Tweak the website filter (on website pages list added at [1]) to make
it work for all website content records (page, blog, ...).

- Update the 'New Page' dialog to be able to select the website_id for
the new page.

- Tweak the '_compute_is_homepage()' method to set 'is_homepage = True'
on website's '/' page when 'homepage_url' is not set in settings.

[1]: https://github.com/odoo/odoo/commit/940f4ee875332dafa1f379970a7683be6b3ee606

task-2889981

X-original-commit: d6014c60acc4231a5e56d492d2a39deaf789cbe8
Part-of: odoo/odoo#101215
This commit is contained in:
xO-Tx
2022-09-27 11:41:51 +02:00
committed by qsm-odoo
parent d3867f48e7
commit f31c9f3b82
7 changed files with 58 additions and 20 deletions
+4
View File
@@ -599,6 +599,10 @@ class Website(Home):
template = default_templ
template = template and dict(template=template) or {}
website_id = kwargs.get('website_id')
if website_id:
website = request.env['website'].browse(website_id)
website._force()
page = request.env['website'].new_page(path, add_menu=add_menu, **template)
url = page['url']
+1 -1
View File
@@ -46,7 +46,7 @@ class Page(models.Model):
def _compute_is_homepage(self):
website = self.env['website'].get_current_website()
for page in self:
page.is_homepage = page.url == website.homepage_url
page.is_homepage = page.url == (website.homepage_url or page.website_id == website and '/')
def _set_is_homepage(self):
website = self.env['website'].get_current_website()
@@ -1,11 +1,12 @@
/** @odoo-module **/
import { useAutofocus } from '@web/core/utils/hooks';
import { useAutofocus, useService } from '@web/core/utils/hooks';
import { Dialog } from '@web/core/dialog/dialog';
import { Switch } from '@website/components/switch/switch';
import {unslugHtmlDataObject} from '../../services/website_service';
import { _t } from 'web.core';
const { xml, useState, Component } = owl;
const { xml, useState, Component, onWillStart } = owl;
const NO_OP = () => {};
@@ -81,10 +82,21 @@ export class AddPageDialog extends Component {
this.title = this.env._t("New Page");
this.primaryTitle = this.env._t("Create");
this.switchLabel = this.env._t("Add to menu");
this.website = useService('website');
this.orm = useService('orm');
this.state = useState({
addMenu: true,
name: '',
websiteId: false,
});
onWillStart(async () => {
const [currentWebsite] = await Promise.all([
await this.orm.call('website', 'get_current_website'),
this.website.fetchWebsites(),
]);
this.state.websiteId = unslugHtmlDataObject(currentWebsite).id;
});
}
@@ -93,9 +105,17 @@ export class AddPageDialog extends Component {
}
async addPage() {
await this.props.addPage(this.state.name, this.state.addMenu);
await this.props.addPage(this.state);
}
}
AddPageDialog.props = {
close: Function,
addPage: Function,
selectWebsite: {
type: Boolean,
optional: true,
},
};
AddPageDialog.components = {
Switch,
WebsiteDialog,
@@ -113,6 +133,19 @@ AddPageDialog.template = xml`
<div class="col-md-9">
<input type="text" t-model="state.name" class="form-control" required="required" t-ref="autofocus"/>
</div>
<t t-if="props.selectWebsite">
<label class="col-form-label col-md-3">Website</label>
<div class="col-md-9">
<select class="form-select" t-model="state.websiteId">
<option t-foreach="website.websites"
t-as="option"
t-key="option.id"
t-att-value="option.id"
t-esc="option.name"
/>
</select>
</div>
</t>
<Switch extraClasses="'offset-md-3 col-md-9 text-start'" label="switchLabel" value="state.addMenu" onChange="(value) => this.onChangeAddMenu(value)"/>
</div>
</WebsiteDialog>
@@ -36,12 +36,13 @@ export class PageListController extends listView.Controller {
onClickCreate() {
if (this.props.resModel === 'website.page') {
return this.dialogService.add(AddPageDialog, {
addPage: async (name, addMenu) => {
selectWebsite: true,
addPage: async (state) => {
// TODO this is duplicated code from new_content.js, this
// should be shared somehow.
// FIXME this always create on website 1 whatever we do.
const url = `/website/add/${encodeURIComponent(name)}`;
const data = await this.http.post(url, { 'add_menu': addMenu || '', csrf_token });
const websiteId = parseInt(state.websiteId);
const url = `/website/add/${encodeURIComponent(state.name)}`;
const data = await this.http.post(url, { 'add_menu': state.addMenu || '', 'website_id': websiteId, csrf_token });
if (data.view_id) {
this.actionService.doAction({
'res_model': 'ir.ui.view',
@@ -51,7 +52,7 @@ export class PageListController extends listView.Controller {
'view_mode': 'form',
});
} else {
this.website.goToWebsite({ path: data.url, edition: true });
this.website.goToWebsite({ path: data.url, edition: true, websiteId });
}
},
});
@@ -80,18 +81,18 @@ PageListController.template = `website.PageListView`;
export class PageListRenderer extends listView.Renderer {
/**
* The goal here is to tweak the renderer to display pages following some
* The goal here is to tweak the renderer to display records following some
* rules:
* - All websites (props.activeWebsite.id === 0):
* -> Show all generic/specific pages.
* -> Show all generic/specific records.
* - A website is selected:
* -> Display website-specific pages & generic ones (only those without
* -> Display website-specific records & generic ones (only those without
* specific clones).
*/
pageFilter(record, records) {
recordFilter(record, records) {
return !this.props.activeWebsite.id
|| this.props.activeWebsite.id === record.data.website_id[0]
|| !record.data.website_id[0] && records.filter(rec => rec.data.url === record.data.url).length === 1;
|| !record.data.website_id[0] && records.filter(rec => rec.data.website_url === record.data.website_url).length === 1;
}
}
PageListRenderer.props = [
@@ -8,7 +8,7 @@
</t>
</xpath>
<xpath expr="//tr[@class='o_data_row']" position="attributes">
<attribute name="t-if">pageFilter(record, list.records)</attribute>
<attribute name="t-if">recordFilter(record, list.records)</attribute>
</xpath>
</t>
@@ -17,7 +17,7 @@
<attribute name="activeWebsite">state.activeWebsite</attribute>
</xpath>
<xpath expr="//Layout" position="inside">
<t t-set-slot="control-panel-website-extra-actions" t-if="props.resModel === 'website.page'">
<t t-set-slot="control-panel-website-extra-actions">
<div class="btn-group" role="toolbar" aria-label="Main actions">
<button class="btn btn-light dropdown-toggle o-no-caret" data-bs-toggle="dropdown" aria-expanded="false">
<i class="me-1 fa fa-globe"/><span t-esc="state.activeWebsite.name"/>
@@ -146,9 +146,9 @@ export class NewContentModal extends Component {
createNewPage() {
this.dialogs.add(AddPageDialog, {
addPage: async (name, addMenu) => {
const url = `/website/add/${encodeURIComponent(name)}`;
const data = await this.http.post(url, { 'add_menu': addMenu || '', csrf_token });
addPage: async (state) => {
const url = `/website/add/${encodeURIComponent(state.name)}`;
const data = await this.http.post(url, { 'add_menu': state.addMenu || '', csrf_token });
if (data.view_id) {
this.action.doAction({
'res_model': 'ir.ui.view',
+1 -1
View File
@@ -78,7 +78,7 @@
<tree js_class="website_pages_list" type="object" action="open_website_url" default_order="url">
<field name="is_homepage" invisible="1"/>
<field name="name" string="Page Title"/>
<field name="url"/>
<field name="website_url" string="Page URL"/>
<field name="view_id" invisible="1"/>
<field name="website_indexed"/>