diff --git a/addons/website/static/src/components/dialog/dialog.js b/addons/website/static/src/components/dialog/dialog.js index c7882550024..12ce4e9ec66 100644 --- a/addons/website/static/src/components/dialog/dialog.js +++ b/addons/website/static/src/components/dialog/dialog.js @@ -10,21 +10,33 @@ const { xml, useState, Component } = owl; const NO_OP = () => {}; export class WebsiteDialog extends Component { - async primaryClick() { - if (this.props.primaryClick) { - await this.props.primaryClick(); - } - if (this.props.closeOnClick) { - this.props.close(); - } + setup() { + this.state = useState({ + disabled: false, + }); } - - async secondaryClick() { - if (this.props.secondaryClick) { - await this.props.secondaryClick(); - } - if (this.props.closeOnClick) { - this.props.close(); + /** + * Disables the buttons of the dialog when a click is made. + * If a handler is provided, await for its call. + * If the prop closeOnClick is true, close the dialog. + * Otherwise, restore the button. + * + * @param handler {function|void} The handler to protect. + * @returns {function(): Promise} handler called when a click is made. + */ + protectedClick(handler) { + return async () => { + if (this.state.disabled) { + return; + } + this.state.disabled = true; + if (handler) { + await handler(); + } + if (this.props.closeOnClick) { + return this.props.close(); + } + this.state.disabled = false; } } diff --git a/addons/website/static/src/components/dialog/dialog.xml b/addons/website/static/src/components/dialog/dialog.xml index 56d35248985..06cb202f7b1 100644 --- a/addons/website/static/src/components/dialog/dialog.xml +++ b/addons/website/static/src/components/dialog/dialog.xml @@ -11,10 +11,10 @@ - - diff --git a/addons/website/static/tests/tours/edit_menus.js b/addons/website/static/tests/tours/edit_menus.js index 723f6a39ffd..5e9b6faf2b6 100644 --- a/addons/website/static/tests/tours/edit_menus.js +++ b/addons/website/static/tests/tours/edit_menus.js @@ -59,6 +59,7 @@ wTourUtils.registerEditionTour('edit_menus', { }, { content: "Confirm the new menu entry without a label", + extra_trigger: '.modal-dialog .o_website_dialog input:eq(0)', trigger: '.modal-footer .btn-primary', }, { @@ -74,6 +75,7 @@ wTourUtils.registerEditionTour('edit_menus', { { content: "It didn't save without a url. Fill url input.", trigger: '.modal-dialog .o_website_dialog input:eq(1)', + extra_trigger: '.modal-dialog .o_website_dialog input.is-invalid', run: 'text #', }, {