45 lines
1.6 KiB
HTML
45 lines
1.6 KiB
HTML
{% extends 'base.html' %}
|
|
{% block title %}Admin{% endblock %}
|
|
{% set adminLink = 'active' %}
|
|
{% block content %}
|
|
<h1 class="mb-3">Admin panel</h1>
|
|
<div id="response-container"></div>
|
|
<form hx-post="{{ url_for('admin.index') }}" hx-target="#response-container" hx-swap="none">
|
|
<input type="hidden" name="action" value="update_word_blacklist">
|
|
<div class="form-group mb-3">
|
|
<label for="blacklist"><h2>Word blacklist</h2></label>
|
|
<textarea id="blacklist" name="blacklist" style="height: 400px; resize: vertical;" placeholder="Word blacklist" class="form-control">{{ blacklist }}</textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">
|
|
<span class="spinner-border spinner-border-sm htmx-indicator" aria-hidden="true"></span>
|
|
<span class="visually-hidden" role="status">Loading...</span>
|
|
Save
|
|
</button>
|
|
</form>
|
|
|
|
{% endblock %}
|
|
{% block scripts %}
|
|
<script>
|
|
const appendAlert = (elementId, message, type) => {
|
|
const alertPlaceholder = document.getElementById(elementId);
|
|
const alertHtml = `
|
|
<div class="alert alert-${type} alert-dismissible" role="alert">
|
|
<div>${message}</div>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
`;
|
|
|
|
alertPlaceholder.innerHTML = alertHtml;
|
|
}
|
|
|
|
document.addEventListener('htmx:afterRequest', function(event) {
|
|
const jsonResponse = event.detail.xhr.response;
|
|
if (jsonResponse) {
|
|
const parsed = JSON.parse(jsonResponse);
|
|
const msgType = event.detail.successful ? 'success' : 'error';
|
|
const targetElementId = event.detail.target.id;
|
|
appendAlert(targetElementId, parsed.message, msgType);
|
|
}
|
|
})
|
|
</script>
|
|
{% endblock %}
|