From 3b239fa0ff9fe5f8d1a51b137c018560656bfd7a Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Wed, 5 Nov 2014 11:31:33 +0000 Subject: [PATCH] Add JS functionality to edit the relations of a status change document - Legacy-Id: 8586 --- ietf/doc/views_status_change.py | 15 ++--- .../doc/status_change/edit_related_rows.html | 41 +++++++++++++ .../doc/status_change/edit_relations.html | 52 +++------------- ietf/templates/doc/status_change/start.html | 61 +++---------------- .../js/status-change-edit-relations.js | 22 +++++++ 5 files changed, 83 insertions(+), 108 deletions(-) create mode 100644 ietf/templates/doc/status_change/edit_related_rows.html create mode 100644 static/facelift/js/status-change-edit-relations.js diff --git a/ietf/doc/views_status_change.py b/ietf/doc/views_status_change.py index 4d868b238..eecfa16e4 100644 --- a/ietf/doc/views_status_change.py +++ b/ietf/doc/views_status_change.py @@ -399,11 +399,11 @@ def clean_helper(form, formtype): elif k.startswith('statchg_relation_row'): status_fields[k[21:]]=v for key in rfc_fields: - if rfc_fields[key]!="": - if key in status_fields: - new_relations[rfc_fields[key]]=status_fields[key] - else: - new_relations[rfc_fields[key]]=None + if rfc_fields[key]!="": + if key in status_fields: + new_relations[rfc_fields[key]]=status_fields[key] + else: + new_relations[rfc_fields[key]]=None form.relations = new_relations @@ -568,7 +568,7 @@ def edit_relations(request, name): if request.method == 'POST': form = EditStatusChangeForm(request.POST) - if 'Submit' in request.POST and form.is_valid(): + if form.is_valid(): old_relations={} for rel in status_change.relateddocument_set.filter(relationship__slug__in=STATUSCHANGE_RELATIONS): @@ -590,9 +590,6 @@ def edit_relations(request, name): return HttpResponseRedirect(status_change.get_absolute_url()) - elif 'Cancel' in request.POST: - return HttpResponseRedirect(status_change.get_absolute_url()) - else: relations={} for rel in status_change.relateddocument_set.filter(relationship__slug__in=STATUSCHANGE_RELATIONS): diff --git a/ietf/templates/doc/status_change/edit_related_rows.html b/ietf/templates/doc/status_change/edit_related_rows.html new file mode 100644 index 000000000..4ca98a14b --- /dev/null +++ b/ietf/templates/doc/status_change/edit_related_rows.html @@ -0,0 +1,41 @@ + {% for rfc,choice_slug in form.relations.items %} +
+
+
+ +
+
+ +
+
+ +
+
+
+ {% endfor %} + +
+
+
+ +

Enter new affected RFC.

+
+ +
+ +
+
+ +
+
+
diff --git a/ietf/templates/doc/status_change/edit_relations.html b/ietf/templates/doc/status_change/edit_relations.html index 7fef7a258..8c0c89f06 100644 --- a/ietf/templates/doc/status_change/edit_relations.html +++ b/ietf/templates/doc/status_change/edit_relations.html @@ -6,55 +6,12 @@

Edit RFCs affected by status change

-

- {% comment %}XXX FACELIFT:{% endcomment %} - Note: With the redesigned UI, you currently must add new RFCs one by one. -

-
{% csrf_token %} - {% for rfc,choice_slug in form.relations.items %} -
-
-
- -
-
- -
-
- -
-
-
- {% endfor %} + {% include "doc/status_change/edit_related_rows.html" %} -
-
-
- -

Enter new affected RFC.

-
- -
- -
-
-
- - {% if form.non_field_errors %} + {% if form.non_field_errors %}
{{ form.non_field_errors }}
{% endif %} @@ -64,3 +21,8 @@
{% endblock %} + +{% block js %} + +{% endblock %} + diff --git a/ietf/templates/doc/status_change/start.html b/ietf/templates/doc/status_change/start.html index 846a8a000..3f8962d1b 100644 --- a/ietf/templates/doc/status_change/start.html +++ b/ietf/templates/doc/status_change/start.html @@ -14,62 +14,11 @@
{% csrf_token %} - - {% for rfc,choice_slug in form.relations.items %} -
-
-
- -
-
- -
-
- -
-
-
- {% endfor %} + -
-
-
- -

Enter new affected RFC.

-
+ {% include "doc/status_change/edit_related_rows.html" %} -
- -
-
-
- -
-
-

- {% comment %}XXX FACELIFT:{% endcomment %} - Note: 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). -

- -
- - Back -
-

-
-
- -
+
{% bootstrap_form form %} @@ -82,3 +31,7 @@ {% endblock %} + +{% block js %} + +{% endblock %} diff --git a/static/facelift/js/status-change-edit-relations.js b/static/facelift/js/status-change-edit-relations.js new file mode 100644 index 000000000..c77b77c26 --- /dev/null +++ b/static/facelift/js/status-change-edit-relations.js @@ -0,0 +1,22 @@ +$(function () { + var form = $(".content-wrapper form"); + var newRowHtml = form.find(".new-row").get(0).outerHTML; + var counter = 1; + + form.on("click", ".delete", function (e) { + e.preventDefault(); + $(this).closest(".row").remove(); + }); + + form.on("keydown", ".new-row input[type=text]", function () { + var top = $(this).closest(".new-row"); + top.removeClass("new-row"); + top.find(".help-block").remove(); + top.find(".delete").show(); + top.find("input,select").each(function () { + this.name += counter; + }); + ++counter; + top.after(newRowHtml); + }); +});