{#- A JSON column drawn as a form from its schema. `row.document` holds the parts: a single value is drawn like any other field, an object's properties sit under its title, and a list of objects or a map is a table whose rows can be added and removed. Form and JSON switch between the form and the document it stands for, as Save would write it. Every input's name says where its value sits in the document, so the form is sent like any other: settings.free_shipping_over, settings.channels.0.id. -#} {% import "adminsite/_icons.html" as icons %} {%- set document = row.document -%} {%- set json_id = "json-" ~ row.path -%} {%- macro value_part(entry) -%} {%- set row = entry.row -%} {% include "adminsite/_field.html" %} {%- endmacro -%} {#- One line of a table: a cell for each value, then its remove button. The first cell carries the row's marker, so a row whose inputs are all empty is still sent, and read as a row left unused. -#} {%- macro table_row(item, counted) -%} {% for cell in item.cells %} {% if loop.first %}{% endif %} {%- set row = cell -%} {%- set note_id = cell.input_id ~ "-note" -%} {%- set field_attrs -%}aria-label="{{ cell.label }}"{% if cell.error %} aria-invalid="true" aria-describedby="{{ note_id }}"{% endif %}{%- endset -%} {% include ["adminsite/widgets/" ~ cell.widget ~ ".html", "adminsite/widgets/input.html"] %} {% if cell.error %}

{{ icons.icon("alert", 14) }}{{ cell.error }}

{% endif %} {% endfor %} {%- endmacro -%} {#- A list of objects, or a map: a table, with a button that copies the blank row in under the next free number. -#} {%- macro table_part(entry) -%} {%- set pairs = entry.kind == "pairs" -%}
{% if entry.label %} {{ entry.label }} {% endif %}
{% if pairs %} {% else %} {% for column in entry.columns %} {% endfor %} {% endif %} {% for item in entry.rows %}{{ table_row(item, pairs) }}{% endfor %}
{{ _('Key') }} {{ _('Value') }} {{ column.label }}{% if not column.field.required and column.widget != "checkbox" %} {{ _('(optional)') }}{% endif %} {{ _('Remove') }}
{% if pairs and entry.key_count %} {{ _('Each key has a row.') }} {% endif %}
{#- The row "add" copies. Inside a template its inputs are never sent. -#} {% if entry.error %}

{{ icons.icon("alert", 14) }}{{ entry.error }}

{% elif entry.note %}

{{ entry.note }}

{% endif %}
{%- endmacro -%} {#- An object inside the document: its properties under its title. -#} {%- macro group_part(entry) -%}
{{ entry.label }} {% if entry.error %}

{{ icons.icon("alert", 14) }}{{ entry.error }}

{% elif entry.note %}

{{ entry.note }}

{% endif %}
{{ parts(entry.entries) }}
{%- endmacro -%} {%- macro part(entry) -%} {%- if entry.kind == "group" -%}{{ group_part(entry) }} {%- elif entry.kind in ("rows", "pairs") -%}{{ table_part(entry) }} {%- elif entry.row is not none -%}{{ value_part(entry) }} {%- endif -%} {%- endmacro -%} {#- A property that may be left out of the document. Unset, its inputs sit in a disabled fieldset, so none of them is sent, and it reads Not set. -#} {%- macro settable_part(entry) -%}
{{ part(entry) }}
{{ entry.label }} {{ _('Not set') }}
{%- endmacro -%} {%- macro parts(entries) -%}
{% for entry in entries %} {% if entry.settable %}{{ settable_part(entry) }}{% else %}{{ part(entry) }}{% endif %} {% endfor %}
{%- endmacro -%} {#- The Form and JSON switch sits in the field's own title line. -#}
{%- if document.kind == "group" -%}
{{ parts(document.entries) }}
{%- else -%}
{{ part(document) }}
{%- endif -%}

{{ _('Reading the form…') }}

{{ _('What Save writes. Switch back to Form to change it.') }}