[FIX] web_editor: prevent inline snippet drop in non-inline area
Before this commit, it was possible to drop an inline snippet (e.g. badge, cards, etc.) next to a section when this section was a snippet which can be dropped as main snippets or as inline snippets (e.g. countdown, embed code, etc.). task-2648348 closes odoo/odoo#78483 X-original-commit: e2f218fbb3d9bab9dba380582aa93e80fa9becc1 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -1927,8 +1927,11 @@ var SnippetsMenu = Widget.extend({
|
||||
* when the DOM elements must be in an editable environment to be
|
||||
* considered (@see noCheck), this is true if the DOM elements'
|
||||
* parent must also be in an editable environment to be considered.
|
||||
* @param {string} excludeParent
|
||||
* jQuery selector that the parents of DOM elements must *not* match
|
||||
* to be considered as potential snippet.
|
||||
*/
|
||||
_computeSelectorFunctions: function (selector, exclude, target, noCheck, isChildren) {
|
||||
_computeSelectorFunctions: function (selector, exclude, target, noCheck, isChildren, excludeParent) {
|
||||
var self = this;
|
||||
|
||||
exclude += `${exclude && ', '}.o_snippet_not_selectable`;
|
||||
@@ -1942,6 +1945,12 @@ var SnippetsMenu = Widget.extend({
|
||||
return oldFilter.apply(this) && $(this).find(target).length !== 0;
|
||||
};
|
||||
}
|
||||
if (excludeParent) {
|
||||
const oldFilter = filterFunc;
|
||||
filterFunc = function () {
|
||||
return oldFilter.apply(this) && !$(this).parent().is(excludeParent);
|
||||
};
|
||||
}
|
||||
|
||||
// Prepare the functions
|
||||
var functions = {
|
||||
@@ -1994,10 +2003,12 @@ var SnippetsMenu = Widget.extend({
|
||||
this.templateOptions = [];
|
||||
var selectors = [];
|
||||
var $styles = $html.find('[data-selector]');
|
||||
const snippetAdditionDropIn = $styles.filter('#so_snippet_addition').data('drop-in');
|
||||
$styles.each(function () {
|
||||
var $style = $(this);
|
||||
var selector = $style.data('selector');
|
||||
var exclude = $style.data('exclude') || '';
|
||||
const excludeParent = $style.attr('id') === "so_content_addition" ? snippetAdditionDropIn : '';
|
||||
var target = $style.data('target');
|
||||
var noCheck = $style.data('no-check');
|
||||
var optionID = $style.data('js') || $style.data('option-name'); // used in tour js as selector
|
||||
@@ -2008,7 +2019,7 @@ var SnippetsMenu = Widget.extend({
|
||||
'base_target': target,
|
||||
'selector': self._computeSelectorFunctions(selector, exclude, target, noCheck),
|
||||
'$el': $style,
|
||||
'drop-near': $style.data('drop-near') && self._computeSelectorFunctions($style.data('drop-near'), '', false, noCheck, true),
|
||||
'drop-near': $style.data('drop-near') && self._computeSelectorFunctions($style.data('drop-near'), '', false, noCheck, true, excludeParent),
|
||||
'drop-in': $style.data('drop-in') && self._computeSelectorFunctions($style.data('drop-in'), '', false, noCheck),
|
||||
'data': _.extend({string: $style.attr('string')}, $style.data()),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user