Compare commits

..

2 commits

2 changed files with 88 additions and 1 deletions

View file

@ -12,7 +12,7 @@ a:hover {
} }
</style> </style>
</head> </head>
<body> <body hx-on::response-error="showErrorDialog(event)">
<main> <main>
<nav> <nav>
<ul> <ul>
@ -37,5 +37,38 @@ a:hover {
{{ inner | safe }} {{ inner | safe }}
</article> </article>
</main> </main>
<dialog id="error-dialog">
<article>
<header>
<button aria-label="Close" rel="prev" onclick="this.closest('dialog').close()"></button>
<h5>Failed web request</h5>
</header>
<p id="error-message">Failed web request</p>
</article>
</dialog>
<script>
function showErrorDialog(evt) {
// TODO exclude certain error codes, e.g. 400 bad request
const xhr = evt.detail.xhr;
const errorMessage = document.getElementById('error-message');
let message = 'An unexpected error occurred.';
if (xhr.status === 401) {
message = 'You need to log in.';
} else if (xhr.status === 403) {
message = 'Access denied.';
} else if (xhr.status === 404) {
message = 'Resource not found.';
} else if (xhr.status === 500) {
message = 'Server error occurred.';
}
errorMessage.textContent = message;
document.getElementById('error-dialog').showModal();
}
</script>
</body> </body>
</html> </html>

View file

@ -2,6 +2,10 @@
{% block inner %} {% block inner %}
<h3>Users</h3> <h3>Users</h3>
<button
onclick="document.getElementById('create-user-form').reset(); document.getElementById('create-user-modal').showModal()"
id="create-user">Create new user</button>
<input <input
type="text" id="username" name="username" type="text" id="username" name="username"
hx-get="/administration/users" hx-get="/administration/users"
@ -48,4 +52,54 @@
{% endif %} {% endif %}
</tbody> </tbody>
</table> </table>
<dialog id="create-user-modal">
<article>
<header>
<button
aria-label="Close"
rel="prev"
onclick="document.getElementById('create-user-modal').close()"
class="close-button"></button>
<h5>Create User</h5>
</header>
<div class="content">
<form id="create-user-form">
<fieldset>
<label>
Username
<input name="username"
placeholder="Username"
/>
</label>
<label>
Admin
<input name="admin"
type="checkbox"
/>
</label>
<label>
Password
<input type="password"
name="password"
placeholder="Password"
/>
</label>
<label>
Confirm password
<input type="password"
name="password-confirm"
placeholder="Password"
/>
</label>
</fieldset>
<input type="submit"
value="Create user"
/>
</form>
</div>
</article>
</dialog>
{% endblock %} {% endblock %}