Skip to content
Snippets Groups Projects
Commit 14cb5ccf authored by Antoine Guenet's avatar Antoine Guenet
Browse files

[FIX] mass_mailing: do not allow links within background-image elements

Since background-image elements and their children will be flattened
into images, links within them won't work. This removes the link button
of the editor toolbar, as well as the link and button commands in those
contexts.

task-2856858

Part-of: odoo/odoo#91314
parent 61f7366d
Branches
Tags
No related merge requests found
......@@ -3,6 +3,7 @@ odoo.define('mass_mailing.wysiwyg', function (require) {
var Wysiwyg = require('web_editor.wysiwyg');
var MassMailingSnippetsMenu = require('mass_mailing.snippets.editor');
const {closestElement} = require('@web_editor/../lib/odoo-editor/src/OdooEditor');
const MassMailingWysiwyg = Wysiwyg.extend({
//--------------------------------------------------------------------------
......@@ -38,13 +39,38 @@ const MassMailingWysiwyg = Wysiwyg.extend({
*/
_getCommands: function () {
const commands = this._super();
const linkCommand = commands.find(command => command.title === 'Link');
if (linkCommand) {
const linkCommands = commands.filter(command => command.title === 'Link' || command.title === 'Button');
for (const linkCommand of linkCommands) {
// Don't open the dialog: use the link tools.
linkCommand.callback = () => this.toggleLinkTools({forceDialog: false});
// Remove the command if the selection is within a background-image.
const superIsDisabled = linkCommand.isDisabled;
linkCommand.isDisabled = () => {
if (superIsDisabled && superIsDisabled()) {
return true;
} else {
const selection = this.odooEditor.document.getSelection();
const range = selection.rangeCount && selection.getRangeAt(0);
return !!range && !!closestElement(range.startContainer, '[style*=background-image]');
}
}
}
return commands;
},
/**
* @override
*/
_updateEditorUI: function (e) {
this._super(...arguments);
// Hide the create-link button if the selection is within a
// background-image.
const selection = this.odooEditor.document.getSelection();
const range = selection.rangeCount && selection.getRangeAt(0);
const isWithinBackgroundImage = !!range && !!closestElement(range.startContainer, '[style*=background-image]');
if (isWithinBackgroundImage) {
this.toolbar.$el.find('#create-link').toggleClass('d-none', true);
}
},
});
return MassMailingWysiwyg;
......
......@@ -56,6 +56,9 @@ export class Powerbox {
clearTimeout(this._renderingTimeout);
this._hoverActive = false;
// Do not show disabled commands.
commands = commands.filter(command => !command.isDisabled || !command.isDisabled());
this._mainWrapperElement.classList.toggle('oe-commandbar-noResult', commands.length === 0);
if (commands.length === 0) {
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment