zkt25/z1/templates/index.html

52 lines
1.5 KiB
HTML

<!DOCTYPE html>
<html lang="sk">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Správa používateľov</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
<div class="container">
<h1>Zoznam používateľov</h1>
<ul id="user-list">
{% for user in users %}
<li>
{{ user[1] }}
<button class="delete-btn" onclick="deleteUser('{{ user[0] }}')">Odstrániť</button>
</li>
{% endfor %}
</ul>
<h2>Pridať používateľa</h2>
<input type="text" id="username" placeholder="Zadajte meno">
<button onclick="addUser()">Pridať</button>
</div>
<script>
function addUser() {
const name = document.getElementById("username").value;
if (!name) {
alert("Zadajte meno!");
return;
}
fetch("/add_user", {
method: "POST",
body: new URLSearchParams({ name }),
headers: { "Content-Type": "application/x-www-form-urlencoded" }
})
.then(response => response.json())
.then(() => location.reload());
}
function deleteUser(id) {
fetch(`/delete_user/${id}`, { method: "POST" })
.then(response => response.json())
.then(() => location.reload());
}
</script>
</body>
</html>