[FIX] website: return to the correct url after editing in backend

Before this commit, clicking on the breadcrumb item "Website Editor"
after an "Edit in backend" systray item click would not redirect to the
edited object path. It would redo the website_editor action with the
initial params (most often path is undefined, and the component will by
default redirect to '/').

Now, when clicking on the "Edit in backend" systray, the frontend path
of the edited object is saved in the service. The client action
component takes it as the default path for the iframe if there is one.

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 3326281e1a
commit 2eef2b5430
3 changed files with 42 additions and 18 deletions
@@ -27,6 +27,7 @@ export class WebsitePreview extends Component {
return () => {
this.websiteService.currentWebsiteId = null;
this.websiteService.pageDocument = null;
this.websiteService.contentWindow = null;
};
}, () => [this.props.action.context.params]);
}
@@ -46,25 +47,28 @@ export class WebsitePreview extends Component {
}
get path() {
let path = this.props.action.context.params && this.props.action.context.params.path;
if (path) {
const url = new URL(path, window.location.origin);
if (this._isTopWindowURL(url)) {
// If the client action is initialized with a path that
// should not be opened inside the iframe (= something we
// would want to open on the top window), we consider that
// this is not a valid flow. Instead of trying to open it on
// the top window, we initialize the iframe with the
// website homepage...
path = '/';
let path = this.websiteService.editedObjectPath;
if (!path) {
path = this.props.action.context.params && this.props.action.context.params.path;
if (path) {
const url = new URL(path, window.location.origin);
if (this._isTopWindowURL(url)) {
// If the client action is initialized with a path that
// should not be opened inside the iframe (= something we
// would want to open on the top window), we consider that
// this is not a valid flow. Instead of trying to open it on
// the top window, we initialize the iframe with the
// website homepage...
path = '/';
} else {
// ... otherwise, the path still needs to be normalized (as
// it would be if the given path was used as an href of a
// <a/> element).
path = url.pathname + url.search + url.hash;
}
} else {
// ... otherwise, the path still needs to be normalized (as
// it would be if the given path was used as an href of a
// <a/> element).
path = url.pathname + url.search + url.hash;
path = '/';
}
} else {
path = '/';
}
return path;
}
@@ -91,6 +95,7 @@ export class WebsitePreview extends Component {
this.title.setParts({ action: this.currentTitle });
this.websiteService.pageDocument = this.iframe.el.contentDocument;
this.websiteService.contentWindow = this.iframe.el.contentWindow;
// Before leaving the iframe, its content is replicated on an
// underlying iframe, to avoid for white flashes (visible on
@@ -27,6 +27,8 @@ export const websiteService = {
let currentMetadata = {};
let fullscreen;
let pageDocument;
let contentWindow;
let editedObjectPath;
const context = reactive({
showNewContentModal: false,
});
@@ -85,6 +87,18 @@ export const websiteService = {
get pageDocument() {
return pageDocument;
},
set contentWindow(window) {
contentWindow = window;
},
get contentWindow() {
return contentWindow;
},
set editedObjectPath(path) {
editedObjectPath = path;
},
get editedObjectPath() {
return editedObjectPath;
},
goToWebsite({ websiteId = currentWebsiteId || websites[0].id, path = '/' } = {}) {
action.doAction('website.website_preview', {
clearBreadcrumbs: true,
@@ -5,12 +5,16 @@ import { useService } from "@web/core/utils/hooks";
import { Dropdown } from "@web/core/dropdown/dropdown";
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
const { Component } = owl;
const { Component, onMounted } = owl;
export class EditInBackendSystray extends Component {
setup() {
this.websiteService = useService('website');
this.actionService = useService('action');
onMounted(() => {
this.websiteService.editedObjectPath = null;
});
}
getElements() {
@@ -22,6 +26,7 @@ export class EditInBackendSystray extends Component {
editInBackend() {
const { metadata: { mainObject } } = this.websiteService.currentWebsite;
this.websiteService.editedObjectPath = this.websiteService.contentWindow.location.pathname;
this.actionService.doAction({
res_model: mainObject.model,
res_id: mainObject.id,