[FIX] website: copy frontend link when using the anchor option
Before this commit, clicking on the "anchor" icon from a snippet editor would copy the client action's url (introduced in [1]). This commit changes the snippet's path computation to use the target's ownerDocument location instead of the global one. [1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b task-2687506 Part-of: odoo/odoo#96401
This commit is contained in:
@@ -2458,7 +2458,7 @@ options.registry.anchor = options.Class.extend({
|
||||
}
|
||||
this._setAnchorName(anchorName + n);
|
||||
}
|
||||
return `${window.location.pathname}#${this.$target[0].id}`;
|
||||
return `${this.ownerDocument.location.pathname}#${this.$target[0].id}`;
|
||||
},
|
||||
/**
|
||||
* Creates a safe id/anchor from text.
|
||||
|
||||
@@ -42,4 +42,35 @@ wTourUtils.dragNDrop({
|
||||
console.error("The paragraph text selection was lost.");
|
||||
}
|
||||
},
|
||||
}, {
|
||||
content: "Click on the anchor option",
|
||||
trigger: '#oe_snippets .snippet-option-anchor we-button',
|
||||
run() {
|
||||
// The clipboard cannot be accessed from a script.
|
||||
// https://w3c.github.io/editing/docs/execCommand/#dfn-the-copy-command
|
||||
// The execCommand is patched for that step so that ClipboardJS still
|
||||
// sends the 'success' event.
|
||||
const oldExecCommand = document.execCommand;
|
||||
document.execCommand = () => true;
|
||||
this.$anchor[0].click();
|
||||
document.execCommand = oldExecCommand;
|
||||
}
|
||||
}, {
|
||||
content: "Check the copied url from the notification toast",
|
||||
trigger: '.o_notification_manager .o_notification_content',
|
||||
run() {
|
||||
const { textContent } = this.$anchor[0];
|
||||
const url = textContent.substring(textContent.indexOf('/'));
|
||||
|
||||
// The url should not target the client action
|
||||
if (url.startsWith('/@')) {
|
||||
console.error('The anchor option should target the frontend');
|
||||
}
|
||||
|
||||
const iframeDocument = document.querySelector('.o_iframe').contentDocument;
|
||||
const snippetId = iframeDocument.querySelector('.s_text_image').id;
|
||||
if (!url || url.indexOf(snippetId) < 0) {
|
||||
console.error('The anchor option does not target the correct snippet.');
|
||||
}
|
||||
},
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user