From 5cee846bb28625121d04ac789f6539a75c919e95 Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Thu, 15 Sep 2022 13:55:03 +0000 Subject: [PATCH] [REF] web: formGroups: improve extensibility X-original-commit: 9f64da010ef74848a3e4dd6b2c6d99365a0312c2 Part-of: odoo/odoo#102153 --- addons/web/static/src/views/fields/field.js | 2 +- .../src/views/form/form_group/form_group.js | 22 +++++++++++---- .../src/views/form/form_group/form_group.xml | 28 +++++++++++-------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/addons/web/static/src/views/fields/field.js b/addons/web/static/src/views/fields/field.js index 35a5ae7d361..d706ee1ca2e 100644 --- a/addons/web/static/src/views/fields/field.js +++ b/addons/web/static/src/views/fields/field.js @@ -56,7 +56,7 @@ function getFieldClassFromRegistry(fieldType, widget, viewType, jsClass) { export function fieldVisualFeedback(FieldComponent, record, fieldName, fieldInfo) { const modifiers = fieldInfo.modifiers || {}; const readonly = evalDomain(modifiers.readonly, record.evalContext); - const inEdit = record.mode !== "readonly"; + const inEdit = record.isInEdition; let empty = !record.isVirtual; if ("isEmpty" in FieldComponent) { diff --git a/addons/web/static/src/views/form/form_group/form_group.js b/addons/web/static/src/views/form/form_group/form_group.js index 3ba011a489b..c6f65229ecf 100644 --- a/addons/web/static/src/views/form/form_group/form_group.js +++ b/addons/web/static/src/views/form/form_group/form_group.js @@ -2,11 +2,15 @@ import { sortBy } from "@web/core/utils/arrays"; class Group extends owl.Component { - getItems() { - const items = Object.entries(this.props.slots).filter(([k, v]) => v.type === "item"); + _getItems() { + const items = Object.entries(this.props.slots || {}).filter(([k, v]) => v.type === "item"); return sortBy(items, (i) => i[1].sequence); } + getItems() { + return this._getItems(); + } + get allClasses() { return this.props.class; } @@ -26,7 +30,12 @@ export class OuterGroup extends Group { return items.map((item) => { const [slotName, slot] = item; const itemSpan = slot.itemSpan || 1; - return { name: slotName, size: itemSpan * colSize, newline: slot.newline, colspan: itemSpan }; + return { + name: slotName, + size: itemSpan * colSize, + newline: slot.newline, + colspan: itemSpan, + }; }); } } @@ -38,6 +47,9 @@ OuterGroup.defaultProps = { }; export class InnerGroup extends Group { + getTemplate(subType) { + return this.constructor.templates[subType] || this.constructor.templates.default; + } getRows() { const maxCols = this.props.maxCols; @@ -49,7 +61,7 @@ export class InnerGroup extends Group { const items = this.getItems(); while (items.length) { const [slotName, slot] = items.shift(); - const { newline, itemSpan, subType, Component, props } = slot; + const { newline, itemSpan } = slot; if (newline) { rows.push(currentRow); currentRow = []; @@ -65,7 +77,7 @@ export class InnerGroup extends Group { } const isVisible = !("isVisible" in slot) || slot.isVisible; - currentRow.push({ name: slotName, subType, itemSpan, props, isVisible, Component }); + currentRow.push({ ...slot, name: slotName, itemSpan, isVisible }); reservedSpace += itemSpan || 1; // Allows to remove the line if the content is not visible instead of leaving an empty line. diff --git a/addons/web/static/src/views/form/form_group/form_group.xml b/addons/web/static/src/views/form/form_group/form_group.xml index 053607f105e..16311ad0caf 100644 --- a/addons/web/static/src/views/form/form_group/form_group.xml +++ b/addons/web/static/src/views/form/form_group/form_group.xml @@ -3,7 +3,7 @@
- + @@ -12,23 +12,15 @@ -
-
+
+
-
- -
-
- -
+ @@ -46,4 +38,16 @@
+ +
+ +
+
+ +
+
+