2019-04-28 22:17:08 +00:00
|
|
|
(() => {
|
|
|
|
addInitHook("end_init", () => {
|
|
|
|
|
|
|
|
// TODO: Move this into a JS file to reduce the number of possible problems
|
|
|
|
var menuItems = {};
|
|
|
|
let items = document.getElementsByClassName("panel_menu_item");
|
2020-04-05 03:18:36 +00:00
|
|
|
for(let i=0; item=items[i]; i++) menuItems[i] = item.getAttribute("data-miid");
|
2019-04-28 22:17:08 +00:00
|
|
|
|
|
|
|
Sortable.create(document.getElementById("panel_menu_item_holder"), {
|
|
|
|
sort: true,
|
2020-04-05 03:18:36 +00:00
|
|
|
onEnd: evt => {
|
|
|
|
console.log("pre menuItems",menuItems)
|
|
|
|
console.log("evt",evt)
|
2019-04-28 22:17:08 +00:00
|
|
|
let oldMiid = menuItems[evt.newIndex];
|
|
|
|
menuItems[evt.oldIndex] = oldMiid;
|
|
|
|
let newMiid = evt.item.getAttribute("data-miid");
|
2020-04-05 03:18:36 +00:00
|
|
|
console.log("newMiid",newMiid);
|
2019-04-28 22:17:08 +00:00
|
|
|
menuItems[evt.newIndex] = newMiid;
|
2020-04-05 03:18:36 +00:00
|
|
|
console.log("post menuItems",menuItems);
|
2019-04-28 22:17:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("panel_menu_items_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) {
|
|
|
|
let resp = JSON.parse(req.responseText);
|
2020-04-05 03:18:36 +00:00
|
|
|
console.log("resp",resp);
|
2019-04-28 22:17:08 +00:00
|
|
|
// TODO: Should we move other notices into TmplPhrases like this one?
|
|
|
|
pushNotice(phraseBox["panel"]["panel.themes_menus_items_order_updated"]);
|
|
|
|
if(resp.success==1) return;
|
|
|
|
}
|
2020-04-05 03:18:36 +00:00
|
|
|
} catch(e) {
|
|
|
|
console.error("e",e)
|
2019-04-28 22:17:08 +00:00
|
|
|
}
|
|
|
|
console.trace();
|
|
|
|
}
|
|
|
|
// ? - Is encodeURIComponent the right function for this?
|
|
|
|
let spl = document.location.pathname.split("/");
|
2020-04-05 03:18:36 +00:00
|
|
|
req.open("POST","/panel/themes/menus/item/order/edit/submit/"+parseInt(spl[spl.length-1],10)+"?s="+encodeURIComponent(me.User.S));
|
2019-04-28 22:17:08 +00:00
|
|
|
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
|
let items = "";
|
2020-04-05 03:18:36 +00:00
|
|
|
for(let i=0; item=menuItems[i];i++) items += item+",";
|
2019-04-28 22:17:08 +00:00
|
|
|
if(items.length > 0) items = items.slice(0,-1);
|
|
|
|
req.send("js=1&items={"+items+"}");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2020-03-09 10:37:41 +00:00
|
|
|
})()
|