{#- 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 field that may be left out of the document, drawn only while it is set. Unset, it is hidden and its inputs sit in a disabled fieldset, so none of them is sent; the box under the document adds it back, in its own place. -#} {%- macro settable_part(entry) -%}
{{ part(entry) }}
{%- endmacro -%} {%- macro parts(entries) -%}
{% for entry in entries %} {% if entry.settable %}{{ settable_part(entry) }}{% else %}{{ part(entry) }}{% endif %} {% endfor %}
{%- endmacro -%} {#- A document whose fields may each be left unset: the fields that are set, then a box that adds one of the others. The box is a picker whose list is the fields left out, in the schema's order, each with its description, and whose choices are the fields that are set. -#} {%- macro partial_parts(entries, name) -%} {%- set settable = entries|selectattr("settable")|list -%} {%- set held = namespace(items=[]) -%} {%- for entry in settable if entry.is_set -%} {%- set held.items = held.items + [{"value": entry.name, "label": entry.label}] -%} {%- endfor -%} {%- set list_id = "unset-" ~ name|replace(".", "-") -%}
{{ parts(entries) }}

{{ _('Nothing set.') }}

{#- A press anywhere in the box goes to the text in it, as in any input. -#}
{{ icons.icon("plus", 16) }}
    {% for entry in settable %} {#- Found by its description as well as its name. -#}
  • {{ entry.label }} {% if entry.note %}{{ entry.note }}{% endif %}
  • {% endfor %}

{{ _('Nothing found.') }}

{%- endmacro -%} {#- The Form and JSON switch sits in the field's own title line. -#}
{%- if document.kind == "group" and document.entries|selectattr("settable")|first -%} {{ partial_parts(document.entries, row.path) }} {%- elif document.kind == "group" -%}
{{ parts(document.entries) }}
{%- else -%}
{{ part(document) }}
{%- endif -%}

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

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