diff --git a/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js b/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js index d4a31a890f4..0a70b60e046 100644 --- a/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js +++ b/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js @@ -20,26 +20,30 @@ export class SettingsFormController extends formView.Controller { ) { const message = this.env._t("Would you like to save your changes?"); await new Promise((resolve) => { - this.dialogService.add( - SettingsConfirmationDialog, - { - body: message, - confirm: async () => { - await this.model.root.save({ stayInEdition: true }); - await this.save(); - }, - cancel: () => {}, - stayHere: () => { - _continue = false; - }, + this.dialogService.add(SettingsConfirmationDialog, { + body: message, + confirm: async () => { + await this.model.root.save({ stayInEdition: true }); + await this.save(); + // It doesn't make sense to do the action of the button + // as the res.config.settings `execute` method will trigger a reload. + _continue = false; + resolve(); }, - { onClose: resolve } - ); + cancel: async () => { + await this.model.root.discard(); + await this.model.root.save({ stayInEdition: true }); + _continue = true; + resolve(); + }, + stayHere: () => { + _continue = false; + resolve(); + }, + }); }); } else { - if (clickParams.name === "execute") { - _continue = await this.model.root.save({ stayInEdition: true }); - } + _continue = await this.model.root.save({ stayInEdition: true }); } return _continue; }; diff --git a/addons/web/static/tests/webclient/settings_form_view_tests.js b/addons/web/static/tests/webclient/settings_form_view_tests.js index a8847e7e300..1e94ef00605 100644 --- a/addons/web/static/tests/webclient/settings_form_view_tests.js +++ b/addons/web/static/tests/webclient/settings_form_view_tests.js @@ -11,6 +11,7 @@ import { import { editSearch } from "@web/../tests/search/helpers"; import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; import { createWebClient, doAction } from "@web/../tests/webclient/helpers"; +import { registry } from "@web/core/registry"; let target; let serverData; @@ -307,7 +308,7 @@ QUnit.module("SettingsFormView", (hooks) => { QUnit.test( "settings views does not read existing id when coming back in breadcrumbs", async function (assert) { - assert.expect(9); + assert.expect(11); serverData.actions = { 1: { @@ -373,7 +374,9 @@ QUnit.module("SettingsFormView", (hooks) => { assert.notOk(target.querySelector(".o_field_boolean input").disabled); assert.verifySteps([ "get_views", // initial setting action - "onchange", // this is a setting view => create new record + "onchange", // this is a setting view => new record transient record + "create", // create the record before doing the action + "read", // read the created record "get_views", // for other action in breadcrumb, "web_search_read", // with a searchread "onchange", // when we come back, we want to restart from scratch @@ -647,6 +650,84 @@ QUnit.module("SettingsFormView", (hooks) => { } ); + QUnit.test("clicking a button with dirty settings -- save", async (assert) => { + registry.category("services").add( + "action", + { + start() { + return { + doActionButton(params) { + assert.step(`action executed ${JSON.stringify(params)}`); + }, + }; + }, + }, + { force: true } + ); + await makeView({ + type: "form", + arch: ` +
+ +