zed/server/templates/admin.hbs
2021-09-18 12:57:04 -04:00

80 lines
3.2 KiB
Handlebars

{{#> layout }}
<script>
window.addEventListener("DOMContentLoaded", function () {
let users = document.getElementById("users");
if (users) {
users.addEventListener("change", async function (event) {
const action = event.target.getAttribute("action");
if (action) {
console.log(action, event.target.checked);
const response = await fetch(action, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ admin: event.target.checked })
});
}
});
}
});
</script>
<div class="max-w-screen-lg mx-auto text-main text-white font-extralight p-20">
<h1 class="font-display font-extralight mb-10">Admin</h1>
<h2 class="text-xl font-bold border-b border-gray-300 mb-4">Users</h1>
<table class="table text-white" id="users">
<tr>
<th class="text-left pr-2">GitHub Login</th>
<th class="text-left pr-2">Admin</th>
<th></th>
</tr>
<form action="/users" method="post" class="m-0 mb-4">
<tr>
<td>
<input name="github_login" type="text" class="border border-gray-300 p-1 mr-2 w-48"
placeholder="@github_handle">
</td>
<td>
<input type="checkbox" id="admin" name="admin" value="true">
</td>
<td class="text-right">
<button class="p-1 w-20 text-white rounded-md bg-gray-600 hover:bg-black">Add</button>
</td>
</tr>
</form>
{{#each users}}
<tr>
<form action="/users/{{id}}/delete" method="post">
<td class="py-1 text-white">
{{github_login}}
</td>
<td>
<input action="/users/{{id}}" type="checkbox" {{#if admin}}checked{{/if}}>
</td>
<td class="text-right">
<button class="p-1 w-20 rounded-md bg-gray-600 hover:bg-black text-white">Remove</button>
</td>
</form>
</tr>
{{/each}}
</table>
<h2 class="text-xl font-bold border-b border-gray-300 mb-4 mt-8">Signups</h1>
<table class="table text-white">
{{#each signups}}
<tr>
<form action="/signups/{{id}}/delete" method="post">
<td class="align-top">{{github_login}}</td>
<td class="pl-4 align-top">{{email_address}}</td>
<td class="pl-4 align-top">{{about}}</td>
<td class="text-right">
<button class="p-1 w-20 rounded-md bg-gray-600 hover:bg-black text-white">Remove</button>
</td>
</form>
</tr>
{{/each}}
</table>
</div>
{{/layout}}