Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kevinvincentals/785cbe89a3a1d1c9235b74e98550be91 to your computer and use it in GitHub Desktop.
Save Kevinvincentals/785cbe89a3a1d1c9235b74e98550be91 to your computer and use it in GitHub Desktop.
{% extends "base.html" %}
{% block content %}
<div class="container">
<h1>Alle brugere</h1>
<div class="d-flex justify-content-between mb-3">
<form class="form-inline">
<label class="sr-only" for="search-field">Søg efter bruger</label>
<input type="text" class="form-control mr-sm-2" id="search-field" placeholder="Søg efter bruger">
</form>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createUserModal">
Opret bruger
</button>
</div>
<table class="table">
<thead>
<tr>
<th>Username</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{% for username in usernames %}
<tr class="user-row">
<td>{{ username }}</td>
<td class="align-middle">
<form method="POST" action="{{ url_for('delete_password', username=username) }}" onsubmit="return confirm('Er du sikker på, at du vil slette brugerens kodeord?');">
<button type="submit" class="btn btn-danger">Slet kodeord</button>
</form>
</td>
<td class="align-middle">
<form method="POST" action="{{ url_for('delete_user', username=username) }}" onsubmit="return confirm('Er du sikker på, at du vil slette brugeren?');">
<button type="submit" class="btn btn-danger">Slet bruger</button>
</form>
</td>
<td class="align-middle">
{% if username in admins %}
<form method="POST" action="{{ url_for('remove_admin', username=username) }}">
<button type="submit" class="btn btn-warning">Fjern admin</button>
</form>
{% else %}
<form method="POST" action="{{ url_for('add_admin', username=username) }}">
<button type="submit" class="btn btn-success">Tilføj admin</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Modal -->
<div class="modal fade" id="createUserModal" tabindex="-1" aria-labelledby="createUserModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="createUserModalLabel">Opret bruger</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="POST" action="{{ url_for('create_user') }}">
<div class="mb-3">
<label for="username" class="form-label">Brugernavn</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<button type="submit" class="btn btn-primary">Opret</button>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
// Add keyup event listener to search field
$("#search-field").on("keyup", function() {
var searchValue = $(this).val().toLowerCase();
// Loop through user rows and hide/show them based on search value
$(".user-row").each(function() {
var username = $(this).find("td:first-child").text().toLowerCase();
if (username.indexOf(searchValue) === -1) {
$(this).hide();
} else {
$(this).show();
}
});
});
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment