canaille-globuzma/canaille/templates/macro/table.html

117 lines
4.4 KiB
HTML
Raw Permalink Normal View History

2024-12-16 17:17:42 +00:00
{#
Macros for rendering table paginated with HTMX.
#}
{% macro search(form, target) %}
2023-03-07 17:29:18 +00:00
<form id="search" action="{{ url_for(request.url_rule.endpoint, **request.view_args) }}" method="POST" class="ui form">
{{ form.hidden_tag() if form.hidden_tag }}
<input type="hidden" name="page" value="{{ form.page.data }}">
<div class="ui fluid action input icon">
<input
type="search"
placeholder="{{ _("Search…") }}"
name="{{ form.query.name }}"
value="{{ form.query.data }}"
hx-post="{{ url_for(request.url_rule.endpoint, **request.view_args) }}"
hx-trigger="keyup changed delay:500ms, search"
hx-target="{{ target }}"
hx-swap="outerHTML"
hx-indicator=".search-button"
/>
<button
type="submit"
class="ui icon button search-button"
title="{{ _("Search") }}"
hx-post="{{ url_for(request.url_rule.endpoint, **request.view_args) }}"
hx-target="{{ target }}"
hx-swap="outerHTML"
hx-indicator=".search-button"
>
2023-03-07 17:29:18 +00:00
<i class="search icon"></i>
</button>
</div>
</form>
{% endmacro %}
{% macro button(form, id, page) %}
{% if page is none %}
<span class="icon disabled ui button" style="border-radius: 0">
{{ caller() }}
</span>
{% else %}
<button
type="submit"
class="icon ui button"
hx-post="{{ url_for(request.url_rule.endpoint, **request.view_args) }}"
hx-target="closest table"
hx-swap="outerHTML"
name="page"
value="{{ page }}"
>
{{ caller() }}
</button>
{% endif %}
{% endmacro %}
{% macro pagination(form) %}
2023-04-03 08:10:13 +00:00
<div class="ui right floated buttons pagination">
2023-08-31 20:34:12 +00:00
<form id="{{ form.__class__.__name__|lower }}" action="{{ url_for(request.url_rule.endpoint, **request.view_args) }}" method="POST">
{{ form.hidden_tag() if form.hidden_tag }}
<input type="hidden" name="query" value="{{ form.query.data }}">
<span class="icon disabled ui button" style="border-radius: 0">
{% trans %}Page{% endtrans %}
</span>
{% if form.page.data > 1 %}
{% call button(form, "previous", form.page.data - 1) %}
<i class="left chevron icon"></i>
{% endcall %}
{% else %}
{% call button(form, "previous", none) %}
<i class="left chevron icon"></i>
{% endcall %}
{% endif %}
{% if form.page.data > 1 %}
{% call button(form, "first", 1) %}
{{ 1|numberformat }}
{% endcall %}
{% endif %}
{% if form.page.data > 2 %}
{% call button(form, "ellipsis-previous", none) %}
{% endcall %}
{% endif %}
<span class="ui button active">
{{ form.page.data|numberformat }}
</span>
{% if form.page.data < form.page_max - 1 %}
{% call button(form, "ellipsis-next", none) %}
{% endcall %}
{% endif %}
{% if form.page.data < form.page_max %}
{% call button(form, "last", form.page_max) %}
{{ form.page_max|numberformat }}
{% endcall %}
{% endif %}
{% if form.page.data < form.page_max %}
{% call button(form, "next", form.page.data + 1) %}
<i class="right chevron icon"></i>
{% endcall %}
{% else %}
{% call button(form, "next", none) %}
<i class="right chevron icon"></i>
{% endcall %}
{% endif %}
</form>
</div>
<div class="ui left floated">
<span class="disabled ui button">
{% trans nb_items=form.nb_items, nb_items_formatted=form.nb_items|numberformat %}
{{ nb_items_formatted }} item
2023-06-30 15:42:16 +00:00
{% pluralize %}
{{ nb_items_formatted }} items
2023-06-30 15:42:16 +00:00
{% endtrans %}
</span>
</div>
{% endmacro %}