{# The one pager every paged table uses: prev and next either side of a "1-100 of 2000" summary. Two forms, because pages differ in where their paging state lives, not in how paging looks -- both emit .pager-controls with the same classes and icons, so the two render identically. Use `pager()` when the state is in the URL, so a page is a link and Back works. Use `pager_controls()` with `pager_scripts()` when the state is an offset held in JavaScript beside filters that never reach the URL, so a page is a re-fetch and navigating away would drop them. #} {# A dead end has nowhere to link to, so it stops being one. Bulma styles a disabled {%- endif -%} {% endmacro %} {# `page_href` is an already-rendered URL carrying the literal PAGENUMBER where the number goes -- substituted rather than appended, which would have to guess whether the separator is "?" or "&". `size_options` adds the per-page dropdown. Pass it on the top row only: the point of changing the size is not having to reach the bottom of the page first. #} {% macro pager(page, per_page, total, page_href, size_options=None) %} {% set start = ((page - 1) * per_page) + 1 if total else 0 %} {% set end = [page * per_page, total] | min %}
{# MSG: Tooltip on the button showing the previous page of a table. #} {{ _end(_('Previous page'), 'left-big', page_href | replace('PAGENUMBER', page - 1), page > 1) }} {# MSG: Tooltip on the button showing the next page of a table. #} {{ _end(_('Next page'), 'right-big', page_href | replace('PAGENUMBER', page + 1), end < total) }} {# Tokens rather than Jinja placeholders, because renderPager() below substitutes the same string client-side and shares this one msgid. #} {# MSG: Pagination summary. {start}, {end} and {total} are replaced with numbers, reading for example "1-100 of 2000". #} {{- _('{start}-{end} of {total}') | replace('{start}', start) | replace('{end}', end) | replace('{total}', total) -}} {% if size_options %} {# MSG: Label before the dropdown choosing how many rows to list per page. #}
{% endif %}
{% endmacro %} {# The ends are real buttons here because there is nowhere to link to, and the summary is filled in by renderPager() once the rows arrive. `prefix` names the element ids; wirePager() binds them by the same prefix, so one page can carry several of these. #} {% macro pager_controls(prefix) %}
{# MSG: Tooltip on the button showing the previous page of a table. #} {# MSG: Tooltip on the button showing the next page of a table. #}
{% endmacro %} {# Drives every pager_controls() on the page. Include once. #} {% macro pager_scripts() %} {% endmacro %}