Skip to content

Commit 3b239fa

Browse files
committed
Add JS functionality to edit the relations of a status change document
- Legacy-Id: 8586
1 parent 8245f4c commit 3b239fa

5 files changed

Lines changed: 83 additions & 108 deletions

File tree

ietf/doc/views_status_change.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ def clean_helper(form, formtype):
399399
elif k.startswith('statchg_relation_row'):
400400
status_fields[k[21:]]=v
401401
for key in rfc_fields:
402-
if rfc_fields[key]!="":
403-
if key in status_fields:
404-
new_relations[rfc_fields[key]]=status_fields[key]
405-
else:
406-
new_relations[rfc_fields[key]]=None
402+
if rfc_fields[key]!="":
403+
if key in status_fields:
404+
new_relations[rfc_fields[key]]=status_fields[key]
405+
else:
406+
new_relations[rfc_fields[key]]=None
407407

408408
form.relations = new_relations
409409

@@ -568,7 +568,7 @@ def edit_relations(request, name):
568568

569569
if request.method == 'POST':
570570
form = EditStatusChangeForm(request.POST)
571-
if 'Submit' in request.POST and form.is_valid():
571+
if form.is_valid():
572572

573573
old_relations={}
574574
for rel in status_change.relateddocument_set.filter(relationship__slug__in=STATUSCHANGE_RELATIONS):
@@ -590,9 +590,6 @@ def edit_relations(request, name):
590590

591591
return HttpResponseRedirect(status_change.get_absolute_url())
592592

593-
elif 'Cancel' in request.POST:
594-
return HttpResponseRedirect(status_change.get_absolute_url())
595-
596593
else:
597594
relations={}
598595
for rel in status_change.relateddocument_set.filter(relationship__slug__in=STATUSCHANGE_RELATIONS):
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{% for rfc,choice_slug in form.relations.items %}
2+
<div class="form-group">
3+
<div class="row">
4+
<div class="col-md-5">
5+
<input class="form-control" name="new_relation_row_{{rfc}}" type="text" value="{{rfc}}">
6+
</div>
7+
<div class="col-md-5">
8+
<select class="form-control" name="statchg_relation_row_{{rfc}}">
9+
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
10+
{% for rel in relation_slugs %}
11+
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
12+
{% endfor %}
13+
</select>
14+
</div>
15+
<div class="col-md-2">
16+
<button class="btn btn-danger delete">Delete</button>
17+
</div>
18+
</div>
19+
</div>
20+
{% endfor %}
21+
22+
<div class="form-group new-row">
23+
<div class="row">
24+
<div class="col-md-5">
25+
<input name="new_relation_row_" type="text" class="form-control" placeholder="rfc...">
26+
<p class="help-block">Enter new affected RFC.</p>
27+
</div>
28+
29+
<div class="col-md-5">
30+
<select class="form-control" name="statchg_relation_row_">
31+
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
32+
{% for rel in relation_slugs %}
33+
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
34+
{% endfor %}
35+
</select>
36+
</div>
37+
<div class="col-md-2">
38+
<button class="btn btn-danger delete" style="display:none">Delete</button>
39+
</div>
40+
</div>
41+
</div>

ietf/templates/doc/status_change/edit_relations.html

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,12 @@
66

77
<h1>Edit RFCs affected by status change</h1>
88

9-
<p class="alert alert-info">
10-
{% comment %}XXX FACELIFT:{% endcomment %}
11-
<b>Note:</b> With the redesigned UI, you currently must add new RFCs one by one.
12-
</p>
13-
149
<form role="form" method="post">
1510
{% csrf_token %}
1611

17-
{% for rfc,choice_slug in form.relations.items %}
18-
<div class="form-group">
19-
<div id="row_{{rfc}}" class="row">
20-
<div class="col-md-5">
21-
<input class="form-control" id="new_relation_row_{{rfc}}" name="new_relation_row_{{rfc}}"
22-
type="text" value="{{rfc}}">
23-
</div>
24-
<div class="col-md-5">
25-
<select class="form-control" id="statchg_relation_row_{{rfc}}" name="statchg_relation_row_{{rfc}}">
26-
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
27-
{% for rel in relation_slugs %}
28-
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
29-
{% endfor %}
30-
</select>
31-
</div>
32-
<div class="col-md-2">
33-
<button class="btn btn-danger" onclick="$('#row_{{rfc}}').remove(); return false;">Delete</button>
34-
</div>
35-
</div>
36-
</div>
37-
{% endfor %}
38-
39-
<div class="form-group">
40-
<div id="relation_row_0" class="row">
41-
<div class="col-md-5">
42-
<input id="new_relation_row_0" name="new_relation_row_0" type="text" class="form-control" placeholder="rfc...">
43-
<p class="help-block">Enter new affected RFC.</p>
44-
</div>
45-
46-
<div class="col-md-5">
47-
<select class="form-control" id="statchg_relation_row_0" name="statchg_relation_row_0">
48-
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
49-
{% for rel in relation_slugs %}
50-
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
51-
{% endfor %}
52-
</select>
53-
</div>
54-
</div>
55-
</div>
12+
{% include "doc/status_change/edit_related_rows.html" %}
5613

