Skip to content

Commit 6af46f9

Browse files
committed
Make user type username to delete as in KSP-SpaceDock#316
1 parent 5e05a70 commit 6af46f9

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

frontend/coffee/admin-users.coffee

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$('.modal-confirm-delete').on 'show.bs.modal', (evt) ->
2+
# Disable final Delete button on modal open
3+
$(evt.target).find('input[type=submit]').prop('disabled', true)
4+
# Clear username confirmation text box on modal open
5+
$(evt.target).find('input[type=text]').val('')
6+
7+
$('.modal-confirm-delete').on 'shown.bs.modal', (evt) ->
8+
# Focus text box on modal open
9+
$(evt.target).find('input[type=text]').focus()
10+
11+
$('.confirm-username').on 'input', (evt) ->
12+
# Enable/disable final Delete button on confirmation text box change
13+
$("#btn-delete-#{evt.target.dataset.userid}").prop('disabled',
14+
evt.target.value != evt.target.dataset.username)

templates/admin-users.html

+23-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
{{ super() }}
44
<style>table td { overflow: hidden; }</style>
55
{% endblock %}
6+
{% block scripts %}
7+
{{ super() }}
8+
<script src="/static/admin-users.js"></script>
9+
{% endblock %}
610
{% block admin_content %}
711
<div class="tab-pane active" id="users">
812
<div class="container admin-container space-left-right">
@@ -69,25 +73,33 @@
6973
</div>
7074
</div>
7175
{% for user in users %}
72-
<div class="modal fade" id="confirm-delete-{{user.id}}" tabindex="-1" role="dialog" aria-labelledby="confirm-delete" aria-hidden="true">
76+
<div class="modal fade modal-confirm-delete" id="confirm-delete-{{user.id}}" tabindex="-1" role="dialog" aria-labelledby="confirm-delete" aria-hidden="true">
7377
<div class="modal-dialog">
7478
<div class="modal-content">
7579
<div class="modal-header">
7680
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
77-
<h4 class="modal-title" id="myModalLabel">Delete User</h4>
81+
<h4 class="modal-title">Delete User</h4>
7882
</div>
79-
<div class="modal-body">
80-
Are you sure you want to delete {{user.username}}?
81-
This cannot be un-done.
82-
</div>
83-
<div class="modal-footer">
84-
<form action="/admin/delete_user/{{ user.id }}" method="POST">
83+
<form action="/admin/delete_user/{{ user.id }}" method="POST">
84+
<div class="modal-body">
85+
<p>Are you sure you want to delete <b>{{user.username}}</b>?
86+
<br>
87+
This cannot be un-done.</p>
88+
<div class="form-group">
89+
<label for="confirm-username">Username:</label>
90+
<input type="text" name="confirm-username"
91+
class="form-control confirm-username"
92+
placeholder="Enter username to confirm"
93+
data-userid="{{user.id}}" data-username="{{user.username}}">
94+
</div>
95+
</div>
96+
<div class="modal-footer">
8597
<a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>
86-
<input type="submit" class="btn btn-danger" value="Delete">
98+
<input type="submit" id="btn-delete-{{user.id}}" class="btn btn-danger" value="Delete" disabled>
8799
<input type="hidden" name="page" value="{{page}}">
88100
<input type="hidden" name="show_non_public" value="{{show_non_public}}">
89-
</form>
90-
</div>
101+
</div>
102+
</form>
91103
</div>
92104
</div>
93105
</div>

0 commit comments

Comments
 (0)