diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py
index 4c180f154a5..d878b5bfc0d 100644
--- a/addons/website/controllers/main.py
+++ b/addons/website/controllers/main.py
@@ -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']
diff --git a/addons/website/models/website_page.py b/addons/website/models/website_page.py
index eeb9139dc9d..f1384394ca2 100644
--- a/addons/website/models/website_page.py
+++ b/addons/website/models/website_page.py
@@ -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()
diff --git a/addons/website/static/src/components/dialog/dialog.js b/addons/website/static/src/components/dialog/dialog.js
index 499f7f87afc..607457ea594 100644
--- a/addons/website/static/src/components/dialog/dialog.js
+++ b/addons/website/static/src/components/dialog/dialog.js
@@ -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`
+
+
+
+
+
+
diff --git a/addons/website/static/src/components/views/page_list.js b/addons/website/static/src/components/views/page_list.js
index 656841201dd..c91afa1447f 100644
--- a/addons/website/static/src/components/views/page_list.js
+++ b/addons/website/static/src/components/views/page_list.js
@@ -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 = [
diff --git a/addons/website/static/src/components/views/page_list.xml b/addons/website/static/src/components/views/page_list.xml
index a64e6368b67..dbb7c148dc4 100644
--- a/addons/website/static/src/components/views/page_list.xml
+++ b/addons/website/static/src/components/views/page_list.xml
@@ -8,7 +8,7 @@
- pageFilter(record, list.records)
+ recordFilter(record, list.records)
@@ -17,7 +17,7 @@
state.activeWebsite
-
+