diff --git a/addons/website/static/src/components/views/page_kanban.js b/addons/website/static/src/components/views/page_kanban.js new file mode 100644 index 00000000000..b00d9363647 --- /dev/null +++ b/addons/website/static/src/components/views/page_kanban.js @@ -0,0 +1,31 @@ +/** @odoo-module **/ + +import {PageControllerMixin, PageRendererMixin} from "./page_views_mixin"; +import {registry} from '@web/core/registry'; +import {kanbanView} from "@web/views/kanban/kanban_view"; + + +export class PageKanbanController extends PageControllerMixin(kanbanView.Controller) { + /** + * @override + */ + async createRecord() { + return this.createWebsiteContent(); + } +} +PageKanbanController.template = 'website.PageKanbanView'; + +export class PageKanbanRenderer extends PageRendererMixin(kanbanView.Renderer) {} +PageKanbanRenderer.props = [ + ...kanbanView.Renderer.props, + "activeWebsite", +]; +PageKanbanRenderer.template = 'website.PageKanbanRenderer'; + +export const PageKanbanView = { + ...kanbanView, + Renderer: PageKanbanRenderer, + Controller: PageKanbanController, +}; + +registry.category("views").add("website_pages_kanban", PageKanbanView); diff --git a/addons/website/static/src/components/views/page_kanban.xml b/addons/website/static/src/components/views/page_kanban.xml new file mode 100644 index 00000000000..2ccc2dca2b5 --- /dev/null +++ b/addons/website/static/src/components/views/page_kanban.xml @@ -0,0 +1,24 @@ + + + + + + recordFilter(record, props.list.records) + + + recordFilter(groupOrRecord.record, props.list.records) + + + + + + state.activeWebsite + + + + + + + + + diff --git a/addons/website/static/src/components/views/page_list.js b/addons/website/static/src/components/views/page_list.js index 043bdbd0a9c..22e2a078eaf 100644 --- a/addons/website/static/src/components/views/page_list.js +++ b/addons/website/static/src/components/views/page_list.js @@ -1,78 +1,21 @@ /** @odoo-module **/ -import {AddPageDialog} from "../dialog/dialog"; +import {PageControllerMixin, PageRendererMixin} from "./page_views_mixin"; import {registry} from '@web/core/registry'; import {listView} from '@web/views/list/list_view'; -import {useService} from "@web/core/utils/hooks"; - -const {onWillStart, useState} = owl; -export class PageListController extends listView.Controller { - /** - * @override - */ - setup() { - super.setup(); - this.website = useService('website'); - - this.websiteSelection = [{id: 0, name: this.env._t("All Websites")}]; - - this.state = useState({ - activeWebsite: this.websiteSelection[0], - }); - - onWillStart(async () => { - await this.website.fetchWebsites(); - this.websiteSelection.push(...this.website.websites); - }); - } - +export class PageListController extends PageControllerMixin(listView.Controller) { /** * @override */ onClickCreate() { - if (this.props.resModel === 'website.page') { - return this.dialogService.add(AddPageDialog, {selectWebsite: true}); - } - const action = this.props.context.create_action; - if (action) { - if (/^\//.test(action)) { - window.location.replace(action); - return; - } - this.actionService.doAction(action, { - onClose: (data) => { - if (data) { - this.website.goToWebsite({path: data.path}); - } - }, - }); - } - } - - onSelectWebsite(website) { - this.state.activeWebsite = website; + return this.createWebsiteContent(); } } PageListController.template = `website.PageListView`; -export class PageListRenderer extends listView.Renderer { - /** - * The goal here is to tweak the renderer to display records following some - * rules: - * - All websites (props.activeWebsite.id === 0): - * -> Show all generic/specific records. - * - A website is selected: - * -> Display website-specific records & generic ones (only those without - * specific clones). - */ - 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.website_url === record.data.website_url).length === 1; - } -} +export class PageListRenderer extends PageRendererMixin(listView.Renderer) {} PageListRenderer.props = [ ...listView.Renderer.props, "activeWebsite", diff --git a/addons/website/static/src/components/views/page_list.xml b/addons/website/static/src/components/views/page_list.xml index dbb7c148dc4..89d5a4d655b 100644 --- a/addons/website/static/src/components/views/page_list.xml +++ b/addons/website/static/src/components/views/page_list.xml @@ -18,17 +18,7 @@ - - - - - - - - - - - + @@ -45,4 +35,18 @@ + + + + + + + + + + + + + + diff --git a/addons/website/static/src/components/views/page_views_mixin.js b/addons/website/static/src/components/views/page_views_mixin.js new file mode 100644 index 00000000000..23d3fe2d23b --- /dev/null +++ b/addons/website/static/src/components/views/page_views_mixin.js @@ -0,0 +1,80 @@ +/** @odoo-module **/ + +import {AddPageDialog} from "../dialog/dialog"; +import {useService} from "@web/core/utils/hooks"; + +const {onWillStart, useState} = owl; + +/** + * Used to share code and keep the same behaviour on different types of 'website + * content' views: + * - Trigger the 'new content' dialogs when 'CREATE' button is clicked. + * - Add a website selector on ControlPanel (that will be used by the renderer + * to filter content). + */ +export const PageControllerMixin = (component) => class extends component { + /** + * @override + */ + setup() { + super.setup(); + this.website = useService('website'); + this.dialog = useService('dialog'); + + this.websiteSelection = [{id: 0, name: this.env._t("All Websites")}]; + + this.state = useState({ + activeWebsite: this.websiteSelection[0], + }); + + onWillStart(async () => { + await this.website.fetchWebsites(); + this.websiteSelection.push(...this.website.websites); + }); + } + + /** + * Adds the new 'website content' record depending on the targeted model and + * 'create_action' passed in context. + */ + createWebsiteContent() { + if (this.props.resModel === 'website.page') { + return this.dialog.add(AddPageDialog, {selectWebsite: true}); + } + const action = this.props.context.create_action; + if (action) { + if (/^\//.test(action)) { + window.location.replace(action); + return; + } + this.actionService.doAction(action, { + onClose: (data) => { + if (data) { + this.website.goToWebsite({path: data.path}); + } + }, + }); + } + } + + onSelectWebsite(website) { + this.state.activeWebsite = website; + } +}; + +export const PageRendererMixin = (component) => class extends component { + /** + * The goal here is to tweak the renderer to display records following some + * rules: + * - All websites (props.activeWebsite.id === 0): + * -> Show all generic/specific records. + * - A website is selected: + * -> Display website-specific records & generic ones (only those without + * specific clones). + */ + 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.website_url === record.data.website_url).length === 1; + } +}; diff --git a/addons/website_blog/views/website_pages_views.xml b/addons/website_blog/views/website_pages_views.xml index b103ab81b55..566e6925ce7 100644 --- a/addons/website_blog/views/website_pages_views.xml +++ b/addons/website_blog/views/website_pages_views.xml @@ -49,32 +49,42 @@ blog.post.kanban blog.post - + + - - + + - + + + + + - + + + + Published + Not Published +