From dafdfba6efb8ab5920a5e5ba70ba32cc7fcb07a3 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Tue, 10 May 2022 15:29:49 +0200 Subject: [PATCH] [IMP] website, web_editor: re-introduce cancel dialog The cancel dialog is now using the new Dialog API and disables buttons when the process is ongoing. This is needed because prior to this commit, the iframe would reload, but it would still be possible to click on the buttons. So one could cancel then click on save and a traceback would show up. See merge commit for more information. task-2687506 --- .../static/src/js/editor/snippets.editor.js | 14 ++++++++++---- .../components/wysiwyg_adapter/wysiwyg_adapter.js | 12 +++++++++++- 2 files changed, 21 insertions(+), 5 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 ab5b0fa07fe..3f936297eff 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -3406,11 +3406,11 @@ var SnippetsMenu = Widget.extend({ * On click on discard button. */ _onDiscardClick: function () { - this._buttonClick(() => { + this._buttonClick(after => { this.snippetEditors.forEach(editor => { editor.toggleOverlay(false); }); - this.trigger_up('request_cancel'); + this.trigger_up('request_cancel', {onReject: after}); }, this.$el[0].querySelector('button[data-action=cancel]')); }, /** @@ -3465,12 +3465,18 @@ var SnippetsMenu = Widget.extend({ return; } this._buttonAction = true; - dom.addButtonLoadingEffect(button); + const removeLoadingEffect = dom.addButtonLoadingEffect(button); const actionButtons = this.$el[0].querySelectorAll('[data-action]'); for (const actionButton of actionButtons) { actionButton.disabled = true; } - await action(); + const after = () => { + removeLoadingEffect(); + for (const actionButton of actionButtons) { + actionButton.disabled = false; + } + }; + await action(after); this._buttonAction = false; }, diff --git a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js index f449c14fa79..a568713f721 100644 --- a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js +++ b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js @@ -7,6 +7,7 @@ import { useWowlService } from '@web/legacy/utils'; import { useHotkey } from '@web/core/hotkeys/hotkey_hook'; import { EditMenuDialog, MenuDialog } from "../dialog/edit_menu"; +import { WebsiteDialog } from '../dialog/dialog'; import { PageOption } from "./page_options"; const { onWillStart, useEffect } = owl; @@ -559,7 +560,16 @@ export class WysiwygAdapterComponent extends ComponentAdapter { * @private */ _onCancelRequest(event) { - return this.props.quitCallback(); + const isDirty = this.widget.isDirty(); + if (isDirty) { + this.dialogs.add(WebsiteDialog, { + body: _t("If you discard the current edits, all unsaved changes will be lost. You can cancel to return to edit mode."), + primaryClick: () => this.props.quitCallback(), + secondaryClick: event.data.onReject, + }); + } else { + return this.props.quitCallback(); + } } /*** * Starts the widgets inside the dropped snippet.