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:
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
91
board/static/board/restricted.js
Normal file
91
board/static/board/restricted.js
Normal 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();
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
<script src="{% static 'board/jquery.js' %}"></script>
|
||||
<script src="{% static 'board/jsframe.min.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 %}
|
||||
|
||||
{% block footer %}
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
<script src="{% static 'board/jsframe.min.js' %}"></script>
|
||||
<script src="{% static 'board/post.js' %}"></script>
|
||||
{% if user.is_staff %}
|
||||
<script src="{% static 'board/ban.js' %}"></script>
|
||||
<script src="{% static 'board/modify.js' %}"></script>
|
||||
<script src="{% static 'board/restricted.js' %}"></script>
|
||||
{% endif %}
|
||||
{% block extrajs %}{% endblock %}
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user