From 647aedfc6758892b664b00717846116369817a60 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 23 Jun 2022 22:27:26 -0700 Subject: [PATCH] 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 --- board/static/board/ban_menu.js | 25 +++++++++++++++++++++ board/static/board/post.js | 29 +++++++++++++++---------- board/templates/board/base.html | 3 +++ board/templates/board/post_snippet.html | 8 ++++++- 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 board/static/board/ban_menu.js diff --git a/board/static/board/ban_menu.js b/board/static/board/ban_menu.js new file mode 100644 index 0000000..9a00ef0 --- /dev/null +++ b/board/static/board/ban_menu.js @@ -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) => $("") + .text("Ban") + .attr("href", "#") + .on("click", (e) => { return openBanWindow(e, postElement); }) + ) +} \ No newline at end of file diff --git a/board/static/board/post.js b/board/static/board/post.js index bf14495..f090462 100644 --- a/board/static/board/post.js +++ b/board/static/board/post.js @@ -31,18 +31,17 @@ function closeMenu(e) { function openMenu(e) { e.preventDefault(); let sender = e.target; - let reportButton = $("") - .text("Report") - .attr("href", "#") - .on("click", (e) => { return openReportWindow(e, $(sender.parentElement)); }); let menuList = $("
    ") .append($("Actions").addClass("post_menu_item")) - .append( - $('
  • ') - .addClass("post_menu_item") - .append(reportButton) - ) .addClass("post_menu_items"); + window.menuItemFactories.forEach(factory => { + item = factory(sender.parentElement); + menuList.append( + $("
  • ") + .addClass("post_menu_item") + .append(item) + ); + }); let rect = sender.getBoundingClientRect(); let menu = $("
    ") .addClass("post_menu") @@ -62,7 +61,7 @@ function openReportWindow(e, postElement) { window.top.reportWindow.close(); } //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", { url: reportUrl, modal: true, @@ -74,8 +73,16 @@ function openReportWindow(e, postElement) { function onLoad(e) { window.reportWindow = null; + window.menuItemFactories.push( + (postElement) => + $("
    ") + .text("Report") + .attr("href", "#") + .on("click", (e) => { return openReportWindow(e, postElement); }) + ); } $(document).on("click", documentClick); $(document).on("click", ".post_id", doQuote); -$(window).on("load", onLoad); \ No newline at end of file +$(window).on("load", onLoad); +window.menuItemFactories = []; \ No newline at end of file diff --git a/board/templates/board/base.html b/board/templates/board/base.html index 74064ce..090a584 100644 --- a/board/templates/board/base.html +++ b/board/templates/board/base.html @@ -11,6 +11,9 @@ + {% if perms.board.create_ban %} + + {% endif %} {% block extrajs %}{% endblock %} diff --git a/board/templates/board/post_snippet.html b/board/templates/board/post_snippet.html index ec86764..55f8a30 100644 --- a/board/templates/board/post_snippet.html +++ b/board/templates/board/post_snippet.html @@ -1,6 +1,12 @@ {% load post_body %} {% load l10n %} -
    +
    {# Image #} {% if post.thumbnail %} {# Image info #}