0001-wcs-add-pagination-for-current-form-cell-10179.patch
combo/apps/wcs/models.py | ||
---|---|---|
303 | 303 |
@register_cell_class |
304 | 304 |
class WcsCurrentFormsCell(WcsUserDataBaseCell): |
305 | 305 |
variable_name = 'user_forms' |
306 |
paginate_by = 10 |
|
306 | 307 | |
307 | 308 |
categories = JSONField(_('Categories'), blank=True) |
308 | 309 |
current_forms = models.BooleanField(_('Current Forms'), default=True) |
... | ... | |
380 | 381 |
continue |
381 | 382 |
context['forms'].extend(context['user_forms'][wcs_site]['data']) |
382 | 383 | |
384 |
if self.paginate_by: |
|
385 |
context['paginate_by'] = self.paginate_by |
|
386 | ||
383 | 387 |
return context |
384 | 388 | |
385 | 389 |
@register_cell_class |
combo/apps/wcs/templates/combo/wcs/current_forms.html | ||
---|---|---|
6 | 6 |
{% include "combo/wcs/list_of_forms.html" with forms=forms %} |
7 | 7 |
</div> |
8 | 8 |
{% endfor %} |
9 |
{% include "combo/pagination.html" %} |
|
9 | 10 |
{% endblock %} |
combo/apps/wcs/templates/combo/wcs/list_of_forms.html | ||
---|---|---|
3 | 3 |
<ul> |
4 | 4 |
{% for data in forms.data|dictsortreversed:"form_receipt_datetime" %} |
5 | 5 |
{% if data.url and data.title %} |
6 |
<li class="{{data.status_css_class}} {% if data.form_status_is_endpoint %}done{% endif %}"><a
|
|
7 |
{% if data.readable %}href="{{ data.url }}"{% endif %}><span class="form-title">{{data.name}}</span> |
|
6 |
<li class="{{data.status_css_class}} {% if data.form_status_is_endpoint %}done{% endif %}" {% if paginate_by %}hidden{% endif %}>
|
|
7 |
<a {% if data.readable %}href="{{ data.url }}"{% endif %}><span class="form-title">{{data.name}}</span>
|
|
8 | 8 |
<span class="form-number">{{data.form_number}} |
9 | 9 |
{% if data.form_digest %}<span class="form-digest">({{data.form_digest}})</span>{% endif %} |
10 | 10 |
</span> |
combo/apps/wcs/templates/combo/wcs/user_all_forms.html | ||
---|---|---|
6 | 6 |
{% include "combo/wcs/list_of_forms.html" with forms=forms %} |
7 | 7 |
</div> |
8 | 8 |
{% endfor %} |
9 |
{% include "combo/pagination.html" %} |
|
9 | 10 |
{% endblock %} |
combo/apps/wcs/templates/combo/wcs/user_done_forms.html | ||
---|---|---|
6 | 6 |
{% include "combo/wcs/list_of_forms.html" with forms=forms %} |
7 | 7 |
</div> |
8 | 8 |
{% endfor %} |
9 |
{% include "combo/pagination.html" %} |
|
9 | 10 |
{% endblock %} |
combo/public/static/js/combo.paginate.js | ||
---|---|---|
1 |
$(function() { |
|
2 |
var page_index = 0; |
|
3 |
var paginate_by = $('a#paginate-by').text(); |
|
4 |
if(!paginate_by) |
|
5 |
return; |
|
6 |
paginate_by = parseInt(paginate_by); |
|
7 |
// Get all <li> inside the same div as us, ignoring whether they are part of |
|
8 |
// different <ul> |
|
9 |
var items = $('div#navigate-pages').parent().find('li'); |
|
10 |
var max_page_index = Math.ceil(items.length / paginate_by); |
|
11 | ||
12 |
function update_page(step) { |
|
13 |
new_index = page_index + step; |
|
14 |
if(!(new_index >= 0 && new_index < max_page_index)) |
|
15 |
return; |
|
16 |
page_index = new_index; |
|
17 |
$('a#prev,a#next').show(); |
|
18 |
if(page_index == 0) |
|
19 |
$('a#prev').hide(); |
|
20 |
if(page_index == max_page_index - 1) |
|
21 |
$('a#next').hide(); |
|
22 |
start_item = paginate_by * page_index; |
|
23 |
items.hide(); |
|
24 |
items.slice(start_item, start_item + paginate_by).show(); |
|
25 |
}; |
|
26 |
update_page(0); |
|
27 | ||
28 |
$('a#next').click(function() {update_page(1)}); |
|
29 |
$('a#prev').click(function() {update_page(-1)}); |
|
30 |
}); |
combo/public/templates/combo/pagination.html | ||
---|---|---|
1 |
{% load static %} |
|
2 | ||
3 |
<script src="{% static "js/combo.paginate.js" %}"></script> |
|
4 | ||
5 |
<div id="navigate-pages"> |
|
6 |
<a hidden id="paginate-by">{{ paginate_by }}</a> |
|
7 |
<a id="prev" href="#prev-item" hidden>Previous</a> |
|
8 |
<a id="next" href="#next-item" hidden>Next</a> |
|
9 |
</div> |
|
0 |
- |