ban_form.html: implement post linking UI

This commit is contained in:
Zankaria 2025-08-31 00:09:02 +02:00
parent baf0e030ed
commit b45df77544

View file

@ -6,11 +6,29 @@
{% if reasons %}
<script type="text/javascript">
$(document).ready(function(){
document.addEventListener("DOMContentLoaded", function() {
{% for key, reason in reasons %}
var data_{{ key }} = '{"reason":"{{ reason.reason|escape('js') }}","message":"{{ reason.reason|escape('js') }}","length":"{{ reason.length|escape('js') }}"}';
$('#reason-selector-id-{{ key }}').click(function() { populateFormJQuery('#ban-form-id', $.parseJSON(data_{{ key }})); });
{% endfor %}
const context_post = document.getElementById('context-post');
context_post.disabled = document.getElementById('context-board-no').checked;
document.getElementById('context-board-no').addEventListener('change', function(e) {
context_post.disabled = e.currentTarget.checked;
});
const boards = [
{% for b in boards %}
'{{ b.uri }}',
{% endfor %}
];
boards.forEach(b => {
document.getElementById(`context-board-${b}`).addEventListener('change', function(e) {
context_post.disabled = false;
});
});
});
</script>
{% endif %}
@ -25,9 +43,8 @@ $(document).ready(function(){
{% if thread %}
<input type="hidden" name="thread" value="{{ thread }}">
{% endif %}
<table>
<tr>
<th>
<label for="ip">{% trans 'IP' %} <span class="unimportant">{% trans '(or subnet)' %}</span></label>
@ -54,8 +71,8 @@ $(document).ready(function(){
<label for="message">{% trans 'Message' %}</label>
</th>
<td>
<input type="checkbox" id="public_message" name="public_message"{% if config.mod.check_ban_message %} checked{% endif %}>
<input type="text" name="message" id="message" size="35" maxlength="200" value="{{ config.mod.default_ban_message|e }}">
<input type="checkbox" id="public_message" name="public_message"{% if config.mod.check_ban_message %} checked{% endif %}>
<input type="text" name="message" id="message" size="35" maxlength="200" value="{{ config.mod.default_ban_message|e }}">
<span class="unimportant">({% trans 'public; attached to post' %})</span>
<script type="text/javascript">
document.getElementById('message').disabled = !document.getElementById('public_message').checked;
@ -71,7 +88,7 @@ $(document).ready(function(){
<label for="length">{% trans 'Length' %}</label>
</th>
<td>
<input type="text" name="length" id="length" size="20" maxlength="43" value="1h">
<input type="text" name="length" id="length" size="20" maxlength="43" value="1h">
<span class="unimportant">(eg. "2d1h30m" or "2 days", empty is permaban)</span></td>
</tr>
<tr>
@ -84,7 +101,7 @@ $(document).ready(function(){
<em>{% trans 'all boards' %}</em>
</label>
</li>
{% for b in boards %}
<li>
<input type="radio" name="board" value="{{ b.uri }}" id="ban-board-{{ b.uri }}"{% if board == b.uri %} checked{% endif %}>
@ -96,6 +113,35 @@ $(document).ready(function(){
</ul>
</td>
</tr>
<tr>
<th>{% trans 'Context post' %}</th>
<td>
<input type="text" name="context-post" id="context-post"/>
<span class="unimportant">Specify the post you want the user to see as context</span></td>
</td>
</tr>
<tr>
<th>{% trans 'Context board' %}</th>
<td>
<ul style="list-style:none;padding:2px 5px">
<li>
<input type="radio" name="context-board" value="*" id="context-board-no"{% if not board %} checked{% endif %}>
<label style="display:inline" for="context-board-no">
<em>{% trans 'no context' %}</em>
</label>
</li>
{% for b in boards %}
<li>
<input type="radio" name="context-board" value="{{ b.uri }}" id="context-board-{{ b.uri }}"{% if board == b.uri %} checked{% endif %}>
<label style="display:inline" for="ban-board-{{ b.uri }}">
{{ config.board_abbreviation|sprintf(b.uri) }} - {{ b.title|e }}
</label>
</li>
{% endfor %}
</ul>
</td>
</tr>
<tr>
<td></td>
<td><input name="new_ban" type="submit" value="{% trans 'New Ban' %}"></td>