From e2a6471e52e6d870745591abec467f43c65fe2ad Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Thu, 16 Mar 2023 14:02:43 +0000 Subject: [PATCH] [FIX] web: introduce all the clickParams in list view buttons **ISSUE** A header button in the list view with "confirm" attribute doesn't show a confirmation dialog when clicked. This is different to the header buttons from the form view. **SOLUTION** In order to achieve similar behaviour, we reuse the BUTTON_CLICK_PARAMS which originated from thew view_compiler and make sure that buttons parsed from the other views also contain the correct set of clickParams. closes odoo/odoo#115974 Task-id: 3216357 X-original-commit: d91eac84ddafe1338470e73ba9921ddcbcac0e80 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Joseph Caburnay (jcb) --- addons/web/static/src/views/utils.js | 38 ++++++++++++++++--- addons/web/static/src/views/view_compiler.js | 22 +---------- .../web/static/tests/views/list_view_tests.js | 31 +++++++++++++++ 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/addons/web/static/src/views/utils.js b/addons/web/static/src/views/utils.js index 87a75bd15a4..fa12473b96d 100644 --- a/addons/web/static/src/views/utils.js +++ b/addons/web/static/src/views/utils.js @@ -18,6 +18,27 @@ const NUMERIC_TYPES = ["integer", "float", "monetary"]; * @property {boolean} duplicate */ +export const BUTTON_CLICK_PARAMS = [ + "name", + "type", + "args", + "context", + "close", + "confirm", + "confirm-title", + "confirm-label", + "special", + "effect", + "help", + "modifiers", + // WOWL SAD: is adding the support for debounce attribute here justified or should we + // just override compileButton in kanban compiler to add the debounce? + "debounce", + // WOWL JPP: is adding the support for not oppening the dialog of confirmation in the settings view + // This should be refactor someday + "noSaveDialog", +]; + /** * Add dependencies to activeFields * @@ -204,6 +225,16 @@ export function isNull(value) { } export function processButton(node) { + const withDefault = { + close: (val) => archParseBoolean(val, false), + context: (val) => val || "{}", + }; + const clickParams = {}; + for (const { name, value } of node.attributes) { + if (BUTTON_CLICK_PARAMS.includes(name)) { + clickParams[name] = withDefault[name] ? withDefault[name](value) : value; + } + } return { className: node.getAttribute("class") || "", disabled: !!node.getAttribute("disabled") || false, @@ -213,12 +244,7 @@ export function processButton(node) { options: JSON.parse(node.getAttribute("options") || "{}"), modifiers: JSON.parse(node.getAttribute("modifiers") || "{}"), display: node.getAttribute("display") || "selection", - clickParams: { - close: archParseBoolean(node.getAttribute("close"), false), - context: node.getAttribute("context") || "{}", - name: node.getAttribute("name"), - type: node.getAttribute("type"), - }, + clickParams, }; } diff --git a/addons/web/static/src/views/view_compiler.js b/addons/web/static/src/views/view_compiler.js index 8b4cbf11544..78878e20511 100644 --- a/addons/web/static/src/views/view_compiler.js +++ b/addons/web/static/src/views/view_compiler.js @@ -7,7 +7,7 @@ import { createTextNode, getTag, } from "@web/core/utils/xml"; -import { toStringExpression } from "./utils"; +import { toStringExpression, BUTTON_CLICK_PARAMS } from "./utils"; /** * @typedef Compiler @@ -18,26 +18,6 @@ import { toStringExpression } from "./utils"; import { xml } from "@odoo/owl"; -const BUTTON_CLICK_PARAMS = [ - "name", - "type", - "args", - "context", - "close", - "confirm", - "confirm-title", - "confirm-label", - "special", - "effect", - "help", - "modifiers", - // WOWL SAD: is adding the support for debounce attribute here justified or should we - // just override compileButton in kanban compiler to add the debounce? - "debounce", - // WOWL JPP: is adding the support for not oppening the dialog of confirmation in the settings view - // This should be refactor someday - "noSaveDialog", -]; const BUTTON_STRING_PROPS = ["string", "size", "title", "icon", "id"]; const INTERP_REGEXP = /(\{\{|#\{)(.*?)(\}{1,2})/g; diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 58c49bb4ac1..f0e9fd629a8 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -18165,4 +18165,35 @@ QUnit.module("Views", (hooks) => { assert.containsNone(target, ".o_optional_columns_dropdown_toggle"); assert.verifySteps(["get_views", "web_search_read"]); }); + + QUnit.test("header buttons in list view", async function (assert) { + await makeView({ + type: "list", + resModel: "foo", + serverData, + arch: ` + +
+
+ + +
`, + + mockRPC: async (route, args) => { + if (route === "/web/dataset/call_button") { + assert.step(args.method); + return true; + } + }, + }); + await click(target.querySelector(".o_data_row .o_list_record_selector input")); + const cpButtons = getButtons(target); + await click(cpButtons[0].querySelector('button[name="a"]')); + assert.containsOnce(document.body, ".modal"); + const modalText = target.querySelector(".modal-body").textContent; + assert.strictEqual(modalText, "Are you sure?"); + await click(document, "body .modal footer button.btn-primary"); + assert.verifySteps(["a"]); + }); });