Add in-line ban capabilities
Anyone with the ability to create bans can now do so via the drop down menu on all posts. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
25
board/static/board/ban_menu.js
Normal file
25
board/static/board/ban_menu.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
function openBanWindow(e, postElement) {
|
||||||
|
e.preventDefault();
|
||||||
|
let banUrl = $(postElement).attr("data-ban-url");
|
||||||
|
if (window.top.banWindow) {
|
||||||
|
window.top.banWindow.close();
|
||||||
|
}
|
||||||
|
window.top.banWindow = new WinBox("New ban", {
|
||||||
|
url: banUrl,
|
||||||
|
x: "center",
|
||||||
|
y: "center",
|
||||||
|
root: document.body,
|
||||||
|
onclose: function (force) {
|
||||||
|
window.top.banWindow = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof window.menuItemFactories !== "undefined") {
|
||||||
|
window.menuItemFactories.push(
|
||||||
|
(postElement) => $("<a>")
|
||||||
|
.text("Ban")
|
||||||
|
.attr("href", "#")
|
||||||
|
.on("click", (e) => { return openBanWindow(e, postElement); })
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -31,18 +31,17 @@ function closeMenu(e) {
|
|||||||
function openMenu(e) {
|
function openMenu(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let sender = e.target;
|
let sender = e.target;
|
||||||
let reportButton = $("<a>")
|
|
||||||
.text("Report")
|
|
||||||
.attr("href", "#")
|
|
||||||
.on("click", (e) => { return openReportWindow(e, $(sender.parentElement)); });
|
|
||||||
let menuList = $("<ul></ul>")
|
let menuList = $("<ul></ul>")
|
||||||
.append($("<lh><strong>Actions</strong></lh>").addClass("post_menu_item"))
|
.append($("<lh><strong>Actions</strong></lh>").addClass("post_menu_item"))
|
||||||
.append(
|
|
||||||
$('<li></li>')
|
|
||||||
.addClass("post_menu_item")
|
|
||||||
.append(reportButton)
|
|
||||||
)
|
|
||||||
.addClass("post_menu_items");
|
.addClass("post_menu_items");
|
||||||
|
window.menuItemFactories.forEach(factory => {
|
||||||
|
item = factory(sender.parentElement);
|
||||||
|
menuList.append(
|
||||||
|
$("<li></li>")
|
||||||
|
.addClass("post_menu_item")
|
||||||
|
.append(item)
|
||||||
|
);
|
||||||
|
});
|
||||||
let rect = sender.getBoundingClientRect();
|
let rect = sender.getBoundingClientRect();
|
||||||
let menu = $("<div></div>")
|
let menu = $("<div></div>")
|
||||||
.addClass("post_menu")
|
.addClass("post_menu")
|
||||||
@@ -62,7 +61,7 @@ function openReportWindow(e, postElement) {
|
|||||||
window.top.reportWindow.close();
|
window.top.reportWindow.close();
|
||||||
}
|
}
|
||||||
//let postId = sender.parentElement.getAttribute("id").substring(1);
|
//let postId = sender.parentElement.getAttribute("id").substring(1);
|
||||||
let reportUrl = postElement.attr("data-report-url");
|
let reportUrl = $(postElement).attr("data-report-url");
|
||||||
window.reportWindow = new WinBox("New Report", {
|
window.reportWindow = new WinBox("New Report", {
|
||||||
url: reportUrl,
|
url: reportUrl,
|
||||||
modal: true,
|
modal: true,
|
||||||
@@ -74,8 +73,16 @@ function openReportWindow(e, postElement) {
|
|||||||
|
|
||||||
function onLoad(e) {
|
function onLoad(e) {
|
||||||
window.reportWindow = null;
|
window.reportWindow = null;
|
||||||
|
window.menuItemFactories.push(
|
||||||
|
(postElement) =>
|
||||||
|
$("<a>")
|
||||||
|
.text("Report")
|
||||||
|
.attr("href", "#")
|
||||||
|
.on("click", (e) => { return openReportWindow(e, postElement); })
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on("click", documentClick);
|
$(document).on("click", documentClick);
|
||||||
$(document).on("click", ".post_id", doQuote);
|
$(document).on("click", ".post_id", doQuote);
|
||||||
$(window).on("load", onLoad);
|
$(window).on("load", onLoad);
|
||||||
|
window.menuItemFactories = [];
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
<script src="{% static 'board/jquery.js' %}"></script>
|
<script src="{% static 'board/jquery.js' %}"></script>
|
||||||
<script src="{% static 'board/winbox.bundle.js' %}"></script>
|
<script src="{% static 'board/winbox.bundle.js' %}"></script>
|
||||||
<script src="{% static 'board/post.js' %}"></script>
|
<script src="{% static 'board/post.js' %}"></script>
|
||||||
|
{% if perms.board.create_ban %}
|
||||||
|
<script src="{% static 'board/ban_menu.js' %}"></script>
|
||||||
|
{% endif %}
|
||||||
{% block extrajs %}{% endblock %}
|
{% block extrajs %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
{% load post_body %}
|
{% load post_body %}
|
||||||
{% load l10n %}
|
{% load l10n %}
|
||||||
<div id="p{{post.id}}" data-report-url="{% url 'board:report_form' board.url post.id %}">
|
<div
|
||||||
|
id="p{{post.id}}"
|
||||||
|
data-report-url="{% url 'board:report_form' board.url post.id %}"
|
||||||
|
{% if perms.board.create_ban %}
|
||||||
|
data-ban-url="{% url 'board:ban_create' board.url post.id %}"
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
{# Image #}
|
{# Image #}
|
||||||
{% if post.thumbnail %}
|
{% if post.thumbnail %}
|
||||||
{# Image info #}
|
{# Image info #}
|
||||||
|
|||||||
Reference in New Issue
Block a user