{# Eingabefelder je Fragetyp. Die Prüfung macht immer der Server. #} {% macro required_mark(q) %}{% if q.required %}{% endif %}{% endmacro %} {% macro describedby(name, q, err) -%} {%- set ids = [] -%} {%- if q.help_text %}{% set _ = ids.append(name ~ '-help') %}{% endif -%} {%- if err %}{% set _ = ids.append(name ~ '-error') %}{% endif -%} {%- if ids %} aria-describedby="{{ ids | join(' ') }}"{% endif -%} {%- endmacro %} {% macro help_and_error(name, q, err, errors_text) %} {% if q.help_text %}

{{ q.help_text }}

{% endif %} {% if err %}

{{ _(errors_text[err]) }}

{% endif %} {% endmacro %} {% macro question_media(q, media_base, embed_policy) %} {% set m = q.config.get('media') or {} %} {% if m.kind == 'images' and m['items'] %}
{% for item in m['items'] %} {{ item.alt }} {% endfor %}
{% elif m.kind == 'video' and m.id %}
{% elif m.kind == 'embed' %} {% set info = embed_info(m, embed_policy) %} {% if info and not info.consent and info.file %}
{% elif info and not info.consent %}
{% elif info %}

{{ _('This video is provided by %(provider)s. When you load it, data such as your IP address is sent to %(provider)s.', provider=info.provider) }}

{{ _('Watch at %(provider)s', provider=info.provider) }}

{% endif %} {% endif %} {% endmacro %} {% macro option_tiles(q, name, vals, multiple, media_base, required) %}
{% for o in q.config.options %} {% endfor %}
{% endmacro %} {% macro question_block(q, values, errors, errors_text, media_base='', embed_policy=none, files={}, accept_for=none, places={}, own_status={}) %} {{ question_media(q, media_base, embed_policy) }} {% set name = 'q' ~ q.id %} {% set err = errors.get(q.id) %} {% set val = (values.get(name) or [''])[0] %} {% set vals = values.get(name) or [] %} {% set other = (values.get(name ~ '_other') or [''])[0] %} {% set cfg = q.config %} {% if q.type == 'heading' %}

{{ q.label }}

{% elif q.type == 'info' %}
{{ q.label }}
{% elif q.type == 'page_break' %}
{% if q.label %}

{{ q.label }}

{% endif %} {% elif q.type in ('yes_no', 'single_choice', 'multiple_choice', 'ranking', 'rating', 'file_upload', 'slots', 'poll') and not (q.type == 'single_choice' and cfg.display == 'dropdown') %}
{{ q.label }}{{ required_mark(q) }} {{ help_and_error(name, q, err, errors_text) }} {% if q.type == 'yes_no' %}
{% elif q.type == 'single_choice' and cfg.display == 'images' %} {{ option_tiles(q, name, [val], false, media_base, q.required) }} {% if cfg.allow_other %}
{% endif %} {% elif q.type == 'single_choice' %}
{% for o in cfg.options %} {% endfor %} {% if cfg.allow_other %} {% endif %}
{% elif q.type == 'multiple_choice' and cfg.display == 'images' %} {{ option_tiles(q, name, vals, true, media_base, false) }} {% if cfg.allow_other %}
{% endif %} {% if cfg.min_select or cfg.max_select %}

{% if cfg.min_select and cfg.max_select %}{{ _('Choose between %(a)s and %(b)s options.', a=cfg.min_select, b=cfg.max_select) }} {% elif cfg.min_select %}{{ _('Choose at least %(a)s options.', a=cfg.min_select) }} {% else %}{{ _('Choose at most %(b)s options.', b=cfg.max_select) }}{% endif %}

{% endif %} {% elif q.type == 'multiple_choice' %}
{% for o in cfg.options %} {% endfor %} {% if cfg.allow_other %} {% endif %}
{% if cfg.min_select or cfg.max_select %}

{% if cfg.min_select and cfg.max_select %}{{ _('Choose between %(a)s and %(b)s options.', a=cfg.min_select, b=cfg.max_select) }} {% elif cfg.min_select %}{{ _('Choose at least %(a)s options.', a=cfg.min_select) }} {% else %}{{ _('Choose at most %(b)s options.', b=cfg.max_select) }}{% endif %}

{% endif %} {% elif q.type == 'ranking' %}

{{ _('Give each option a place: 1 is your first choice.') }}

{% set n = cfg.options | length %} {% for o in cfg.options %} {% set rank_name = name ~ '_rank_' ~ o.id %} {% set rank_val = (values.get(rank_name) or [''])[0] %} {% endfor %}
{% elif q.type == 'slots' and cfg.single %} {% set a = places.get(q.id, {}).get('single') %} {% set st = own_status.get((q.id, 'single')) %} {% set mine = 'single' in vals %} {% set full = a is not none and a.full %}
{% elif q.type == 'slots' %} {% set avail = places.get(q.id, {}) %}
{% for o in cfg.options %} {% set a = avail.get(o.id) %} {% set mine = o.id in vals %} {% set st = own_status.get((q.id, o.id)) %} {% set full = a is not none and a.full %} {% if not (full and cfg.hide_full and not mine) %} {% endif %} {% endfor %}
{% elif q.type == 'poll' %} {% set allowed_votes = ['yes', 'maybe', 'no'] if cfg.answers == 'ynm' else ['yes', 'no'] %} {% set vote_names = {'yes': _('Yes'), 'maybe': _('Maybe'), 'no': _('No')} %}
{% for o in cfg.options %} {% set vname = name ~ '_' ~ o.id %} {% set cur = (values.get(vname) or [''])[0] %}
{{ option_text(o) }}{% if o.proposed %} {{ _('proposed') }}{% endif %}{% if o.id in (cfg.confirmed or []) %} {{ _('confirmed') }}{% endif %} {% for v in allowed_votes %}{% endfor %}
{% endfor %}
{% if cfg.allow_proposals %}
{% if cfg.mode == 'dates' %} {% else %} {% endif %}

{{ _('Your proposal is added for everyone and counts as your “yes”.') }}

{% endif %} {% elif q.type == 'file_upload' %} {% set kept = values.get(name ~ '_keep') or [] %} {% set kept_files = files.get(q.id) or [] %} {% if kept %}

{{ _('Uncheck a file to remove it.') }}

{% endif %} 1 %}multiple{% endif %} {% if accept_for %}accept="{{ accept_for(q) }}"{% endif %} {% if q.required and not kept %}required{% endif %} aria-label="{{ q.label }}">

{{ ngettext('At most %(num)d file', 'At most %(num)d files', cfg.max_files or 1) }}, {{ _('each at most %(mb)s MB.', mb=cfg.max_mb or 10) }}

{% elif q.type == 'rating' %}
{% if cfg.label_min %}{{ cfg.label_min }}{% endif %} {% for i in range(1, (cfg.scale_max or 5) + 1) %} {% endfor %} {% if cfg.label_max %}{{ cfg.label_max }}{% endif %}
{% endif %}
{% elif q.type == 'participant_name' %} {# Vorbelegung für Angemeldete: Name und Adresse aus dem Konto #} {% set acct_parts = (user.display_name.rsplit(' ', 1) if user and user.display_name else []) %} {% set first = (values.get(name ~ '_first') or [acct_parts[0] if acct_parts | length == 2 else ''])[0] %} {% set last = (values.get(name ~ '_last') or [acct_parts[1] if acct_parts | length == 2 else ''])[0] %} {% set email = (values.get(name ~ '_email') or [user.email if user and not values else ''])[0] %} {% set email_mode = cfg.email or 'optional' %}
{{ q.label }}{{ required_mark(q) }} {{ help_and_error(name, q, err, errors_text) }}
{% if email_mode != 'off' %} {% endif %}
{% else %}
{{ help_and_error(name, q, err, errors_text) }} {% set common %}id="{{ name }}-input" name="{{ name }}"{{ describedby(name, q, err) }}{% if q.required %} required{% endif %}{% if err %} aria-invalid="true"{% endif %}{% endset %} {% if q.type == 'short_text' %} {% elif q.type == 'long_text' %} {% elif q.type == 'email' %} {% elif q.type == 'phone' %} {% elif q.type == 'number' %}
{% if cfg.unit %}{{ cfg.unit }}{% endif %}
{% elif q.type == 'date' %} {% elif q.type == 'time' %} {% elif q.type == 'datetime' %} {% elif q.type == 'single_choice' %} {% if cfg.allow_other %} {% endif %} {% endif %}
{% endif %} {% endmacro %} {# Eintrag "Teilnahme mit Plätzen" mit genau einer Option: Zustand als Text #} {# Wer sich schon eingetragen hat (nur wenn das Formular Namen zeigt) #} {% macro slot_names_line(q, option_id) -%} {%- set by_q = (slot_names.get(q.id) if slot_names is defined and slot_names else none) or {} -%} {%- set who = by_q.get(option_id) -%} {%- if who and (who.confirmed or who.waiting) -%} {%- if who.confirmed %}{{ _('Signed up:') }} {{ who.confirmed | join(', ') }}{% endif -%} {%- if who.waiting %}{% if who.confirmed %} · {% endif %}{{ _('Waiting list:') }} {{ who.waiting | join(', ') }}{% endif -%} {%- endif -%} {%- endmacro %} {% macro slot_state(a, st, full, waitlist) -%} {%- if st == 'waiting' %}{{ _('you are on the waiting list') }} {%- elif st == 'confirmed' %}{{ _('booked for you') }} {%- elif a is not none and a.capacity %} {%- if full %}{% if waitlist %}{{ _('booked up, waiting list possible') }}{% else %}{{ _('booked up') }}{% endif %} {%- else %}{{ ngettext('%(num)d place left', '%(num)d places left', a.free) }}{% endif %} {%- endif -%} {%- endmacro %} {% macro cond_attr(q) %}{% if q.config.get('condition') %} data-cond='{{ q.config.condition | tojson }}'{% endif %}{% endmacro %} {# Fragengruppe: eine Tabellenzeile je Frage. Die Prüfung macht der Server. #} {% macro group_block(g, members, values, errors, errors_text, places={}, own_status={}) %} {% set gname = 'q' ~ g.id %} {% set gerr = errors.get(g.id) %} {% set kind = g.config.get('member_type') or 'slots' %} {% set counting = kind in ('slots', 'yes_no') %} {% set limit = (g.config.get('max_select') or 0) if counting else 0 %} {% set least = (g.config.get('min_select') or 0) if counting else 0 %} {% set group_rules = kind == 'slots' %}
{{ g.label }}{% if least %}{% endif %} {{ help_and_error(gname, g, gerr, errors_text) }} {% if limit or least %}

{%- if kind == 'yes_no' %} {%- if least and limit %}{{ _('Between %(a)s and %(b)s “Yes” in this group.', a=least, b=limit) }} {%- elif least %}{{ ngettext('At least %(num)d “Yes” in this group.', 'At least %(num)d “Yes” in this group.', least) }} {%- else %}{{ ngettext('At most %(num)d “Yes” in this group.', 'At most %(num)d “Yes” in this group.', limit) }}{% endif %} {%- else %} {%- if least and limit and least == limit %}{{ ngettext('Please choose exactly %(num)d entry here.', 'Please choose exactly %(num)d entries here.', least) }} {%- elif least and limit %}{{ _('Please choose between %(a)s and %(b)s entries here.', a=least, b=limit) }} {%- elif least %}{{ ngettext('Please choose at least %(num)d entry here.', 'Please choose at least %(num)d entries here.', least) }} {%- else %}{{ ngettext('You can choose at most %(num)d entry here.', 'You can choose at most %(num)d entries here.', limit) }}{% endif %} {%- endif -%}

{% endif %} {% if members %} {% set first = members[0].config %}
{% if kind == 'slots' %} {% elif kind == 'yes_no' %} {% elif kind == 'rating' %} {% set top = first.scale_max or 5 %} {% for i in range(1, top + 1) %} {% endfor %} {% else %} {% for o in first.options %}{% endfor %} {% endif %} {% for q in members %} {% set name = 'q' ~ q.id %} {% set err = errors.get(q.id) %} {% set val = (values.get(name) or [''])[0] %} {% set cfg = q.config %} {% set row_id = name ~ '-row' %} {% set must = q.required and not group_rules %} {% if kind == 'slots' %} {% set a = places.get(q.id, {}).get('single') %} {% set st = own_status.get((q.id, 'single')) %} {% set mine = 'single' in (values.get(name) or []) %} {% set full = a is not none and a.full %} {% endif %} {% if kind == 'slots' %} {% elif kind == 'yes_no' %} {% elif kind == 'rating' %} {% for i in range(1, (first.scale_max or 5) + 1) %} {% endfor %} {% else %} {% for o in cfg.options %} {% endfor %} {% endif %} {% endfor %}
{{ _('Question') }}{{ _('Places') }} {{ _('Sign up') }}{{ first.label_yes or _('Yes') }} {{ first.label_no or _('No') }}{{ i }}{% if loop.first and first.label_min %}{{ first.label_min }}{% elif loop.last and first.label_max %}{{ first.label_max }}{% endif %}{{ o.label }}
{{ q.label }}{% if must %}{% endif %} {% if q.help_text %}{{ q.help_text }}{% endif %} {% if err %}{{ _(errors_text[err]) }}{% endif %} {% if kind == 'slots' %}{{ slot_names_line(q, 'single') }}{% endif %} {{ slot_state(a, st, full, cfg.waitlist) }}
{% endif %}
{% endmacro %}