Add JS functionality to edit the relations of a status change document

- Legacy-Id: 8586
This commit is contained in:
Ole Laursen 2014-11-05 11:31:33 +00:00
parent 8245f4c9b3
commit 3b239fa0ff
5 changed files with 83 additions and 108 deletions

View file

@ -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):

View file

@ -0,0 +1,41 @@
{% for rfc,choice_slug in form.relations.items %}
<div class="form-group">
<div class="row">
<div class="col-md-5">
<input class="form-control" name="new_relation_row_{{rfc}}" type="text" value="{{rfc}}">
</div>
<div class="col-md-5">
<select class="form-control" name="statchg_relation_row_{{rfc}}">
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
{% for rel in relation_slugs %}
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<button class="btn btn-danger delete">Delete</button>
</div>
</div>
</div>
{% endfor %}
<div class="form-group new-row">
<div class="row">
<div class="col-md-5">
<input name="new_relation_row_" type="text" class="form-control" placeholder="rfc...">
<p class="help-block">Enter new affected RFC.</p>
</div>
<div class="col-md-5">
<select class="form-control" name="statchg_relation_row_">
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
{% for rel in relation_slugs %}
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<button class="btn btn-danger delete" style="display:none">Delete</button>
</div>
</div>
</div>

View file

@ -6,55 +6,12 @@
<h1>Edit RFCs affected by status change</h1>
<p class="alert alert-info">
{% comment %}XXX FACELIFT:{% endcomment %}
<b>Note:</b> With the redesigned UI, you currently must add new RFCs one by one.
</p>
<form role="form" method="post">
{% csrf_token %}
{% for rfc,choice_slug in form.relations.items %}
<div class="form-group">
<div id="row_{{rfc}}" class="row">
<div class="col-md-5">
<input class="form-control" id="new_relation_row_{{rfc}}" name="new_relation_row_{{rfc}}"
type="text" value="{{rfc}}">
</div>
<div class="col-md-5">
<select class="form-control" id="statchg_relation_row_{{rfc}}" name="statchg_relation_row_{{rfc}}">
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
{% for rel in relation_slugs %}
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<button class="btn btn-danger" onclick="$('#row_{{rfc}}').remove(); return false;">Delete</button>
</div>
</div>
</div>
{% endfor %}
{% include "doc/status_change/edit_related_rows.html" %}
<div class="form-group">
<div id="relation_row_0" class="row">
<div class="col-md-5">
<input id="new_relation_row_0" name="new_relation_row_0" type="text" class="form-control" placeholder="rfc...">
<p class="help-block">Enter new affected RFC.</p>
</div>
<div class="col-md-5">
<select class="form-control" id="statchg_relation_row_0" name="statchg_relation_row_0">
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
{% for rel in relation_slugs %}
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
{% endfor %}
</select>
</div>
</div>
</div>
{% if form.non_field_errors %}
{% if form.non_field_errors %}
<div class="alert alert-danger">{{ form.non_field_errors }}</div>
{% endif %}
@ -64,3 +21,8 @@
</div>
</form>
{% endblock %}
{% block js %}
<script src="/facelift/js/status-change-edit-relations.js"></script>
{% endblock %}

View file

@ -14,62 +14,11 @@
<form class="start-rfc-status-change-review" role="form" method="post">
{% csrf_token %}
<label class="control-label">Affected RFCs</label>
{% for rfc,choice_slug in form.relations.items %}
<div class="form-group">
<div id="relation_row_{{rfc}}" class="row">
<div class="col-md-5">
<input class="form-control" id="new_relation_row_{{rfc}}" name="new_relation_row_{{rfc}}" type="text" value="{{rfc}}">
</div>
<div class="col-md-5">
<select class="form-control" id="statchg_relation_row_{{rfc}}" name="statchg_relation_row_{{rfc}}">
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
{% for rel in relation_slugs %}
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<button class="btn btn-danger" onclick="$('#relation_row_{{rfc}}').remove(); return false;">Delete</button>
</div>
</div>
</div>
{% endfor %}
<label class="control-label">Affected RFCs</label>
<div class="form-group">
<div id="relation_row_0" class="row">
<div class="col-md-5">
<input class="form-control" id="new_relation_row_0" name="new_relation_row_0" type="text" placeholder="rfc...">
<p class="help-block">Enter new affected RFC.</p>
</div>
{% include "doc/status_change/edit_related_rows.html" %}
<div class="col-md-5">
<select class="form-control" id="statchg_relation_row_0" name="statchg_relation_row_0">
<option value="" {% if choice_slug == "" %}selected{% endif %}>(None)</option>
{% for rel in relation_slugs %}
<option value="{{rel.slug}}" {% if choice_slug == rel.slug %}selected{%endif%}>{{rel.name}}</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10">
<p class="alert alert-danger">
{% comment %}XXX FACELIFT:{% endcomment %}
<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).
</p>
<div class="buttonlist">
<button type="submit" class="btn btn-primary" name="submit_response">Submit</button>
<a class="btn btn-default pull-right" href="{{ back_url }}">Back</a>
</div>
<p></p>
</div>
</div>
<div class="row">
<div class="row">
<div class="col-md-10">
{% bootstrap_form form %}
@ -82,3 +31,7 @@
</form>
{% endblock %}
{% block js %}
<script src="/facelift/js/status-change-edit-relations.js"></script>
{% endblock %}

View file

@ -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);
});
});