Skip to content

Commit 7928d3b

Browse files
authored
Merge pull request #579 from OpenUpSA/fix/delete-committee
Send csrf_token along with DELETE request
2 parents e8782cb + 27f8d08 commit 7928d3b

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

pmg/templates/admin/my_edit.html

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
{% extends 'admin/model/edit.html' %}
22

33
{% block body %}
4-
{% if admin_view.frontend_url(model) %}
5-
<div class="pull-right">
6-
{% set alert_url = admin_view.alert_url(model) %}
7-
{% if alert_url %}
8-
<a href="{{ admin_view.alert_url(model) }}" class="btn btn-default"><i class="fa fa-envelope"></i> Send alert</a>
9-
{% endif %}
4+
{% if admin_view.frontend_url(model) %}
5+
<div class="pull-right">
6+
{% set alert_url = admin_view.alert_url(model) %}
7+
{% if alert_url %}
8+
<a href="{{ admin_view.alert_url(model) }}" class="btn btn-default"><i class="fa fa-envelope"></i> Send alert</a>
9+
{% endif %}
1010
{% if admin_view.name == "Committees" %}
1111
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delete_modal">
12-
Delete {{admin_view.name}}
12+
Delete {{admin_view.name}}
1313
</button>
1414
<div class="modal fade" id="delete_modal" tabindex="-1" role="dialog">
15-
<div class="modal-dialog" role="document">
16-
<div class="modal-content">
17-
<div class="panel panel-danger">
18-
<div class="panel-heading">Delete Record</div>
19-
<div class="panel-body">
20-
<p>You are about to delete this record. This action cannot be undone.</p>
21-
<p>Would you like to proceed?</p>
22-
<div id="reason" class="alert alert-warning" role="alert" style="display:none">
23-
</div>
24-
</div>
25-
<div class="panel-footer text-center">
26-
<button type="button" class="btn btn-secondary" id="cancel_delete">Cancel</button>
27-
<button type="button" class="btn btn-danger" id="confirm_delete">Delete</button>
15+
<div class="modal-dialog" role="document">
16+
<div class="modal-content">
17+
<div class="panel panel-danger">
18+
<div class="panel-heading">Delete Record</div>
19+
<div class="panel-body">
20+
<p>You are about to delete this record. This action cannot be undone.</p>
21+
<p>Would you like to proceed?</p>
22+
<div id="reason" class="alert alert-warning" role="alert" style="display:none">
23+
</div>
24+
</div>
25+
<div class="panel-footer text-center">
26+
<button type="button" class="btn btn-secondary" id="cancel_delete">Cancel</button>
27+
<button type="button" class="btn btn-danger" id="confirm_delete">Delete</button>
28+
</div>
29+
</div>
2830
</div>
29-
</div>
3031
</div>
31-
</div>
3232
</div>
3333
<script>
34-
window.addEventListener('load', function(event){
35-
$("#cancel_delete").click(function() {
36-
$("#delete_modal").modal("toggle");
37-
});
38-
$("#confirm_delete").click(function(event) {
39-
event.preventDefault();
40-
console.log('deleting the model');
41-
$.ajax({
42-
url: "../delete?id={{ model.id }}",
43-
type: "DELETE",
44-
success: function(data){
45-
if (data.success == 'ok'){
46-
console.log("Deleted");
47-
window.location.replace("{{ return_url }}");
48-
}else{
49-
$('#reason').css('display','block');
50-
$('#reason').html(data.reason);
51-
}
52-
},
53-
error: function(xhr, data, error){
54-
console.log("unable to delete model");
55-
$('#reason').html(data.reason);
56-
console.log(xhr.statusCode);
57-
console.log(xhr.statusText);
58-
console.log(error);
59-
}
60-
});
61-
});
62-
});
34+
window.addEventListener('load', function (event) {
35+
$("#cancel_delete").click(function () {
36+
$("#delete_modal").modal("toggle");
37+
});
38+
$("#confirm_delete").click(function (event) {
39+
event.preventDefault();
40+
$.ajax({
41+
url: "../delete?id={{ model.id }}",
42+
type: "DELETE",
43+
beforeSend: function (xhr) {
44+
xhr.setRequestHeader("X-CSRFToken", $('[name=csrf_token]').val());
45+
},
46+
success: function (data) {
47+
if (data.success == 'ok') {
48+
window.location.replace("{{ return_url }}");
49+
} else {
50+
$('#reason').css('display', 'block');
51+
$('#reason').html(data.reason);
52+
}
53+
},
54+
error: function (xhr, data, error) {
55+
$('#reason').html(data.reason);
56+
console.log(xhr.statusCode);
57+
console.log(xhr.statusText);
58+
console.log(error);
59+
}
60+
});
61+
});
62+
});
6363
</script>
6464
{% endif %}
6565

66-
<a href="{{ admin_view.frontend_url(model) }}" class="btn btn-primary"><i class="fa fa-eye"></i> View page</a>
67-
</div>
68-
{% endif %}
66+
<a href="{{ admin_view.frontend_url(model) }}" class="btn btn-primary"><i class="fa fa-eye"></i> View page</a>
67+
</div>
68+
{% endif %}
6969

70-
{% if admin_view.name == 'Users' %}
71-
{% include "admin/_user_actions.html" %}
72-
{% endif %}
70+
{% if admin_view.name == 'Users' %}
71+
{% include "admin/_user_actions.html" %}
72+
{% endif %}
7373

74-
<h2>Edit {{ admin_view.name }}</h2>
74+
<h2>Edit {{ admin_view.name }}</h2>
7575

76-
{{ super() }}
77-
{% endblock %}
76+
{{ super() }}
77+
{% endblock %}

0 commit comments

Comments
 (0)