You've already forked snikket-web-portal
101 lines
3.5 KiB
Django/Jinja
101 lines
3.5 KiB
Django/Jinja
{% macro box(type, title, slim=False, caller=None) %}
|
|
<aside class="box{% if slim %} slim{% endif %} {{ type }}"><header>{{ title }}</header> {{ caller() }}</aside>
|
|
{% endmacro %}
|
|
|
|
{% macro avatar(from_, hash, char=None, caller=None) -%}
|
|
{%- if hash -%}
|
|
<div class="avatar" style="background-image: url('{{ url_for_avatar(from_, hash) }}');"></div>
|
|
{%- else -%}
|
|
<div class="avatar shim" style="background-color: {{ text_to_css(from_) }}"><span data-avatar-char="{{ char or from_[0] }}"></span></div>
|
|
{%- endif -%}
|
|
{%- endmacro %}
|
|
|
|
{% macro showuri(uri, caller=None) %}
|
|
{%- if uri is none -%}
|
|
<em>—</em>
|
|
{%- else -%}
|
|
<div><input type="text" readonly="readonly" value="{{ uri }}"></div>
|
|
<div>{% call clipboard_button(uri, show_label=True) %}{% trans %}Copy link{% endtrans %}{% endcall %}</div>
|
|
{%- endif -%}
|
|
{% endmacro %}
|
|
|
|
{% macro icon(name, caller=None) -%}
|
|
{%- set alt = "" if caller is none else caller() -%}
|
|
{%- if alt %}<span class="a11y-only">{{ alt }}</span>{% endif %}<svg class="icon icon-{{ name }}" aria-hidden="true"><use xlink:href="{{ url_for('static', filename='img/icons.svg' )}}#icon-{{ name }}"></use></svg>
|
|
{%- endmacro %}
|
|
|
|
{% macro standard_button(icon_name, href, caller=None, class=None) -%}
|
|
{%- set label = caller() -%}
|
|
<a href="{{ href }}" class="button {% if class %}{{ class }}{% endif %}" aria-label="{{ a11y }}" title="{{ a11y }}">{% call icon(icon_name) %}{% endcall %}<span>{{ label }}</span></a>
|
|
{%- endmacro %}
|
|
|
|
{% macro form_button(icon_name, button_obj, caller=None, class=None) -%}
|
|
<button {% if class %}class="{{ class }}"{% endif %} id="{{ button_obj.id }}" name="{{ button_obj.name }}" type="submit" value="{{ button_obj.data or 'true' }}">{% call icon(icon_name) %}{% endcall %}<span>{{ button_obj.label.text }}</span></button>
|
|
{%- endmacro %}
|
|
|
|
{% macro custom_form_button(icon_name, name, value, caller=None, slim=False, class=None) -%}
|
|
{%- set text = caller() -%}
|
|
<button
|
|
{% if class %}class="{{ class }}"{% endif %}
|
|
{% if name %}name="{{ name }}"{% endif %}
|
|
type="submit"
|
|
{% if value %} value="{{ value }}"{% endif %}
|
|
{% if slim %}
|
|
aria-label="{{ text }}"
|
|
title="{{ text }}"
|
|
{% endif %}
|
|
>
|
|
{%- call icon(icon_name) %}{% endcall -%}
|
|
{%- if not slim -%}
|
|
<span>{{ text }}</span>
|
|
{%- endif -%}
|
|
</button>
|
|
{%- endmacro %}
|
|
|
|
{% macro action_button(icon_name, href, caller=None, class=None) -%}
|
|
{%- set a11y = caller() -%}
|
|
<a href="{{ href }}" class="button {% if class %}{{ class }}{% endif %}" aria-label="{{ a11y }}" title="{{ a11y }}">{% call icon(icon_name) %}{% endcall %}</a>
|
|
{%- endmacro %}
|
|
|
|
{% macro clipboard_button(data, show_label=False, caller=None, class=None) -%}
|
|
{%- set label = caller() -%}
|
|
<a class="button{% if class %} {{ class }}{% endif %}"
|
|
{% if not show_label %}
|
|
aria-label="{{ label }}"
|
|
title="{{ label }}"
|
|
{% endif %}
|
|
data-cliptext="{{ data }}"
|
|
onclick="copy_to_clipboard_btn(this); return false;">
|
|
{%- call icon("copy") %}{% endcall -%}
|
|
{%- if show_label %}
|
|
<span>{{ label }}</span>
|
|
{% endif -%}
|
|
</a>
|
|
{%- endmacro %}
|
|
|
|
{% macro render_errors(field, caller=None) -%}
|
|
{%- set error_list = field.errors if field.errors is not mapping else (field.errors.values() | flatten | list) -%}
|
|
{%- if error_list -%}
|
|
<div class="box warning">{#- -#}
|
|
<header>{% trans %}Invalid input{% endtrans %}</header>
|
|
{%- if error_list | length == 1 -%}
|
|
<p>{{ error_list[0] }}.</p>
|
|
{%- else -%}
|
|
<ul>
|
|
{%- for error in error_list -%}
|
|
<li>{{ error }}</li>
|
|
{%- endfor -%}
|
|
</ul>
|
|
{%- endif -%}
|
|
</div>
|
|
{%- endif -%}
|
|
{%- endmacro %}
|
|
|
|
{% macro value_or_hint(v, caller=None) %}
|
|
{%- if v is not none -%}
|
|
{{- v -}}
|
|
{%- else -%}
|
|
—
|
|
{%- endif -%}
|
|
{% endmacro %}
|