Add ability to create bans from reports
This is done in the admin view and opens a new iframed window. The ban form is pretty barebones and doesn't have full functionality yet, but that is coming. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
{% extends "admin/change_list.html" %}
|
||||
{% load static %}
|
||||
{% block extrastyle %}
|
||||
{{ block.super }}
|
||||
<style>
|
||||
@@ -9,5 +10,53 @@
|
||||
background-color: var(--message-error-bg);
|
||||
color: var(--error-fg);
|
||||
}
|
||||
|
||||
.wb-min {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wb-max {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wb-full {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
{% endblock extrastyle %}
|
||||
{% endblock extrastyle %}
|
||||
{% block extrahead %}
|
||||
{{block.super}}
|
||||
<script src="{% static 'board/jquery.js' %}"></script>
|
||||
<script src="{% static 'board/winbox.bundle.js' %}"></script>
|
||||
{% endblock extrahead %}
|
||||
|
||||
{% block footer %}
|
||||
{{block.super}}
|
||||
<script>
|
||||
|
||||
function openBanWindow(e) {
|
||||
e.preventDefault();
|
||||
let banUrl = e.target.getAttribute("data-ban-url");
|
||||
if (window.banWindow) {
|
||||
window.banWindow.close();
|
||||
}
|
||||
window.banWindow = new WinBox("New ban", {
|
||||
url: banUrl,
|
||||
x: "center",
|
||||
y: "center",
|
||||
root: document.body,
|
||||
onclose: function(force) {
|
||||
window.top.banWindow = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onLoad(e) {
|
||||
window.banWindow = null;
|
||||
}
|
||||
|
||||
$(".ban_link").on("click", openBanWindow);
|
||||
$(window).on("load", onLoad);
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
50
board/templates/board/ban_form.html
Normal file
50
board/templates/board/ban_form.html
Normal file
@@ -0,0 +1,50 @@
|
||||
{% extends "board/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form id="form" action="{% url 'board:ban_create' url=board.url id=post.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
<tr>
|
||||
<th>{% translate 'Post ID' %}:</th>
|
||||
<td>{{post.id}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% translate 'Board' %}:</th>
|
||||
<td>{{board.url}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>IP:</th>
|
||||
<td>{{post.ip}}</td>
|
||||
</tr>
|
||||
{{form.as_table}}
|
||||
<tr>
|
||||
<th>{% translate "Previous bans" %}</th>
|
||||
<td>{{previous_bans|length}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% translate "Current bans" %}</th>
|
||||
<td id="current_bans">{{current_bans|length}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td><input type="submit" id="submit" value="{% translate 'Create ban' %}" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function submitConfirm(e) {
|
||||
console.log($("#current_bans").text());
|
||||
if($("#current_bans").text() !== '0') {
|
||||
let result = window.confirm("There is already at least one ban for this IP address on this board, are you sure you want to continue?");
|
||||
if (!result) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$("#submit").on("click", submitConfirm);
|
||||
</script>
|
||||
{% endblock content %}
|
||||
29
board/templates/board/ban_success.html
Normal file
29
board/templates/board/ban_success.html
Normal file
@@ -0,0 +1,29 @@
|
||||
{% extends "board/base.html" %}
|
||||
{% load l10n %}
|
||||
{# Title #}
|
||||
{% block title %}{% localize on %}Ban success{% endlocalize %}{% endblock %}
|
||||
{# Body #}
|
||||
{% block content %}
|
||||
<div class="row" id="message">
|
||||
{% localize on %}A ban has been created. This window will close in 1 second.{% endlocalize %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function isIframe() {
|
||||
try {
|
||||
return window.self !== window.top;
|
||||
} catch (_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
if(isIframe()) {
|
||||
window.top.banWindow.close();
|
||||
} else {
|
||||
window.close();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user