summaryrefslogtreecommitdiff
path: root/views/manage.html
blob: d7e2b65dedfd62bbb3f42794590e4135109b7544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{% extends "base.html" %}

{% block head %}
	<link rel="stylesheet" href="/styles/manage.css">
	<script type="module">
		// Progressive enhancement – perform form requests without leaving page.

		for (const application of document.querySelectorAll(".applications__item")) {
			for (const form of application.querySelectorAll("form.action")) {
				form.addEventListener("submit", async (event) => {
					event.preventDefault();

					if (!confirm("Are you sure?")) {
						return;
					}

					let ok;
					try {
						const response = await fetch(form.action, {
							method: "POST",
							data: new FormData(form),
						});
						ok = response.ok;
					} catch {
						ok = false;
					}

					if (ok) {
						application.remove();
					} else {
						alert("Something went wrong >w<");
					}
				});
			}
		}
	</script>
{% endblock %}

{% block content %}
	<h1>Manage applications</h1>
	<div class="applications">
		{% for application in applications %}
			<section class="applications__item">
				<span class="application__username">{{ application.username | e }}</span>
				<p>{{ application.motivation | e }}</p>
				<form class="action" method="POST" action="/manage/reject/{{ application.userId | e }}">
					<button class="action__button action__button--reject">Reject</button>
				</form>
				<form class="action" method="POST" action="/manage/accept/{{ application.userId | e }}">
					<button class="action__button action__button--accept">Accept</button>
				</form>
			</section>
		{% endfor %}
	</div>
{% endblock %}