gosora/public/panel_forums.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

(() => {
addInitHook("end_init", () => {
formVars = {
'forum_active': ['Hide','Show'],
'forum_preset': ['all','announce','members','staff','admins','archive','custom']
};
var forums = {};
let items = document.getElementsByClassName("panel_forum_item");
for(let i=0; item=items[i]; i++) forums[i] = item.getAttribute("data-fid");
2020-03-09 10:37:41 +00:00
console.log("forums",forums);
Sortable.create(document.getElementById("panel_forums"), {
sort: true,
onEnd: (evt) => {
2020-03-11 09:13:05 +00:00
console.log("pre forums",forums)
console.log("evt",evt)
let oldFid = forums[evt.newIndex];
forums[evt.oldIndex] = oldFid;
let newFid = evt.item.getAttribute("data-fid");
2020-03-11 09:13:05 +00:00
console.log("newFid",newFid);
forums[evt.newIndex] = newFid;
2020-03-11 09:13:05 +00:00
console.log("post forums",forums);
}
});
document.getElementById("panel_forums_order_button").addEventListener("click", () => {
let req = new XMLHttpRequest();
if(!req) {
console.log("Failed to create request");
return false;
}
req.onreadystatechange = () => {
try {
if(req.readyState!==XMLHttpRequest.DONE) return;
// TODO: Signal the error with a notice
if(req.status!==200) return;
let resp = JSON.parse(req.responseText);
console.log("resp",resp);
// TODO: Should we move other notices into TmplPhrases like this one?
pushNotice(phraseBox["panel"]["panel.forums_order_updated"]);
if(resp.success==1) return;
} catch(e) {
console.error("e",e)
}
console.trace();
}
// ? - Is encodeURIComponent the right function for this?
2019-08-31 22:59:00 +00:00
req.open("POST","/panel/forums/order/edit/submit/?s=" + encodeURIComponent(me.User.S));
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
let items = "";
for(let i=0;item=forums[i];i++) items += item+",";
if(items.length > 0) items = items.slice(0,-1);
req.send("js=1&items={"+items+"}");
});
});
2020-03-09 10:37:41 +00:00
})()