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 <alekratz@gmail.com>
This commit is contained in:
2022-07-17 15:56:44 -07:00
parent 1a2ac653d7
commit 8ea95a927c
5 changed files with 93 additions and 89 deletions

View File

@@ -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) => $("<a>")
.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();
}

View File

@@ -1,40 +0,0 @@
if (typeof window.menuItemFactories !== "undefined") {
window.menuItemFactories.push(
(postElement) => $("<a>")
.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();
}

View File

@@ -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) => $("<a>")
.text("Ban")
.attr("href", "#")
.on("click", (e) => {
e.preventDefault();
openBanWindow($(postElement).attr("data-ban-url"));
})
);
window.menuItemFactories.push(
(postElement) => $("<a>")
.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();
}

View File

@@ -17,7 +17,7 @@
<script src="{% static 'board/jquery.js' %}"></script> <script src="{% static 'board/jquery.js' %}"></script>
<script src="{% static 'board/jsframe.min.js' %}"></script> <script src="{% static 'board/jsframe.min.js' %}"></script>
<script src="{% static 'board/post.js' %}"></script> <script src="{% static 'board/post.js' %}"></script>
<script src="{% static 'board/ban.js' %}"></script> <script src="{% static 'board/restricted.js' %}"></script>
{% endblock extrahead %} {% endblock extrahead %}
{% block footer %} {% block footer %}

View File

@@ -13,8 +13,7 @@
<script src="{% static 'board/jsframe.min.js' %}"></script> <script src="{% static 'board/jsframe.min.js' %}"></script>
<script src="{% static 'board/post.js' %}"></script> <script src="{% static 'board/post.js' %}"></script>
{% if user.is_staff %} {% if user.is_staff %}
<script src="{% static 'board/ban.js' %}"></script> <script src="{% static 'board/restricted.js' %}"></script>
<script src="{% static 'board/modify.js' %}"></script>
{% endif %} {% endif %}
{% block extrajs %}{% endblock %} {% block extrajs %}{% endblock %}
</head> </head>