From b7d522e9e7e31ac6bf926aae65e58d9f6cfa8903 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Mon, 23 Nov 2020 14:46:45 +0000 Subject: [FIX] web_editor: prevent a modal from closing when dropping a snippet Before this commit, when you dropped a snippet using the move button in a modal. The modal closed after the drop. This commit allows to define an element in which to destroy the editors. Part of https://github.com/odoo/odoo/pull/61998 task-2312878 closes odoo/odoo#61998 Signed-off-by: Quentin Smetz (qsm) --- addons/web_editor/static/src/js/editor/snippets.editor.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'addons/web_editor/static/src/js/editor') diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index a67f45b3dc0..4e151f29546 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1521,9 +1521,15 @@ var SnippetsMenu = Widget.extend({ }, /** * @private + * @param {jQuery|null|undefined} [$el] + * The DOM element whose inside editors need to be destroyed. + * If no element is given, all the editors are destroyed. */ - _destroyEditors: async function () { + _destroyEditors: async function ($el) { const proms = _.map(this.snippetEditors, async function (snippetEditor) { + if ($el && !$el.has(snippetEditor.$target).length) { + return; + } await snippetEditor.cleanForSave(); snippetEditor.destroy(); }); @@ -2291,7 +2297,11 @@ var SnippetsMenu = Widget.extend({ * @param {OdooEvent} ev */ _onDragAndDropStop: async function (ev) { - await this._destroyEditors(); + const $modal = ev.data.$snippet.closest('.modal'); + // If the snippet is in a modal, destroy editors only in that modal. + // This to prevent the modal from closing because of the cleanForSave + // on each editors. + await this._destroyEditors($modal.length ? $modal : null); await this._activateSnippet(ev.data.$snippet); }, /** -- cgit v1.2.3