2019-04-27 06:32:26 +00:00
|
|
|
(() => {
|
|
|
|
addInitHook("end_init", () => {
|
|
|
|
|
|
|
|
formVars = {
|
2022-02-21 03:16:15 +00:00
|
|
|
'forum_active': ['Hide','Show'],
|
|
|
|
'forum_preset': ['all','announce','members','staff','admins','archive','custom']
|
2019-04-27 06:32:26 +00:00
|
|
|
};
|
|
|
|
var forums = {};
|
|
|
|
let items = document.getElementsByClassName("panel_forum_item");
|
2020-04-04 01:25:59 +00:00
|
|
|
for(let i=0; item=items[i]; i++) forums[i] = item.getAttribute("data-fid");
|
2020-07-23 04:02:16 +00:00
|
|
|
log("forums",forums);
|
2019-04-27 06:32:26 +00:00
|
|
|
|
|
|
|
Sortable.create(document.getElementById("panel_forums"), {
|
2022-02-21 03:16:15 +00:00
|
|
|
sort: true,
|
|
|
|
onEnd: (evt) => {
|
|
|
|
log("pre forums",forums)
|
|
|
|
log("evt",evt)
|
|
|
|
let oldFid = forums[evt.newIndex];
|
|
|
|
forums[evt.oldIndex] = oldFid;
|
|
|
|
let newFid = evt.item.getAttribute("data-fid");
|
|
|
|
log("newFid",newFid);
|
|
|
|
forums[evt.newIndex] = newFid;
|
|
|
|
log("post forums",forums);
|
|
|
|
}
|
2019-04-27 06:32:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("panel_forums_order_button").addEventListener("click", () => {
|
2022-02-21 03:16:15 +00:00
|
|
|
let req = new XMLHttpRequest();
|
|
|
|
if(!req) {
|
|
|
|
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);
|
|
|
|
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?
|
|
|
|
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+"}");
|
2019-04-27 06:32:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2020-03-09 10:37:41 +00:00
|
|
|
})()
|