diff options
| author | Benjamin Vray <bvr@odoo.com> | 2020-11-23 14:46:45 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2021-01-27 15:10:51 +0000 |
| commit | b7d522e9e7e31ac6bf926aae65e58d9f6cfa8903 (patch) | |
| tree | 768d89f1311bc648ccccb04c72bfe8bb2ea5c5df | |
| parent | edf28efe19bedfe5eb62baf6fa5832a50d18e775 (diff) | |
[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) <qsm@odoo.com>
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.editor.js | 14 |
1 files changed, 12 insertions, 2 deletions
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); }, /** |
