[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) <aab@odoo.com> Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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: `
|
||||
<tree>
|
||||
<header>
|
||||
<button name="a" type="object" string="Confirm" confirm="Are you sure?" />
|
||||
</header>
|
||||
<field name="foo"/>
|
||||
<field name="bar" />
|
||||
</tree>`,
|
||||
|
||||
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"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user