|
1 |
| -{# ========================================================================== |
2 |
| - |
3 |
| - Filter List Controls |
4 |
| - |
5 |
| - ========================================================================== |
6 |
| - |
7 |
| - Description: |
8 |
| - |
9 |
| - Create an expandable of filters when given: |
10 |
| - |
11 |
| - controls: Collection of field controls and other settings to determine |
12 |
| - what's rendered. |
13 |
| - |
14 |
| - form: Django form that carries the fields that are to be rendered. |
15 |
| - |
16 |
| - |
17 |
| - ========================================================================== #} |
18 |
| -{% from 'organisms/expandable.html' import expandable with context %} |
19 |
| - |
20 | 1 | {% macro _filter_selectable(type, label_text, id, name, value, required=None, group=None) %}
|
21 | 2 | <li class="m-form-field m-form-field__checkbox">
|
22 | 3 | <input class="{{ 'a-checkbox' if type == 'checkbox' else 'a-radio' }}"
|
|
33 | 14 | </li>
|
34 | 15 | {% endmacro %}
|
35 | 16 |
|
36 |
| -{% macro _render_filter_fields(controls, form) -%} |
37 |
| - {% if controls.title %} |
| 17 | +{% macro _render_filter_fields(value, form) -%} |
| 18 | + {% if value.title %} |
38 | 19 | {% set field_id = 'title' %}
|
39 | 20 | <div class="content-l_col
|
40 | 21 | content-l_col-1">
|
|
54 | 35 | </div>
|
55 | 36 | </div>
|
56 | 37 | {% endif %}
|
57 |
| - {% if controls.categories.filter_category %} |
| 38 | + {% if value.categories.filter_category %} |
58 | 39 | <div class="content-l_col
|
59 | 40 | content-l_col-1-3">
|
60 | 41 | <div class="o-form_group">
|
|
63 | 44 | Category
|
64 | 45 | </legend>
|
65 | 46 | <ul class="m-list m-list__unstyled">
|
66 |
| - {% for slug, name in choices_for_page_type(controls.categories.page_type) %} |
| 47 | + {% for slug, name in choices_for_page_type(value.categories.page_type) %} |
67 | 48 | {{ _filter_selectable('checkbox', category_label(slug), 'categories_' ~ slug, 'categories', slug) }}
|
68 | 49 | {% endfor %}
|
69 | 50 | </ul>
|
70 | 51 | </fieldset>
|
71 | 52 | </div>
|
72 | 53 | </div>
|
73 | 54 | {% endif %}
|
74 |
| - {% if controls.topics or controls.authors or controls.date_range %} |
| 55 | + {% if value.topics or value.authors or value.date_range %} |
75 | 56 | <div class="content-l_col
|
76 | 57 | content-l_col-2-3">
|
77 | 58 | <div class="content-l">
|
78 |
| - {% if controls.topics %} |
| 59 | + {% if value.topics %} |
79 | 60 | {% set field_id = 'topics' %}
|
80 | 61 | <div class="content-l_col
|
81 | 62 | content-l_col-1-2">
|
|
95 | 76 | </div>
|
96 | 77 | </div>
|
97 | 78 | {% endif %}
|
98 |
| - {% if controls.authors %} |
| 79 | + {% if value.authors %} |
99 | 80 | {% set field_id = 'authors' %}
|
100 | 81 | <div class="content-l_col
|
101 | 82 | content-l_col-1-2">
|
|
115 | 96 | </div>
|
116 | 97 | </div>
|
117 | 98 | {% endif %}
|
118 |
| - {% if controls.date_range %} |
| 99 | + {% if value.date_range %} |
119 | 100 | <div class="content-l_col
|
120 | 101 | content-l_col-1">
|
121 | 102 | <div class="o-form_group">
|
|
164 | 145 | {% endif %}
|
165 | 146 | {% endmacro %}
|
166 | 147 |
|
167 |
| -{% macro _filters_form(controls, form) %} |
| 148 | +{% macro _filters_form(value, form) %} |
168 | 149 | <form
|
169 |
| - {% if 'filterable-list' in controls.form_type %} |
| 150 | + {% if 'filterable-list' in value.form_type %} |
170 | 151 | method="get"
|
171 | 152 | action=".">
|
172 |
| - {% elif 'pdf-generator' in controls.form_type %} |
| 153 | + {% elif 'pdf-generator' in value.form_type %} |
173 | 154 | method="post"
|
174 | 155 | action="pdf/">
|
175 | 156 | <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
|
176 | 157 | {% endif %}
|
177 | 158 |
|
178 | 159 | <div class="content-l">
|
179 |
| - {{ _render_filter_fields(controls, form) }} |
| 160 | + {{ _render_filter_fields(value, form) }} |
180 | 161 | <div class="content-l_col
|
181 | 162 | content-l_col-1
|
182 | 163 | m-btn-group">
|
|
192 | 173 | </form>
|
193 | 174 | {% endmacro %}
|
194 | 175 |
|
195 |
| -{% from 'molecules/info-unit.html' import info_unit with context %} |
196 |
| -{% import 'molecules/notification.html' as notification with context %} |
197 |
| -{% import 'organisms/post-preview.html' as post_preview with context %} |
| 176 | +{# ========================================================================== |
| 177 | + |
| 178 | + Filterable List Controls |
198 | 179 |
|
199 |
| -{% macro render_if_any(block_value) %} |
200 |
| - <div class="block block__flush-top"> |
201 |
| - {% if filter_data.form.filterable_pages.first() %} |
202 |
| - {{ render(block_value) }} |
203 |
| - {% elif block_value.no_posts_message %} |
204 |
| - {{ notification.render('default', true, |
205 |
| - block_value.no_posts_message, |
206 |
| - block_value.no_posts_explanation) }} |
207 |
| - {% endif %} |
208 |
| - </div> |
209 |
| -{% endmacro %} |
| 180 | + ========================================================================== |
210 | 181 |
|
211 |
| -{% macro render(controls) %} |
212 |
| - <div class="o-filterable-list-controls" |
213 |
| - id="o-filterable-list-controls"> |
214 |
| - {% set form = filter_data.form %} |
215 |
| - {% set posts = filter_data.page_set %} |
216 |
| - {% if has_active_filters %} |
217 |
| - {% do controls.update({'is_expanded':true}) %} |
| 182 | + Description: |
| 183 | + |
| 184 | + Create an expandable of filters when given: |
| 185 | + |
| 186 | + value: Collection of field value and other settings to determine |
| 187 | + what's rendered. |
| 188 | + |
| 189 | + form: Django form that carries the fields that are to be rendered. |
| 190 | + |
| 191 | + fragment_id: A unique ID for the filter list control. |
| 192 | + |
| 193 | + ========================================================================== #} |
| 194 | +{% macro render(value, form, fragment_id) %} |
| 195 | + {% from 'organisms/expandable.html' import expandable with context %} |
| 196 | + <div id="{{ fragment_id }}" class="o-filterable-list-controls"> |
| 197 | + {% if value.has_active_filters %} |
| 198 | + {% do value.update({'is_expanded':true}) %} |
218 | 199 | {% endif %}
|
219 |
| - {% set form_markup = _filters_form(controls, form) %} |
220 |
| - {% call() expandable(controls, expandable_cue_additional_text='filters') %} |
| 200 | + |
| 201 | + {% set form_markup = _filters_form(value, form) %} |
| 202 | + {% call() expandable(value, expandable_cue_additional_text='filters') %} |
221 | 203 | {{ form_markup | safe }}
|
222 | 204 | {% endcall %}
|
223 |
| - {% for field in form %} |
224 |
| - {% if field.errors %} |
225 |
| - {% for error in field.errors %} |
226 |
| - {{ notification.render('error', true, error) }} |
227 |
| - {% endfor %} |
228 |
| - {% endif %} |
229 |
| - {% endfor %} |
230 |
| - {% if 'filterable-list' in controls.form_type and posts is defined %} |
231 |
| - {% if form.is_valid() %} |
232 |
| - {% set count = posts.paginator.count %} |
233 |
| - {% if not has_active_filters %} |
234 |
| - {{ notification.render('default', false, '') }} |
235 |
| - {% elif count == 0 %} |
236 |
| - {{ notification.render( |
237 |
| - 'warning', |
238 |
| - true, |
239 |
| - 'Sorry, there were no results based on your filter selections.', |
240 |
| - 'Please reset the filter or change your selections and try again.' |
241 |
| - ) }} |
242 |
| - {% else %} |
243 |
| - {{ notification.render( |
244 |
| - 'success', |
245 |
| - true, |
246 |
| - count ~ ' filtered result' ~ count|pluralize('s') |
247 |
| - ) }} |
248 |
| - {% endif %} |
249 |
| - {% endif %} |
250 |
| - {% endif %} |
251 |
| - {% if controls.categories.page_type == 'activity-log' %} |
252 |
| - {% import 'activity-log/_activity-list.html' as activity_list with context %} |
253 |
| - {{ activity_list.render(posts) }} |
254 |
| - {% elif controls.output_5050 %} |
255 |
| - <div class="o-info-unit-group u-mb30" data-qa-hook="image-text-50-50"> |
256 |
| - <div class="content-l"> |
257 |
| - {% for post in posts %} |
258 |
| - <div class="content-l_col |
259 |
| - content-l_col-1-2"> |
260 |
| - {% set post_url = pageurl(post) %} |
261 |
| - {% if post.preview_image %} |
262 |
| - {% set photo = image(post.preview_image, 'original') %} |
263 |
| - {% endif %} |
264 |
| - {% set heading = '<a href="' ~ post_url ~ '"><h2 class="h3">' ~ |
265 |
| - post.preview_title ~ |
266 |
| - '</h2></a>' |
267 |
| - if post.preview_title else null %} |
268 |
| - {% set sub_heading = '<a href="' ~ post_url ~ '"><h2 class="h4">' ~ |
269 |
| - post.preview_subheading ~ |
270 |
| - '</h2></a>' |
271 |
| - if post.preview_subheading else null %} |
272 |
| - {% if post.secondary_link_url and post.secondary_link_text %} |
273 |
| - {% set links = [ |
274 |
| - { |
275 |
| - 'url': post.secondary_link_url, |
276 |
| - 'text': post.secondary_link_text |
277 |
| - } |
278 |
| - ] %} |
279 |
| - {% endif %} |
280 |
| - {{ info_unit( { |
281 |
| - 'image': { |
282 |
| - 'url': photo.url if photo else '/', |
283 |
| - 'alt': post.preview_image.alt if post.preview_image.alt else '', |
284 |
| - }, |
285 |
| - 'heading': heading, |
286 |
| - 'sub_heading': sub_heading, |
287 |
| - 'body': post.preview_description, |
288 |
| - 'links': links or null, |
289 |
| - 'link_image_and_heading': controls.link_image_and_heading |
290 |
| - } ) }} |
291 |
| - </div> |
292 |
| - {% endfor %} |
293 |
| - </div> |
294 |
| - </div> |
295 |
| - {% else %} |
296 |
| - {% for post in posts %} |
297 |
| - {{ post_preview.render(post, controls) }} |
298 |
| - {% endfor %} |
299 |
| - {% endif %} |
300 |
| - <div class="block block__flush-top block__flush-bottom block__padded-top"> |
301 |
| - {% import 'molecules/pagination.html' as pagination with context %} |
302 |
| - {% set fragment_id = 'o-filterable-list-controls' %} |
303 |
| - {{ pagination.render( posts.paginator.num_pages, posts.number, fragment_id) }} |
304 |
| - </div> |
305 | 205 | </div>
|
306 | 206 | {% endmacro %}
|
0 commit comments