Skip to content

Commit 46d48ac

Browse files
committed
Allow sorting liaisons when selecting a related liaison. Fixes ietf-tools#386
- Legacy-Id: 2546
1 parent 80ca4e9 commit 46d48ac

4 files changed

Lines changed: 46 additions & 54 deletions

File tree

ietf/liaisons/views.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,25 @@ def liaison_edit(request, object_id):
227227
return add_liaison(request, liaison=liaison)
228228

229229
def ajax_liaison_list(request):
230-
public_liaisons = LiaisonDetail.objects.filter(Q(approval__isnull=True)|Q(approval__approved=True)).order_by("-submitted_date")
230+
order = request.GET.get('order_by', 'submitted_date')
231+
plain_order = order
232+
reverse_order = order.startswith('-')
233+
if reverse_order:
234+
plain_order = order[1:]
235+
if plain_order not in ('submitted_date', 'deadline_date', 'title', 'to_body', 'from_raw_body'):
236+
order = 'submitted_date'
237+
reverse_order = True
238+
plain_order = 'submitted_date'
239+
elif plain_order in ('submitted_date', 'deadline_date'):
240+
# Reverse order for date fields, humans find it more natural
241+
if reverse_order:
242+
order = plain_order
243+
else:
244+
order = '-%s' % plain_order
245+
public_liaisons = LiaisonDetail.objects.filter(Q(approval__isnull=True)|Q(approval__approved=True)).order_by(order)
231246

232247
return object_list(request, public_liaisons,
233248
allow_empty=True,
234249
template_name='liaisons/liaisondetail_simple_list.html',
235-
extra_context={}
250+
extra_context={plain_order: not reverse_order and '-' or None}
236251
)

ietf/templates/liaisons/liaisondetail_list.html

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,7 @@ <h1>Liaison Statements</h1>
2323
{% endif %}
2424
{% endblock %}
2525

26-
<table class="ietf-table" width="100%">
27-
<tr>
28-
<th width="9%" class="orderField orderField{{ submitted_date|yesno:"Active,Inactive,Reversed" }}">
29-
<a href="?order_by={{ submitted_date|default_if_none:"" }}submitted_date">Date</a>
30-
</th>
31-
<th width="15%" class="orderField orderField{{ from_raw_body|yesno:"Active,Inactive,Reversed" }}">
32-
<a href="?order_by={{ from_raw_body|default_if_none:"" }}from_raw_body">From</a>
33-
</th>
34-
<th width="15%" class="orderField orderField{{ to_body|yesno:"Active,Inactive,Reversed" }}">
35-
<a href="?order_by={{ to_body|default_if_none:"" }}to_body">To</a>
36-
</th>
37-
<th width="9%" class="orderField orderField{{ deadline_date|yesno:"Active,Inactive,Reversed" }}">
38-
<a href="?order_by={{ deadline_date|default_if_none:"" }}deadline_date">Deadline</a>
39-
</th>
40-
<th width="50%" class="orderField orderField{{ title|yesno:"Active,Inactive,Reversed" }}">
41-
<a href="?order_by={{ title|default_if_none:"" }}title">Title</a>
42-
</th>
43-
</tr>
26+
{% include "liaisons/liaisondetail_simple_list.html" %}
4427

45-
{% for liaison in object_list %}
46-
<tr class="{% cycle oddrow,evenrow %}">
47-
<td style="white-space:nowrap;">{{ liaison.submitted_date|date:"Y-m-d" }}</td>
48-
<td>{{ liaison.from_body|escape }}</td>
49-
<td>
50-
{% if liaison.by_secretariat %}
51-
{% if liaison.submitter_email %}
52-
<a href="mailto:{{ liaison.submitter_email}}">{{ liaison.submitter_name|escape }}</a>
53-
{% else %}
54-
{{ liaison.submitter_name|escape }}
55-
{% endif %}
56-
{% else %}
57-
{{ liaison.to_body|escape }}
58-
{% endif %}
59-
</td>
60-
<td>
61-
{{ liaison.deadline_date|default:"--" }}
62-
</td>
63-
<td>
64-
{% if liaison.by_secretariat %}
65-
{% for file in liaison.uploads_set.all %}
66-
<a href="https://datatracker.ietf.org/documents/LIAISON/file{{ file.file_id }}{{ file.file_extension }}">{{ file.file_title|escape }}</a><br/>
67-
{% endfor %}
68-
{% else %}
69-
<a href="{{ liaison.detail_id }}/">{{ liaison.title|escape }}</a>
70-
{% endif %}
71-
</td>
72-
</tr>
73-
{% endfor %}
74-
75-
</table>
7628
{% endblock %}
7729

