github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/public/panel_forums.js (about) 1 (() => { 2 addInitHook("end_init", () => { 3 4 formVars = { 5 'forum_active': ['Hide','Show'], 6 'forum_preset': ['all','announce','members','staff','admins','archive','custom'] 7 }; 8 var forums = {}; 9 let items = document.getElementsByClassName("panel_forum_item"); 10 for(let i=0; item=items[i]; i++) forums[i] = item.getAttribute("data-fid"); 11 log("forums",forums); 12 13 Sortable.create(document.getElementById("panel_forums"), { 14 sort: true, 15 onEnd: (evt) => { 16 log("pre forums",forums) 17 log("evt",evt) 18 let oldFid = forums[evt.newIndex]; 19 forums[evt.oldIndex] = oldFid; 20 let newFid = evt.item.getAttribute("data-fid"); 21 log("newFid",newFid); 22 forums[evt.newIndex] = newFid; 23 log("post forums",forums); 24 } 25 }); 26 27 document.getElementById("panel_forums_order_button").addEventListener("click", () => { 28 let req = new XMLHttpRequest(); 29 if(!req) { 30 log("Failed to create request"); 31 return false; 32 } 33 req.onreadystatechange = () => { 34 try { 35 if(req.readyState!==XMLHttpRequest.DONE) return; 36 // TODO: Signal the error with a notice 37 if(req.status!==200) return; 38 39 let resp = JSON.parse(req.responseText); 40 log("resp",resp); 41 // TODO: Should we move other notices into TmplPhrases like this one? 42 pushNotice(phraseBox["panel"]["panel.forums_order_updated"]); 43 if(resp.success==1) return; 44 } catch(e) { 45 console.error("e",e) 46 } 47 console.trace(); 48 } 49 // ? - Is encodeURIComponent the right function for this? 50 req.open("POST","/panel/forums/order/edit/submit/?s=" + encodeURIComponent(me.User.S)); 51 req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 52 let items = ""; 53 for(let i=0;item=forums[i];i++) items += item+","; 54 if(items.length > 0) items = items.slice(0,-1); 55 req.send("js=1&items={"+items+"}"); 56 }); 57 58 }); 59 })()