From 9d8803f6baba14448ef2dc81ce0132c563a94d45 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 20 Sep 2021 09:46:33 +0000 Subject: [PATCH] [IMP] web_editor: allow onRemove to be async Now, a snippet option can do async operations in its onRemove implementation. task-2636545 X-original-commit: ef2e55d7f407dedfbf724f2cae32a0fcaede6890 Part-of: odoo/odoo#77256 --- addons/web_editor/static/src/js/editor/snippets.editor.js | 4 ++-- addons/web_editor/static/src/js/editor/snippets.options.js | 3 ++- 2 files changed, 4 insertions(+), 3 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 7f51ee7749d..8ea0ddfb647 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -451,9 +451,9 @@ var SnippetEditor = Widget.extend({ await new Promise(resolve => { this.trigger_up('call_for_each_child_snippet', { $snippet: this.$target, - callback: function (editor, $snippet) { + callback: async function (editor, $snippet) { for (var i in editor.styles) { - editor.styles[i].onRemove(); + await editor.styles[i].onRemove(); } }, onSuccess: resolve, diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 02a911c15d0..bbe193c813e 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -2950,8 +2950,9 @@ const SnippetOptionWidget = Widget.extend({ * Called when the associated snippet is about to be removed from the DOM. * * @abstract + * @returns {Promise|undefined} */ - onRemove: function () {}, + onRemove: async function () {}, /** * Called when the target is shown, only meaningful if the target was hidden * at some point (typically used for 'invisible' snippets).