ietf/templates/liaisons/liaisondetail_simple_list.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
<table class="ietf-table" width="100%">
2-
<tr><th width="9%">Date</th><th width="20%">From</th><th width="20%">To</th><th width="50%">Title</th></tr>
2+
<tr>
3+
<th width="9%" class="orderField orderField{{ submitted_date|yesno:"Active,Inactive,Reversed" }}">
4+
<a href="?order_by={{ submitted_date|default_if_none:"" }}submitted_date">Date</a>
5+
</th>
6+
<th width="15%" class="orderField orderField{{ from_raw_body|yesno:"Active,Inactive,Reversed" }}">
7+
<a href="?order_by={{ from_raw_body|default_if_none:"" }}from_raw_body">From</a>
8+
</th>
9+
<th width="15%" class="orderField orderField{{ to_body|yesno:"Active,Inactive,Reversed" }}">
10+
<a href="?order_by={{ to_body|default_if_none:"" }}to_body">To</a>
11+
</th>
12+
<th width="9%" class="orderField orderField{{ deadline_date|yesno:"Active,Inactive,Reversed" }}">
13+
<a href="?order_by={{ deadline_date|default_if_none:"" }}deadline_date">Deadline</a>
14+
</th>
15+
<th width="50%" class="orderField orderField{{ title|yesno:"Active,Inactive,Reversed" }}">
16+
<a href="?order_by={{ title|default_if_none:"" }}title">Title</a>
17+
</th>
18+
</tr>
319

420
{% for liaison in object_list %}
521
<tr class="{% cycle oddrow,evenrow %}">
@@ -16,6 +32,9 @@
1632
{{ liaison.to_body|escape }}
1733
{% endif %}
1834
</td>
35+
<td>
36+
{{ liaison.deadline_date|default:"--" }}
37+
</td>
1938
<td>
2039
{% if liaison.by_secretariat %}
2140
{% for file in liaison.uploads_set.all %}
@@ -24,7 +43,6 @@
2443
{% else %}
2544
<a href="{{ liaison.detail_id }}/">{{ liaison.title|escape }}</a>
2645
{% endif %}
27-
<span style="display: none" class="liaisonPK">{{ liaison.pk }}</span>
2846
</td>
2947
</tr>
3048
{% endfor %}

static/js/liaisons.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
var cancel_dialog = form.find('#cancel-dialog');
142142
var config = {};
143143
var related_trigger = form.find('#id_related_to');
144+
var related_url = form.find('#id_related_to').parent().find('.listURL').text();
144145
var related_dialog = form.find('#related-dialog');
145146
var unrelate_trigger = form.find('#id_no_related_to');
146147

@@ -257,6 +258,7 @@
257258
};
258259

259260
var selectRelated = function() {
261+
trigger = $(this);
260262
widget = $(this).parent();
261263
url = widget.find('.listURL').text();
262264
title = widget.find('.relatedLiaisonWidgetTitle');
@@ -270,7 +272,12 @@
270272
dataType: 'html',
271273
success: function(response){
272274
related_dialog.html(response);
273-
related_dialog.find('a').click(getRelatedLink);
275+
related_dialog.find('th a').click(function() {
276+
widget.find('.listURL').text(related_url + $(this).attr('href'));
277+
trigger.click();
278+
return false;
279+
});
280+
related_dialog.find('td a').click(getRelatedLink);
274281
}
275282
});
276283
return false;

0 commit comments

Comments
 (0)