{# Results -- These macros are designed for handling the listing/results pages and the different formats that the content can be listed. They should be called like so: -------------------------------------------------------------------------------- {%- import "macros/results.html" as _results -%} {{ _results.filter(form) }} {{ _results.list( form, page, headings=headings, columns=columns, action=decor.result_action ) }} {{ _results.paging(form, paginator, page) }} -------------------------------------------------------------------------------- The `list` macro accepts a `headings` and `columns` value. These should be provided as macros containing a list of the headings/data columns like so: -------------------------------------------------------------------------------- {% macro headings() %} {{ _results.heading('Heading 1') }} {{ _results.heading('Heading 2', sort_with='heading_2') }} ... {% endmacro %} {% macro columns(item) %} {{ _results.column(item.item_1) }} {{ _results.column(item.item_2) }} ... {% endmacro %} -------------------------------------------------------------------------------- The values `form` and `page` must be passed. The `form` value is used to set the current sorted column. The `page` value is used to loop through and display each of the items, using the `columns` macro for each row. You can also pass through an `action` value. This allows you to set `data-url` URL against the row (tr) which can then be made linkable using JS. #} {%- import "manhattan/manage/components/form.html" as _form with context -%} {# Filter -- A search form used to filter the results of a list page. The filter form requires that you pass a `form` value. This is used to generate the list of form filters. Everything passed to the filter macro is passed to and applied to the form macro inside it. -------------------------------------------------------------------------------- {{ _results.filter(form) }} -------------------------------------------------------------------------------- As standard you can also pass `class` to apply a custom class style to the containing element. You can also pass any other HTML attribute using keyword arguments and these will be applied to the container. -------------------------------------------------------------------------------- {{ _results.filter( form=form, action='/some-url', method='POST', class='some-class', **{'data-some-attribute': 'Some value'} ) }} -------------------------------------------------------------------------------- #} {% macro filter(form, action=None, method='GET', class=None) %} {%- set class = ' [ mh-filter ] [ mh-form--reverse-optional mh-form--fixed-btns-disabled ] ' + (' ' + class if class else '') -%} {%- call _form.form( form, action=action, method=method, class=class, **kwargs ) -%} {# Filter fields -- Loop through all form fields provided and show them appropriately unless they are the q field, page field, or within the advanced filters field. Also, we convert the sort_by field to a hidden field as ordering is achieved with javascript. #} {%- for field in form if not field.name in ['q', 'page', 'filters'] -%} {%- if field.name == 'sort_by' -%} {%- elif field.type != 'HiddenField' -%} {{ _form.field(field, class='mh-filter__field') }} {%- endif -%} {%- endfor -%} {%- if form.filters and form.filters._inline -%} {%- for field in form.filters -%} {{ _form.field(field, class='mh-filter__field') }} {%- endfor -%} {%- endif -%} {# Common field class -- The last field in the filter can contain the q field, the search button, and advanced filter dropdown. Given this, we need to format it differently depending on whether or not these exist. This is done by setting different classes against the common field. #} {%- set common_class = 'mh-filter__common' + (' mh-filter__common--has-q' if form.q else '') + (' mh-filter__common--has-adv-filter' if (form.filters and not form.filters._inline) else '') -%} {%- call _form.field(class=common_class) -%} {# Keyword field -- If there is a `q` field in the filter, it is manually inserted into the common field next to the search button. #} {%- if form.q -%} {{ _form.control(form.q) }} {%- endif -%} {# Search button -- Only show the search button if there are fields that are not a hidden field or not in the excluded list. #} {%- if form._info.show_search_button -%} {%- endif -%} {# Advanced filter -- If used, an advanced filter button appears to the right of the search field allowing the user to toggle the filter form in a dropdown. #} {%- if form.filters and not form.filters._inline -%} {{ advanced_filter(form) }} {%- endif -%} {%- endcall -%} {%- endcall -%} {% endmacro %} {% macro advanced_filter(form) %}
{{ fallback_text }} |