2024-12-16 17:17:42 +00:00
|
|
|
{#
|
|
|
|
Macros for rendering table paginated with HTMX.
|
|
|
|
#}
|
2023-03-09 16:41:26 +00:00
|
|
|
{% 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 }}">
|
2023-03-09 16:41:26 +00:00
|
|
|
<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"
|
|
|
|
/>
|
2023-03-09 22:11:39 +00:00
|
|
|
<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 %}
|
|
|
|
|
2023-08-27 14:33:48 +00:00
|
|
|
{% 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 %}
|
2023-03-09 16:41:26 +00:00
|
|
|
{% 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">
|
2023-08-27 14:33:48 +00:00
|
|
|
{{ 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) %}
|
2024-03-26 19:22:32 +00:00
|
|
|
{{ 1|numberformat }}
|
2023-08-27 14:33:48 +00:00
|
|
|
{% endcall %}
|
|
|
|
{% endif %}
|
|
|
|
{% if form.page.data > 2 %}
|
|
|
|
{% call button(form, "ellipsis-previous", none) %}
|
|
|
|
…
|
|
|
|
{% endcall %}
|
|
|
|
{% endif %}
|
|
|
|
<span class="ui button active">
|
2024-03-26 19:22:32 +00:00
|
|
|
{{ form.page.data|numberformat }}
|
2023-08-27 14:33:48 +00:00
|
|
|
</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) %}
|
2024-03-26 19:22:32 +00:00
|
|
|
{{ form.page_max|numberformat }}
|
2023-08-27 14:33:48 +00:00
|
|
|
{% 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>
|
2023-03-09 16:41:26 +00:00
|
|
|
</div>
|
|
|
|
<div class="ui left floated">
|
|
|
|
<span class="disabled ui button">
|
2024-03-26 19:22:32 +00:00
|
|
|
{% 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 %}
|
2024-03-26 19:22:32 +00:00
|
|
|
{{ nb_items_formatted }} items
|
2023-06-30 15:42:16 +00:00
|
|
|
{% endtrans %}
|
2023-03-09 16:41:26 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
2023-02-25 17:11:19 +00:00
|
|
|
{% endmacro %}
|