[FIX] web: form: the status bar must be present if in arch
Before this commit, when the status bar did not have buttons to display it was not displayed at all. After this commit, we display it even if there are not any button inside. Part-of: odoo/odoo#78221
This commit is contained in:
committed by
Géry Debongnie
parent
042e1a5c30
commit
8ca03fb6e3
@@ -356,23 +356,21 @@ export class FormCompiler extends ViewCompiler {
|
||||
buttons.push(compiled);
|
||||
}
|
||||
}
|
||||
if (buttons.length) {
|
||||
let slotId = 0;
|
||||
const statusBarButtons = createElement("StatusBarButtons");
|
||||
statusBarButtons.setAttribute("readonly", "!props.record.isInEdition");
|
||||
for (const button of buttons) {
|
||||
const slot = createElement("t", {
|
||||
"t-set-slot": `button_${slotId++}`,
|
||||
isVisible: button.getAttribute("t-if") || true,
|
||||
displayInReadOnly:
|
||||
button.hasAttribute("className") &&
|
||||
button.getAttribute("className").includes("oe_read_only"),
|
||||
});
|
||||
append(slot, button);
|
||||
append(statusBarButtons, slot);
|
||||
}
|
||||
append(statusBar, statusBarButtons);
|
||||
let slotId = 0;
|
||||
const statusBarButtons = createElement("StatusBarButtons");
|
||||
statusBarButtons.setAttribute("readonly", "!props.record.isInEdition");
|
||||
for (const button of buttons) {
|
||||
const slot = createElement("t", {
|
||||
"t-set-slot": `button_${slotId++}`,
|
||||
isVisible: button.getAttribute("t-if") || true,
|
||||
displayInReadOnly:
|
||||
button.hasAttribute("className") &&
|
||||
button.getAttribute("className").includes("oe_read_only"),
|
||||
});
|
||||
append(slot, button);
|
||||
append(statusBarButtons, slot);
|
||||
}
|
||||
append(statusBar, statusBarButtons);
|
||||
append(statusBar, others);
|
||||
return statusBar;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,13 @@ const { Component } = owl;
|
||||
|
||||
export class StatusBarButtons extends Component {
|
||||
get visibleSlotNames() {
|
||||
if (!this.props.slots) {
|
||||
return [];
|
||||
}
|
||||
return Object.entries(this.props.slots)
|
||||
.filter(
|
||||
(entry) => entry[1].isVisible && (entry[1].displayInReadOnly ? this.props.readonly : true)
|
||||
(entry) =>
|
||||
entry[1].isVisible && (entry[1].displayInReadOnly ? this.props.readonly : true)
|
||||
)
|
||||
.map((entry) => entry[0]);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ QUnit.module("Form Compiler", () => {
|
||||
const expected = /*xml*/ `
|
||||
<t>
|
||||
<div t-att-class="props.class" t-attf-class="{{props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}}" class="o_form_nosheet" t-ref="compiled_view_root">
|
||||
<div class="o_form_statusbar"/>
|
||||
<div class="o_form_statusbar"><StatusBarButtons readonly="!props.record.isInEdition"/></div>
|
||||
<div>someDiv</div>
|
||||
</div>
|
||||
</t>`;
|
||||
@@ -152,7 +152,7 @@ QUnit.module("Form Compiler", () => {
|
||||
<t>
|
||||
<div t-att-class="props.class" t-attf-class="{{props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}}" t-ref="compiled_view_root">
|
||||
<div class="o_form_sheet_bg">
|
||||
<div class="o_form_statusbar"/>
|
||||
<div class="o_form_statusbar"><StatusBarButtons readonly="!props.record.isInEdition"/></div>
|
||||
<div>someDiv</div>
|
||||
<div class="o_form_sheet">
|
||||
<div>inside sheet</div>
|
||||
@@ -204,6 +204,38 @@ QUnit.module("Form Compiler", () => {
|
||||
`;
|
||||
assert.areContentEquivalent(compileTemplate(arch), expected);
|
||||
});
|
||||
|
||||
QUnit.test("properly compile status bar with content", (assert) => {
|
||||
const arch = /*xml*/ `
|
||||
<form>
|
||||
<header><div>someDiv</div></header>
|
||||
</form>`;
|
||||
|
||||
const expected = /*xml*/ `
|
||||
<div class="o_form_statusbar">
|
||||
<StatusBarButtons readonly="!props.record.isInEdition">
|
||||
<t t-set-slot="button_0" isVisible="true" displayInReadOnly="false">
|
||||
<div>someDiv</div>
|
||||
</t>
|
||||
</StatusBarButtons>
|
||||
</div>`;
|
||||
|
||||
assert.areContentEquivalent(compileTemplate(arch), expected);
|
||||
});
|
||||
|
||||
QUnit.test("properly compile status bar without content", (assert) => {
|
||||
const arch = /*xml*/ `
|
||||
<form>
|
||||
<header></header>
|
||||
</form>`;
|
||||
|
||||
const expected = /*xml*/ `
|
||||
<div class="o_form_statusbar">
|
||||
<StatusBarButtons readonly="!props.record.isInEdition"/>
|
||||
</div>`;
|
||||
|
||||
assert.areContentEquivalent(compileTemplate(arch), expected);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.module("Form Renderer", (hooks) => {
|
||||
|
||||
@@ -293,6 +293,18 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.containsNone(target, "label.o_form_label_empty:contains(timmy)");
|
||||
});
|
||||
|
||||
QUnit.test("status bar rendering without buttons", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `<form><header/><sheet/></form>`,
|
||||
resId: 2,
|
||||
});
|
||||
|
||||
assert.containsOnce(target, ".o_form_sheet_bg > .o_form_statusbar > .o_statusbar_buttons");
|
||||
});
|
||||
|
||||
QUnit.test("duplicate fields rendered properly", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
|
||||
Reference in New Issue
Block a user