{%- import "apostrophe-ui:components/fields.html" as commonFields with context -%} {%- macro fields(fields, options = {}) -%} {%- set groups = apos.schemas.toGroups(fields) -%}
{%- if options.tabs != false -%}
{%- if groups.length > 1 -%} {%- for group in groups -%} {%- if group.fields.length -%}
{{ __(group.label | d('')) }}
{%- endif -%} {%- endfor -%} {%- endif -%}
{%- endif -%}
{%- for group in groups -%} {%- if group.fields.length -%}
{%- for field in group.fields -%} {%- if not field.contextual -%} {{ apos.schemas.field(field, options.readOnly) }} {%- endif -%} {%- endfor -%}
{%- endif -%} {%- endfor -%}
{%- endmacro -%} {# Output a fieldset for the given field, and call the given #} {# macro to populate it. Usually not called directly #} {%- macro fieldset(field, bodyMacro) %} {# WARNING: if you remove apos-field as a class you will have problems with nested schemas reusing #} {# field names. We use this class with our $.findSafe plugin. #} {% set options = { 'id': apos.utils.generateId() } %}
{%- if field.help -%}
{{ __(field.help) }}
{%- endif -%} {{ bodyMacro(field, options) }}
{#
{{ bodyMacro(field) }}
#} {%- endmacro -%} {# This is used directly to output a text field #} {%- macro string(field) -%} {{ fieldset(field, stringBody) }} {%- endmacro -%} {# Usually passed to fieldset() by text(), this can also be called #} {# directly if you don't want the fieldset #} {%- macro stringBody(field, options) -%} {%- if field.textarea -%} {{ commonFields.textarea(field.name, field.placeholder, field.readOnly, options) }} {%- else -%} {{ commonFields.string(field.name, field.placeholder, '', field.readOnly, options) }} {%- endif -%} {%- endmacro -%} {%- macro integer(field) -%} {{ fieldset(field, stringBody) }} {%- endmacro -%} {%- macro float(field) -%} {{ fieldset(field, stringBody) }} {%- endmacro -%} {%- macro slug(field) -%} {{ fieldset(field, stringBody) }} {%- endmacro -%} {%- macro password(field) -%} {{ fieldset(field, passwordBody) }} {%- endmacro -%} {%- macro passwordBody(field, options) -%} {%- endmacro -%} {%- macro tags(field) -%} {{ fieldset(field, tagsBody) }} {%- endmacro -%} {%- macro tagsBody(field, options) -%} {# Always using this wrapper div makes it easy to use this with #} {# selective, and in both standalone and fieldset situations. -Tom #}
{# Text entry for autocompleting the next item #} {% if not field.readOnly %} {{ __('Limit Reached!') }} {{ __("Add") }} {% endif %}
{%- endmacro -%} {# Maybe fancier later #} {%- macro email(field) -%} {{ fieldset(field, stringBody) }} {%- endmacro -%} {# Typically we enhance this with jquery ui datepicker later #} {%- macro date(field) -%} {{ fieldset(field, stringBody) }} {%- endmacro -%} {%- macro time(field) -%} {{ fieldset(field, stringBody) }} {%- endmacro -%} {%- macro checkboxes(field) -%} {{ fieldset(field, checkboxesBody) }} {%- endmacro -%} {%- macro checkboxesBody(field) -%} {%- for choice in field.choices -%}
{%- endfor -%} {%- endmacro -%} {# // If you need to include extra fields on a select option // format a JSON string in 'data-extra' like this: // // // // Also see the showFields case below in the formSelectStandalone macro. // -matt #} {%- macro select(field) -%} {%- set selectMultiple = ' apos-fieldset-selectize' if field.selectMultiple else '' -%} {% set selectFields = ' apos-fieldset-select-show-fields' if apos.utils.containsProperty(field.choices, 'showFields') else '' %} {{ fieldset(field | merge({ classes: selectMultiple + selectFields }), selectBody) }} {%- endmacro -%} {# Often used directly in a custom fieldset with other controls #} {%- macro selectBody(field) -%} {{ commonFields.select(field.name, field.choices, '', field.readOnly) }} {%- endmacro -%} {# Less ambiguous to work with than a checkbox #} {%- macro boolean(field) -%} {% set selectFields = ' apos-fieldset-select-show-fields' if apos.utils.containsProperty(field.choices, 'showFields') else '' %} {{ fieldset(field | merge({ classes: selectMultiple }), booleanBody) }} {%- endmacro -%} {% macro booleanBody(field) %} {{ selectBody(field | merge({ choices: [ { value: '1', label: __('Yes') }, { value: '0', label: __('No') }] })) }} {%- endmacro -%} {%- macro array(field) -%}
{#- Cannot be inside the sortable div -#}
{{ __("Edit %s", __(field.label | d(''))) }}
{%- endmacro -%} {%- macro singleton(field) -%} {{ fieldset(field, singletonBody) }} {%- endmacro -%} {%- macro singletonBody(field) -%} {# js adds this singleton to the dialog #}
{%- endmacro -%} {%- macro area(field) -%} {{ fieldset(field | merge({ attributes: 'data-editable' }), singletonBody) }} {%- endmacro -%} {%- macro areaBody(field) -%} {# js adds this area to the dialog #}
{%- endmacro -%} {# Currently the join editors can use the same markup, so we have one #} {# body macro. -Tom #} {%- macro joinByOne(field) -%} {{ fieldset(field, joinBody) }} {%- endmacro -%} {%- macro joinByArray(field) -%} {{ fieldset(field, joinBody) }} {%- endmacro -%} {# ajax populates joins, see apostrophe-docs/views/chooser.html #} {%- macro joinBody(field) -%}
{# ajax populates me #}
{%- endmacro -%} {%- macro object(field) -%}
{% for item in field.schema %} {{ apos.schemas.field(item, field.readOnly) }} {% endfor %}
{%- endmacro -%}