57-
{% if form.non_field_errors %}
14+
{% if form.non_field_errors %}
5815
<div class="alert alert-danger">{{ form.non_field_errors }}</div>
5916
{% endif %}
6017

@@ -64,3 +21,8 @@ <h1>Edit RFCs affected by status change</h1>
6421
</div>
6522
</form>
6623
{% endblock %}
24+
25+
{% block js %}
26+
<script src="/facelift/js/status-change-edit-relations.js"></script>
27+
{% endblock %}
28+

ietf/templates/doc/status_change/start.html

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,11 @@ <h1>Begin RFC status change review</h1>
1414
<form class="start-rfc-status-change-review" role="form" method="post">
1515
{% csrf_token %}
1616

17-
<label class="control-label">Affected RFCs</label>
18-
{% for rfc,choice_slug in form.relations.items %}
19-
<div class="form-group">
20-
<div id="relation_row_{{rfc}}" class="row">
21-
<div class="col-md-5">
22-
<input class="form-control" id="new_relation_row_{{rfc}}" name="new_relation_row_{{rfc}}" type="text" value="{{rfc}}">
23-
</div>
24-
<div class="col-md-5">
25-
<select class="form-control" id="statchg_relation_row_{{rfc}}" name="statchg_relation_row_{{rfc}}">
26-
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
27-
{% for rel in relation_slugs %}
28-
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
29-
{% endfor %}
30-
</select>
31-
</div>
32-
<div class="col-md-2">
33-
<button class="btn btn-danger" onclick="$('#relation_row_{{rfc}}').remove(); return false;">Delete</button>
34-
</div>
35-
</div>
36-
</div>
37-
{% endfor %}
38-
39-
<div class="form-group">
40-
<div id="relation_row_0" class="row">
41-
<div class="col-md-5">
42-
<input class="form-control" id="new_relation_row_0" name="new_relation_row_0" type="text" placeholder="rfc...">
43-
<p class="help-block">Enter new affected RFC.</p>
44-
</div>
17+
<label class="control-label">Affected RFCs</label>
4518

46-
<div class="col-md-5">
47-
<select class="form-control" id="statchg_relation_row_0" name="statchg_relation_row_0">
48-
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
49-
{% for rel in relation_slugs %}
50-
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
51-
{% endfor %}
52-
</select>
53-
</div>
54-
</div>
55-
</div>
19+
{% include "doc/status_change/edit_related_rows.html" %}
5620

57-
<div class="row">
58-
<div class="col-md-10">
59-
<p class="alert alert-danger">
60-
{% comment %}XXX FACELIFT:{% endcomment %}
61-
<b>Note:</b> With the redesigned UI, you currently must add new affected RFCs one by one, hitting submit each time. Only when the list of affected RFCs is complete and correct, move on to fill out the bottom part of the form (and do a final submit).
62-
</p>
63-
64-
<div class="buttonlist">
65-
<button type="submit" class="btn btn-primary" name="submit_response">Submit</button>
66-
<a class="btn btn-default pull-right" href="{{ back_url }}">Back</a>
67-
</div>
68-
<p></p>
69-
</div>
70-
</div>
71-
72-
<div class="row">
21+
<div class="row">
7322
<div class="col-md-10">
7423
{% bootstrap_form form %}
7524

@@ -82,3 +31,7 @@ <h1>Begin RFC status change review</h1>
8231

8332
</form>
8433
{% endblock %}
34+
35+
{% block js %}
36+
<script src="/facelift/js/status-change-edit-relations.js"></script>
37+
{% endblock %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$(function () {
2+
var form = $(".content-wrapper form");
3+
var newRowHtml = form.find(".new-row").get(0).outerHTML;
4+
var counter = 1;
5+
6+
form.on("click", ".delete", function (e) {
7+
e.preventDefault();
8+
$(this).closest(".row").remove();
9+
});
10+
11+
form.on("keydown", ".new-row input[type=text]", function () {
12+
var top = $(this).closest(".new-row");
13+
top.removeClass("new-row");
14+
top.find(".help-block").remove();
15+
top.find(".delete").show();
16+
top.find("input,select").each(function () {
17+
this.name += counter;
18+
});
19+
++counter;
20+
top.after(newRowHtml);
21+
});
22+
});

0 commit comments

Comments
 (0)