[FIX] web: missing t-attf-class part for ViewButtons

Before this commit
When defining a view button in some view arch, the combination of its
class attribute with a `t-attf-class` is not correctly handled.

After this commit
This is fixed.

Part-of: odoo/odoo#94952
This commit is contained in:
Bruno Boi
2022-07-05 17:32:51 +02:00
parent 0bef662b80
commit ebcecf74c6
3 changed files with 64 additions and 2 deletions
+3 -1
View File
@@ -82,7 +82,9 @@ export function combineAttributes(el, attr, parts, glue = " ") {
if (el.hasAttribute(attr)) {
allValues.push(el.getAttribute(attr));
}
allValues.push(...(Array.isArray(parts) ? parts : [parts]));
parts = Array.isArray(parts) ? parts : [parts];
parts = parts.filter((part) => !!part);
allValues.push(...parts);
el.setAttribute(attr, allValues.join(glue));
}
+6 -1
View File
@@ -345,7 +345,12 @@ export class ViewCompiler {
}
button.setAttribute("clickParams", JSON.stringify(clickParams));
button.setAttribute("className", toStringExpression(el.className));
combineAttributes(
button,
"className",
[toStringExpression(el.className), button.className],
"+` `+"
);
el.removeAttribute("class");
button.removeAttribute("class");
@@ -33,6 +33,7 @@ import { getNextTabableElement } from "@web/core/utils/ui";
import { session } from "@web/session";
import { KanbanAnimatedNumber } from "@web/views/kanban/kanban_animated_number";
import { kanbanView } from "@web/views/kanban/kanban_view";
import { ViewButton } from "@web/views/view_button/view_button";
import AbstractField from "web.AbstractField";
import legacyFieldRegistry from "web.field_registry";
import Widget from "web.Widget";
@@ -861,6 +862,60 @@ QUnit.module("Views", (hooks) => {
]);
});
QUnit.test("view button and string interpolated attribute in kanban", async (assert) => {
patchWithCleanup(ViewButton.prototype, {
setup() {
this._super();
assert.step(
`[${this.props.clickParams["name"]}] className: '${this.props.className}'`
);
},
});
await makeView({
type: "kanban",
resModel: "partner",
serverData,
arch: `
<kanban>
<field name="foo"/>
<templates>
<t t-name="kanban-box">
<div>
<a name="one" type="object" class="hola"/>
<a name="two" type="object" class="hola" t-attf-class="hello"/>
<a name="sri" type="object" class="hola" t-attf-class="{{record.foo.value}}"/>
<a name="foa" type="object" class="hola" t-attf-class="{{record.foo.value}} olleh"/>
<a name="fye" type="object" class="hola" t-attf-class="hello {{record.foo.value}}"/>
</div>
</t>
</templates>
</kanban>`,
});
assert.verifySteps([
"[one] className: 'hola oe_kanban_action oe_kanban_action_a'",
"[two] className: 'hola oe_kanban_action oe_kanban_action_a hello'",
"[sri] className: 'hola oe_kanban_action oe_kanban_action_a yop'",
"[foa] className: 'hola oe_kanban_action oe_kanban_action_a yop olleh'",
"[fye] className: 'hola oe_kanban_action oe_kanban_action_a hello yop'",
"[one] className: 'hola oe_kanban_action oe_kanban_action_a'",
"[two] className: 'hola oe_kanban_action oe_kanban_action_a hello'",
"[sri] className: 'hola oe_kanban_action oe_kanban_action_a blip'",
"[foa] className: 'hola oe_kanban_action oe_kanban_action_a blip olleh'",
"[fye] className: 'hola oe_kanban_action oe_kanban_action_a hello blip'",
"[one] className: 'hola oe_kanban_action oe_kanban_action_a'",
"[two] className: 'hola oe_kanban_action oe_kanban_action_a hello'",
"[sri] className: 'hola oe_kanban_action oe_kanban_action_a gnap'",
"[foa] className: 'hola oe_kanban_action oe_kanban_action_a gnap olleh'",
"[fye] className: 'hola oe_kanban_action oe_kanban_action_a hello gnap'",
"[one] className: 'hola oe_kanban_action oe_kanban_action_a'",
"[two] className: 'hola oe_kanban_action oe_kanban_action_a hello'",
"[sri] className: 'hola oe_kanban_action oe_kanban_action_a blip'",
"[foa] className: 'hola oe_kanban_action oe_kanban_action_a blip olleh'",
"[fye] className: 'hola oe_kanban_action oe_kanban_action_a hello blip'",
]);
});
QUnit.test("kanban with kanban-tooltip template", async (assert) => {
serviceRegistry.add("tooltip", tooltipService);
let simulateTimeout;