Commit 61763ca9 authored by Okhin's avatar Okhin

Fixing the Me Too! form

parent 54b78bc0
......@@ -8,67 +8,81 @@
{% endblock %}
{% block scripts %}
<script type="text/javascript">
$("#lookup_btn").click(function(event) {
event.preventDefault();
$.ajax({
dataType: "json",
url: "/lookup/",
data: {
country: $("#id_country").val(),
operator: $("#id_operator").val(),
contract: $("#id_contract").val(),
media: $("#id_media").val(),
type: $("#id_type").val(),
},
success: function(data) {
var filtered = data.filter(function(data) {
return data.fields.state in ["ooscope", "duplicate"]
});
if (filtered.length == 0) {
$("#lookup_btn").parent().parent().hide();
$("#collapseField").collapse('show');
return;
}
<script type="text/javascript">
$('.metoo').submit(function(event) {
event.preventDefault();
var form = $(this);
var pk = form.attr("id").split("-")[1];
var email = form.find("#email-" + pk).val();
console.log("pk: " + pk + "email: " + email);
filtered = filtered.slice(0, 10);
$.each(filtered, function(key, obj) {
if (obj.fields.state in ["ooscope", "duplicate"]) {
return;
};
$("#modal-list").append(
"<dt>" + obj.fields.resource + "</dt>" +
"<dd><p>" + obj.fields.editorial + "</p>" +
"<div class=\"confirm\"><a class=\"btn btn-default\">{% trans "Me too!" %}</a>" +
"<div class=\"info-validate float-confirm\">" +
"<form method=\"get\" action=\"\" id=\"i" + obj.pk + "\" class=\"confirm_form\">" +
"<div>" +
"<label>{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>" +
"<input type=\"text\" name=\"email\" />" +
"<input type=\"hidden\" value=\"{{obj.pk}}\" />" +
"<input type=\"submit\" value=\"{% trans "Ok" %}\" />" +
"</div>" +
"</form>" +
"</div>" +
"</dd>"
);
});
$('#similar_modal').modal('show');
console.log("Modal displayed");
},
error: function(xhr, status, err) {
console.log(err, xhr);
}
});
$.ajax({
url: "/confirm/" + pk + "/" + email,
success: function(data) {
form.find("div").html(data);
}
});
}
$("#lookup_btn").click(function(event) {
event.preventDefault();
$.ajax({
dataType: "json",
url: "/lookup/",
data: {
country: $("#id_country").val(),
operator: $("#id_operator").val(),
contract: $("#id_contract").val(),
media: $("#id_media").val(),
type: $("#id_type").val(),
},
success: function(data) {
var filtered = data.filter(function(data) {
return data.fields.state in ["ooscope", "duplicate"]
});
if (filtered.length == 0) {
$("#lookup_btn").parent().parent().hide();
$("#collapseField").collapse('show');
return;
}
$("#btn_dismiss").click(function(event) {
event.preventDefault();
$("#similar_modal").modal('hide');
$("#lookup_btn").parent().parent().hide();
$("#collapseField").collapse('show');
filtered = filtered.slice(0, 10);
$.each(filtered, function(key, obj) {
if (obj.fields.state in ["ooscope", "duplicate"]) {
return;
};
$("#modal-list").append(
"<dt>" + obj.fields.resource + "</dt>" +
"<dd><p>" + obj.fields.editorial + "</p>" +
"<div class=\"confirm\"><a class=\"btn btn-default\">{% trans "Me too!" %}</a>" +
"<div class=\"info-validate float-confirm\">" +
"<form method=\"get\" action=\"\" id=\"i" + obj.pk + "\" class=\"confirm_form\">" +
"<div>" +
"<label>{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>" +
"<input type=\"text\" name=\"email\" />" +
"<input type=\"hidden\" value=\"{{obj.pk}}\" />" +
"<input type=\"submit\" value=\"{% trans "Ok" %}\" />" +
"</div>" +
"</form>" +
"</div>" +
"</dd>"
);
});
$('#similar_modal').modal('show');
console.log("Modal displayed");
},
error: function(xhr, status, err) {
console.log(err, xhr);
}
});
</script>
});
$("#btn_dismiss").click(function(event) {
event.preventDefault();
$("#similar_modal").modal('hide');
$("#lookup_btn").parent().parent().hide();
$("#collapseField").collapse('show');
});
</script>
{% endblock %}
{%block content%}
......@@ -106,15 +120,15 @@
<tr>
<td><a href="{{ violation.get_absolute_url }}">{{ violation.operator }} ({{ violation.country|country }}) {{ violation.contract }}</a>
<div class="well collapse" id="info-{{ violation.pk }}">
<form method="post" action="/confirm/{{ violation.pk }}" id="{{ violation.pk }}">
<form method="post" class="metoo" action="/confirm/{{ violation.pk }}" id="{{ violation.pk }}">
<div class="form-group form-inline">
<label for"email-{{ violation.pk }}">{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
{% csrf_token %}
<input type="email" id="email-{{ violation.pk }}" class="form-control" name="email" placeholder="Email"/>
<input type="hidden" value="{{ violation.pk }}" />
<input type="hidden" id="id-{{ violation.pk }}" value="{{ violation.pk }}" />
<div class="btn-group" role="group" aria-label="confirm-deny">
<button class="btn btn-success">{% trans "OK" %}</ button>
<button data-toggle="collapse" data-target="#info-{{ violation.pk}}" aria-expanded="false" aria-controls="info-{{ volation.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button>
<button data-toggle="collapse" data-target="#info-{{ violation.pk}}" aria-expanded="false" aria-controls="info-{{ volation.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button>
</div>
</div>
</form>
......@@ -146,13 +160,13 @@
</div>
<div class="panel-body">
{% if forms.error %}
{% for field in form %}
{% for error in field.error %}
<div class="alert alert-error">
{{ error|escape }}
</div>
{% endfor %}
{% endfor %}
{% for field in form %}
{% for error in field.error %}
<div class="alert alert-error">
{{ error|escape }}
</div>
{% endfor %}
{% endfor %}
{% endif %}
<p>{% trans "Please report cases of zero-rating (services which are excluded from your download limit), specialised services or the blocking, throttling or prioritisation of online services. For a more detailed description of what to report, check our <a href='/about/#guidelines'>guidelines</a>." %}
<form name="addForm" enctype="multipart/form-data" action="/" method="post" class="form">
......@@ -178,7 +192,7 @@
{% bootstrap_field form.nick %}
{% bootstrap_field form.captcha %}
{% buttons %}
<button type="submit" class="btn btn-primary">{% trans "save" %}</button>
<button type="submit" class="btn btn-primary">{% trans "save" %}</button>
{% endbuttons %}
</div>
</form>
......@@ -202,7 +216,7 @@
<p>{% trans "Those are cases that might be similar to yours, please feel free to add your input on those cases instead of adding yours if they overlap." %}</p>
<dl id="modal-list">
</dl>
</table>
</table>
</div>
<div class="modal-footer">
<button type="button" id="btn_dismiss" class="btn btn-default" data-dismiss="modal">{% trans "Dismiss" %}</button>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment