[IMP] website: add publish systray item

See merge commit for more information.

task-2687506
This commit is contained in:
Younn Olivier
2022-06-24 10:28:05 +02:00
committed by qsm-odoo
parent fbfe4d1fcb
commit 028efcbffe
6 changed files with 64 additions and 6 deletions
@@ -2,6 +2,7 @@
import { registry } from '@web/core/registry';
import { useService } from '@web/core/utils/hooks';
import { unslugHtmlDataObject } from '../../services/website_service';
const { Component, onWillStart, useRef, useEffect } = owl;
@@ -84,8 +85,12 @@ export class WebsitePreview extends Component {
this.currentUrl = this.iframe.el.contentDocument.location.href;
history.replaceState({}, this.props.action.display_name, this.currentUrl);
const { mainObject, isPublished, canPublish } = this.iframe.el.contentDocument.documentElement.dataset;
this.websiteService.currentMetadata = {
path: this.currentUrl,
mainObject: unslugHtmlDataObject(mainObject),
isPublished: isPublished === 'True',
canPublish: canPublish === 'True',
};
// Before leaving the iframe, its content is replicated on an
@@ -20,6 +20,8 @@ patch(NavBar.prototype, 'website_navbar', {
if (this.env.debug && !websiteSystrayRegistry.contains('web.debug_mode_menu')) {
websiteSystrayRegistry.add('web.debug_mode_menu', registry.category('systray').get('web.debug_mode_menu'), {sequence: 100});
}
useBus(websiteSystrayRegistry, 'CONTENT-UPDATED', () => this.render(true));
},
/**
@@ -6,7 +6,7 @@ const { reactive } = owl;
const websiteSystrayRegistry = registry.category('website_systray');
const unslugHtmlDataObject = (repr) => {
export const unslugHtmlDataObject = (repr) => {
const match = repr && repr.match(/(.+)\((\d+),(.*)\)/);
if (!match) {
return null;
@@ -37,6 +37,7 @@ export const websiteService = {
},
set currentMetadata(metadata) {
currentMetadata = metadata;
websiteSystrayRegistry.trigger('CONTENT-UPDATED');
},
get currentWebsite() {
const currentWebsite = websites.find(w => w.id === currentWebsiteId);
@@ -0,0 +1,52 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { Switch } from '@website/components/switch/switch';
import { useService, useBus } from '@web/core/utils/hooks';
const { Component, xml, useState } = owl;
const websiteSystrayRegistry = registry.category('website_systray');
class PublishSystray extends Component {
setup() {
this.website = useService('website');
this.rpc = useService('rpc');
this.state = useState({
published: this.website.currentWebsite.metadata.isPublished,
});
useBus(websiteSystrayRegistry, 'CONTENT-UPDATED', () => this.state.published = this.website.currentWebsite.metadata.isPublished);
}
get label() {
return this.state.published ? this.env._t("Published") : this.env._t("Unpublished");
}
publishContent() {
this.state.published = !this.state.published;
const { metadata: { mainObject } } = this.website.currentWebsite;
return this.rpc('/website/publish', {
id: mainObject.id,
object: mainObject.model,
});
}
}
PublishSystray.template = xml`
<div t-on-click="publishContent" class="o_menu_systray_item d-md-flex ml-auto">
<a href="#">
<Switch value="state.published" extraClasses="'mb-0 o_switch_danger_success'"/>
<t t-esc="this.label"/>
</a>
</div>`;
PublishSystray.components = {
Switch
};
export const systrayItem = {
Component: PublishSystray,
isDisplayed: env => env.services.website.currentWebsite && env.services.website.currentWebsite.metadata.canPublish,
};
websiteSystrayRegistry.add("Publish", systrayItem, { sequence: 12 });
@@ -75,11 +75,7 @@
</t>
</div>
<div class="o_menu_systray d-none d-md-flex ml-auto" groups="website.group_website_publisher">
<t t-call="website.website_publisher">
<t t-set="extra_classes" t-valuef="o_menu_systray_item"/>
<t t-set="desktop_navbar" t-value="true"/>
</t>
<div class="o_menu_systray d-none d-md-flex" groups="website.group_website_publisher">
<!-- Mobile preview -->
<div class="o_mobile_preview o_menu_systray_item" id="mobile-menu">
<a data-action="show-mobile-preview" href="#" accesskey="v"><span title="Mobile preview" role="img" aria-label="Mobile preview" class="fa fa-lg fa-mobile"/></a>
@@ -49,6 +49,8 @@
'data-main-object': repr(main_object) if main_object else None,
'data-seo-object': repr(seo_object) if seo_object else None,
'data-oe-company-name': res_company.name,
'data-is-published': 'website_published' in main_object.fields_get() and main_object.website_published,
'data-can-publish': 'can_publish' in main_object.fields_get() and main_object.can_publish,
})"/>
</xpath>