From 8ea95a927cc195d3fdb9fcb04b82336046806a52 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sun, 17 Jul 2022 15:56:44 -0700 Subject: [PATCH] Move modify.js + ban.js => restricted.js Further in on restricted JS to simplify things. Rather than breaking out all Javascript stuff into their own granular files, this just includes all admin actions together in the same file. Signed-off-by: Alek Ratzloff --- board/static/board/ban.js | 46 ---------- board/static/board/modify.js | 40 -------- board/static/board/restricted.js | 91 +++++++++++++++++++ .../admin/board/reportrecord/change_list.html | 2 +- board/templates/board/base.html | 3 +- 5 files changed, 93 insertions(+), 89 deletions(-) delete mode 100644 board/static/board/ban.js delete mode 100644 board/static/board/modify.js create mode 100644 board/static/board/restricted.js diff --git a/board/static/board/ban.js b/board/static/board/ban.js deleted file mode 100644 index 8cd516e..0000000 --- a/board/static/board/ban.js +++ /dev/null @@ -1,46 +0,0 @@ -// HACK: this should be a const, but it will cause an error if included twice in -// the same page (like an iframe). -if (typeof window.banWindowName === "undefined") { - window.banWindowName = "ban-window"; -} - -if (typeof window.menuItemFactories !== "undefined") { - window.menuItemFactories.push( - (postElement) => $("") - .text("Ban") - .attr("href", "#") - .on("click", (e) => { - e.preventDefault(); - openBanWindow($(postElement).attr("data-ban-url")); - }) - ); -} - -function getBanWindow() { - return window.top.jsFrame.getWindowByName(banWindowName); -} - -function openBanWindow(banUrl) { - if (window.top.jsFrame.containsWindowName(banWindowName)) { - getBanWindow().closeFrame(); - } - let banWindow = window.top.jsFrame.create({ - title: "New Ban", - name: banWindowName, - width: 475, - url: banUrl, - }); - $(banWindow.iframe, "iframe").on("load", () => { - fitWindowToContent(banWindow); - banWindow.setResizable(false); - }); - banWindow.setPosition( - window.innerWidth, - window.innerHeight / 2, - "RIGHT_CENTER" - ); - $(banWindow.iframe, "iframe").on("load", () => { - banWindow.iframe.contentWindow.thisWindow = banWindow; - }); - banWindow.show(); -} diff --git a/board/static/board/modify.js b/board/static/board/modify.js deleted file mode 100644 index 8d3246c..0000000 --- a/board/static/board/modify.js +++ /dev/null @@ -1,40 +0,0 @@ -if (typeof window.menuItemFactories !== "undefined") { - window.menuItemFactories.push( - (postElement) => $("") - .text("Modify post") - .attr("href", "#") - .on("click", (e) => { - e.preventDefault(); - openModifyWindow($(postElement).attr("data-modify-url")); - }) - ); -} - -// HACK: this should be a const, but it will cause an error if included twice in -// the same page (like an iframe). -if (typeof window.modifyWindowName === "undefined") { - window.modifyWindowName = "modify-window"; -} - -function getModifyWindow() { - return window.top.jsFrame.getWindowByName(modifyWindowName); -} - -function openModifyWindow(modifyUrl) { - if (window.top.jsFrame.containsWindowName(modifyWindowName)) { - getModifyWindow().closeFrame(); - } - - let modifyWindow = window.top.jsFrame.create({ - title: "Modifying post", - name: modifyWindowName, - width: 475, - url: modifyUrl, - }); - $(modifyWindow.iframe, "iframe").on("load", () => { - fitWindowToContent(modifyWindow); - modifyWindow.setResizable(false); - modifyWindow.iframe.contentWindow.thisWindow = modifyWindow; - }); - modifyWindow.show(); -} \ No newline at end of file diff --git a/board/static/board/restricted.js b/board/static/board/restricted.js new file mode 100644 index 0000000..7322713 --- /dev/null +++ b/board/static/board/restricted.js @@ -0,0 +1,91 @@ +//////////////////////////////////////////////////////////////////////////////// +// Constants +//////////////////////////////////////////////////////////////////////////////// + +// HACK: this should be a const, but it will cause an error if included twice in +// the same page (like an iframe). +if (typeof window.banWindowName === "undefined") { + window.banWindowName = "ban-window"; + window.modifyWindowName = "modify-window"; +} + +if (typeof window.menuItemFactories !== "undefined") { + window.menuItemFactories.push( + (postElement) => $("") + .text("Ban") + .attr("href", "#") + .on("click", (e) => { + e.preventDefault(); + openBanWindow($(postElement).attr("data-ban-url")); + }) + ); + window.menuItemFactories.push( + (postElement) => $("") + .text("Modify post") + .attr("href", "#") + .on("click", (e) => { + e.preventDefault(); + openModifyWindow($(postElement).attr("data-modify-url")); + }) + ); +} + +//////////////////////////////////////////////////////////////////////////////// +// Ban window +//////////////////////////////////////////////////////////////////////////////// + +function getBanWindow() { + return window.top.jsFrame.getWindowByName(banWindowName); +} + +function openBanWindow(banUrl) { + if (window.top.jsFrame.containsWindowName(banWindowName)) { + getBanWindow().closeFrame(); + } + let banWindow = window.top.jsFrame.create({ + title: "New Ban", + name: banWindowName, + width: 475, + url: banUrl, + }); + $(banWindow.iframe, "iframe").on("load", () => { + fitWindowToContent(banWindow); + banWindow.setResizable(false); + }); + banWindow.setPosition( + window.innerWidth, + window.innerHeight / 2, + "RIGHT_CENTER" + ); + $(banWindow.iframe, "iframe").on("load", () => { + banWindow.iframe.contentWindow.thisWindow = banWindow; + }); + banWindow.show(); +} + +//////////////////////////////////////////////////////////////////////////////// +// Modify window +//////////////////////////////////////////////////////////////////////////////// + +function getModifyWindow() { + return window.top.jsFrame.getWindowByName(modifyWindowName); +} + +function openModifyWindow(modifyUrl) { + if (window.top.jsFrame.containsWindowName(modifyWindowName)) { + getModifyWindow().closeFrame(); + } + + let modifyWindow = window.top.jsFrame.create({ + title: "Modifying post", + name: modifyWindowName, + width: 475, + url: modifyUrl, + }); + $(modifyWindow.iframe, "iframe").on("load", () => { + fitWindowToContent(modifyWindow); + modifyWindow.setResizable(false); + modifyWindow.iframe.contentWindow.thisWindow = modifyWindow; + }); + modifyWindow.show(); +} \ No newline at end of file diff --git a/board/templates/admin/board/reportrecord/change_list.html b/board/templates/admin/board/reportrecord/change_list.html index 7dac6a8..fd30830 100644 --- a/board/templates/admin/board/reportrecord/change_list.html +++ b/board/templates/admin/board/reportrecord/change_list.html @@ -17,7 +17,7 @@ - + {% endblock extrahead %} {% block footer %} diff --git a/board/templates/board/base.html b/board/templates/board/base.html index 6df7da1..5e50f0f 100644 --- a/board/templates/board/base.html +++ b/board/templates/board/base.html @@ -13,8 +13,7 @@ {% if user.is_staff %} - - + {% endif %} {% block extrajs %}{% endblock %}