Mercurial > hg > fapweb
view admin.js @ 1024:2a96426159f1
Fix configuration file checking.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Nov 2015 21:41:27 +0200 |
parents | ffacd904fd1f |
children | 8fecb417e6a9 |
line wrap: on
line source
// // FAPWeb - Simple Web-based Demoparty Management System // Party administration page frontend module // (C) Copyright 2012-2015 Tecnic Software productions (TNSP) // var activeAttendee = -1, prevAttendee = -1, activeAttendeeTmp = ""; var activeEntry = -1, prevEntry = -1, activeEntryTmp = ""; var registeredTabs = Object(); var activeTabs = Object(); // // Tab related code // function jsUpdateTabList(tabset, extra) { var tabs = ""; var content = ""; // Update the tab header list for this tabset for (var id in registeredTabs[tabset]) { var thead = registeredTabs[tabset][id]; tabs += "<a id=\"tabHead"+ tabset + id + "\" href=\"#\" onClick=\"jsSwitchActiveTab('"+tabset+"', '"+id+ "')\">"+ thead +"</a> "; content += "<div id=\"tabCont"+ tabset + id +"\"></div>"; } // Update the DOM elements var item = document.getElementById("tabHeaders"+ tabset); if (item) item.innerHTML = tabs + extra; item = document.getElementById("tabContents"+ tabset); if (item) item.innerHTML = content; } function jsRegisterTab(tabset, id, name) { // Create tabset object "array" if it does not exist if (!registeredTabs[tabset]) registeredTabs[tabset] = Object(); // Register tab registeredTabs[tabset][id] = name; } function jsSwitchActiveTab(tabset, tab) { // Go through all registered tabs to update their state for (var id in registeredTabs[tabset]) { var tabContent = document.getElementById("tabCont"+ tabset + id); var tabHead = document.getElementById("tabHead"+ tabset + id); if (tabContent && tabHead) { tabContent.style.display = (tab == id) ? "block" : "none"; tabHead.style.borderTop = (tab == id) ? "4px solid white" : "none"; if (tab == id) { // Set active tab and refresh contents activeTabs[tabset] = id; setTimeout("refreshDispatch"+ tabset +"('"+ id +"');", 10); jsCancelUploadCBS(); } else { // Clear inactive tabs tabContent.innerHTML = ""; } } } } // // Admin interface specific popups // function jsHandleAdminPopupKeys(ev) { ev = ev || window.event; var key = ev.keyCode ? ev.keyCode : ev.which; if (key == 27) { jsCloseAdminPopup(); return false; } else return true; } function jsCloseAdminPopup() { var nitem = document.getElementById("adminPopup"); if (nitem) { document.onkeydown = null; nitem.innerHTML = ""; nitem.style.display = "none"; } } function jsOpenAdminPopup(txt) { var nitem = document.getElementById("adminPopup"); if (nitem) { document.onkeydown = jsHandleAdminPopupKeys; nitem.innerHTML = txt; nitem.style.display = "block"; } } // // Generic element refresh // function jsRefreshItems(id,name,extra) { var msuccess = function(txt) { var nitem = document.getElementById(id); if (nitem) nitem.innerHTML = txt; } jsSendPOSTRequest("action=get&type="+name+extra, msuccess); } function jsDeleteItem(id,prefix,type,func,dsc,dsc2) { var msuccess = function(txt) { var item = document.getElementById(prefix+id); item.style.display = "none"; setTimeout(func, 50); } // Clearly mark the element when asking confirmation var item = document.getElementById(prefix+id); var tmp = item.className; item.className += " deleteWarning"; // Ask confirmation for deletion var mcb_ok = function (data) { jsSendPOSTRequest("action=delete&type="+type+"&id="+id, msuccess); item.className = tmp; } var mcb_cancel = function (data) { item.className = tmp; } if (dsc) jsConfirmBox("Are you sure you want to delete "+dsc+" #"+id+"?", mcb_ok, mcb_cancel, 0); else jsConfirmBox(dsc2, mcb_ok, mcb_cancel, 0); } function jsRefreshPanels(id, tab, args, set_default) { var msuccess = function(txt) { var nitem = document.getElementById(tab); if (nitem) { if (nitem.innerHTML == "") { nitem.innerHTML = "<div id=\"tabHeaders"+id+"\" class=\"tabHeadersSub\"></div>" + "<div id=\"tabContents"+id+"\" class=\"tabContentsSub\"></div>"; } try { var tmp = JSON.parse("{"+ txt +"}"); registeredTabs[id] = tmp; jsUpdateTabList(id, ""); if (activeTabs[id]) jsSwitchActiveTab(id, activeTabs[id]); else if (set_default == "*") { for (var nid in registeredTabs[id]) { jsSwitchActiveTab(id, nid); break; } } else if (set_default != "") jsSwitchActiveTab(id, set_default); } catch (err) { jsErrorMessageBox("JSON.parse("+ txt +") failure: "+ err); } } } jsSendPOSTRequest("action=get&type="+args, msuccess); } function refreshDispatchCC(id) { switch (id) { case "News" : jsRefreshItems("tabContCCNews", "news", ""); break; case "Attendees" : jsRefreshItems("tabContCCAttendees", "attendees", ""); activeAttendee = -1; break; case "Voting" : jsRefreshItems("tabContCCVoting", "voters", ""); break; case "Compos" : jsRefreshItems("tabContCCCompos", "compos", ""); break; case "InfoSys" : jsRefreshItems("tabContCCInfoSys", "infoMain", ""); break; case "Settings" : jsRefreshPanels("CS", "tabContCCSettings", "settingslist", "*"); break; case "Entries" : jsRefreshPanels("CM", "tabContCCEntries", "compolist", ""); break; } } function refreshDispatchCS(id) { jsRefreshItems("tabContCS"+ id, "settings", "&id="+ id); } function refreshDispatchCM(id) { prevEntry = activeEntry = -1; jsRefreshItems("tabContCM"+ id, "entries", "&id="+ id); } // // Site news management // function addNews() { var args = jsMakePostArgs({"title":1,"text":1,"author":1}, "nn", ""); var msuccess = function(txt) { setTimeout("refreshDispatchCC('News');", 50); } if (args != "") jsSendPOSTRequest("action=add&type=news&"+args, msuccess); return false; } function deleteNews(id) { jsDeleteItem(id, "news", "news", "refreshDispatchCC('News');", "news item"); } function updateNews(id) { var args = jsMakePostArgs({"title":1,"text":1,"author":1}, "ne", id); var msuccess = function(txt) { jsRefreshItems("news"+id, "newsitem", "&id="+id); } if (args != "") jsSendPOSTRequest("action=update&type=news&id="+id+"&"+args, msuccess); } // // Visitor/attendee management // function addAttendee() { var args = jsMakePostArgs({"name":1,"groups":1,"oneliner":1,"email":1}, "ne", "x"); var msuccess = function(txt) { setTimeout("refreshDispatchCC('Attendees');", 50); } if (args != "") jsSendPOSTRequest("action=add&type=attendees&"+args, msuccess); return false; } function deleteAttendee(id) { jsDeleteItem(id, "attendee", "attendees", "refreshDispatchCC('Attendees');", "attendee"); } function updateAttendee(id) { var args = jsMakePostArgs({"name":1,"groups":1,"oneliner":1,"email":1,"reghost":1}, "at", id); var msuccess = function(txt) { activateAttendee(-1); } if (args != "") jsSendPOSTRequest("action=update&type=attendees&id="+id+"&"+args, msuccess); } function activateAttendee(id) { var msuccess1 = function(txt) { var nitem = document.getElementById("attendee"+prevAttendee); if (nitem) { nitem.innerHTML = txt; nitem.className = activeAttendeeTmp; } } var msuccess2 = function(txt) { var nitem = document.getElementById("attendee"+activeAttendee); if (nitem) { nitem.innerHTML = txt; activeAttendeeTmp = nitem.className; nitem.className += " active"; activeAttendee = id; } } if (activeAttendee != id) { prevAttendee = activeAttendee; activeAttendee = id; if (prevAttendee != -1) jsSendPOSTRequest("action=get&type=attendee&id="+prevAttendee+"&edit=0", msuccess1); if (activeAttendee != -1) jsSendPOSTRequest("action=get&type=attendee&id="+activeAttendee+"&edit=1", msuccess2); } } // // Compo management // function addCompo() { var args = jsMakePostArgs({"name":1, "description":1, "notes":1}, "nc", ""); var msuccess = function(txt) { setTimeout("refreshDispatchCC('Compos');", 50); } if (args != "") jsSendPOSTRequest("action=add&type=compo&"+args, msuccess); return false; } function updateCompoType(id) { var msuccess = function(txt) { jsRefreshItems("compo"+id, "compo", "&id="+id); } jsSendPOSTRequest("action=update&type=compotype&id="+id+"&ctype="+jsGetValue("cotype"+id+"Sel", 4), msuccess); } function updateCompo(id) { var args = jsMakePostArgs({"name":1, "description":1, "notes":1, "visible":3, "voting":3, "show_authors":3, "cpath":1, "preview_type":4}, "co", id, true); var msuccess = function(txt) { jsRefreshItems("compo"+id, "compo", "&id="+id); } if (args != "") jsSendPOSTRequest("action=update&type=compo&id="+id+"&"+args, msuccess); } function deleteCompo(id) { jsDeleteItem(id, "compo", "compo", "refreshDispatchCC('Compos');", 0, "Are you ABSOLUTELY sure you want to delete compo #"+id+"? "+ "This will delete all votes AND entries related to it!"); } // // Entry management // function activateEntry(id, force) { var msuccess1 = function(txt) { var nitem = document.getElementById("entry"+prevEntry); if (nitem) { nitem.innerHTML = txt; nitem.className = activeEntryTmp; } } var msuccess2 = function(txt) { var nitem = document.getElementById("entry"+activeEntry); if (nitem) { nitem.innerHTML = txt; activeEntryTmp = nitem.className; nitem.className += " active"; activeEntry = id; } } if (activeEntry != id || force) { jsCancelUploadCBS(); prevEntry = activeEntry; activeEntry = id; if (prevEntry != -1) jsSendPOSTRequest("action=get&type=entry&id="+prevEntry+"&edit=0", msuccess1); if (activeEntry != -1) jsSendPOSTRequest("action=get&type=entry&id="+activeEntry+"&edit=1", msuccess2); } } function addEntry(id) { var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1, "notes":1, "evalue":2}, "ne", id, true); jsCancelUploadCBS(); var msuccess = function(txt) { setTimeout("refreshDispatchCM("+ id +");", 50); } if (args != "") jsSendPOSTRequest("action=add&type=entry&compo_id="+id+"&"+args, msuccess); return false; } function updateEntry(cid, id, edit) { var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1, "notes":1, "compo_id":4, "evalue":2}, "en", id, true); var has_id = "compo_id" in lastPostArgs; var compo_id = lastPostArgs["compo_id"]; jsCancelUploadCBS(); if (!("compo_id" in lastPostArgs)) { args += "&compo_id=" + cid; compo_id = cid; } var msuccess = function(txt) { if (cid != compo_id) { var nitem = document.getElementById("entry"+ id); if (nitem) nitem.style.display = "none"; } else activateEntry(edit ? id : -1, true); } var mcb_ok = function(data) { jsSendPOSTRequest("action=update&type=entry&id="+id+"&edit="+edit+"&"+args, msuccess); } var mcb_cancel = function(data) { activeEntry = -1; } if (args != "") { if (cid != compo_id) { jsConfirmBox("Are you sure you want to change entry #"+id+ "'s compo from "+cid+" to "+compo_id+"?", mcb_ok, mcb_cancel); } else mcb_ok(); } } function deleteEntry(cid, id) { jsCancelUploadCBS(); jsDeleteItem(id, "entry", "entries", "refreshDispatchCM("+ cid +");", "entry"); } // // Votekey management // function voteKeyRefresh(id) { var msuccess2 = function(txt) { var nitem = document.getElementById("vkey"+id); if (nitem) nitem.className = txt; } var msuccess1 = function(txt) { var nitem = document.getElementById("vkey"+id); if (nitem) nitem.innerHTML = txt; } jsSendPOSTRequest("action=get&type=votekey&id="+id, msuccess1); jsSendPOSTRequest("action=get&type=votekeyclass&id="+id, msuccess2); } function voteKeyUpdate(id, type, args) { var msuccess = function(txt) { voteKeyRefresh(id); } jsSendPOSTRequest("action=votekey&type="+type+"&id="+id+"&"+args, msuccess); } function voteKeySetActive(id) { var args = jsMakePostArgs({"active":3}, "vk", id); var mcb_ok = function (data) { voteKeyUpdate(id, "active", args); } var mcb_cancel = function (data) { voteKeyRefresh(id); } if (lastPostArgs["active"] == 0) jsConfirmBox("Are you sure you want to deactivate vote key #"+id+"?", mcb_ok, mcb_cancel, 0); else mcb_ok(0); } function voteKeyAssign(id, mode) { var args = jsMakePostArgs({"key_id":2}, "vk", id); var mcb_ok = function (data) { voteKeyUpdate(id, (mode ? "assign" : "clear"), args); } if (mode == 0) jsConfirmBox("Are you sure you want to clear vote key assign #"+id+"?", mcb_ok, 0, 0); else mcb_ok(0); } // // Misc functions // function performSystemCheck() { jsSendPOSTRequest("action=check", jsMessageBox); } function generateEntryPositions(id, patch) { var msuccess = function (data) { refreshDispatchCM(id); refreshCurrEntryData(); refreshCurrEntryListData(); } var mcb_ok = function (data) { if (id == 0) jsSendPOSTRequest("action=randomize&type=all&patch="+patch, msuccess); else jsSendPOSTRequest("action=randomize&type=compo&id="+id+"&patch="+patch, msuccess); } if (patch == 0) { jsConfirmBox("Are you <b>ABSOLUTELY CERTAIN</b> you want to delete and regenerate entry show positions "+ (id == 0 ? "for ALL compos" : "for this compo") +"? "+ "<b>This will completely annihilate current show position numbers! AND FUCK UP YOUR EXPORTED FILE ORDER (ask ccr to know what that means.)</b>", mcb_ok, 0, 0); } else mcb_ok(0); } // // Competition control // function setShowMode(mode) { jsSendPOSTRequest("action=ctrl&type=setShowMode&mode="+mode); } function refreshCurrEntryData() { jsRefreshItems("ctrlCurrCompoData", "infoCurrCompoData", ""); } function refreshCurrEntryListData() { jsRefreshItems("ctrlEntryList", "infoCurrEntryList", ""); refreshCurrEntryData(); } function activateCompo() { jsSendPOSTRequest("action=ctrl&type=setCompoID&id="+jsGetValue("ctrlCompoListSel", 4), refreshCurrEntryListData); } function setSelectedEntry() { jsSendPOSTRequest("action=ctrl&type=setEntry&index="+jsGetValue("ctrlEntryListSel", 4), refreshCurrEntryData); } function switchEntry(dir) { jsSendPOSTRequest("action=ctrl&type="+ (dir < 0 ? "prevEntry" : "nextEntry"), refreshCurrEntryListData); } // // Rotation list editing and handling // function refreshRotationListSel() { jsRefreshItems("ctrlRotationListsSel", "infoRotationLists", ""); } function refreshRotationListEdit(id) { jsRefreshItems("ctrlRotationListEdit", "infoRotationListEdit", "&id="+id+"&full=0"); refreshRotationListSel(); } function refreshActiveRotationList() { jsRefreshItems("ctrlActiveRotationList", "infoActiveRotationList", ""); } function setRotateDuration() { var duration = jsGetValue("ctrlRotSlideDuration", 2); jsSendPOSTRequest("action=ctrl&type=setRotateDuration&duration="+duration); } function setActiveRotationList() { var id = jsGetValue("ctrlRotationListsSel", 4); if (id > 0) jsSendPOSTRequest("action=ctrl&type=setActiveRotationList&id="+id, refreshActiveRotationList); else jsErrorMessageBox("No rotation list selected?"); } function updateRotationList(id) { var name = jsGetValue("ctrlEDRotationListName", 1); jsSendPOSTRequest("action=ctrl&type=updateRotationList&id="+id+"&name="+name, refreshRotationListSel); } function moveRotationListSlide(list_id, dir) { var msuccess = function(txt) { refreshRotationListEdit(list_id); } var slide = jsGetValue("ctrlEDRotationListSel", 4); if (slide) { var str = slide.split("_"); jsSendPOSTRequest("action=ctrl&type=moveRotationListSlide&list_id="+list_id+ "&slide_id="+parseInt(str[0])+"&order_num="+parseInt(str[1])+"&dir="+dir, msuccess); } else jsErrorMessageBox("No slide selected?"); } function addRotationListSlide(list_id) { var msuccess = function(txt) { refreshRotationListEdit(list_id); } var slide_id = jsGetValue("ctrlEDDisplaySlidesSel", 4); if (slide_id > 0) jsSendPOSTRequest("action=ctrl&type=addRotationListSlide&list_id="+list_id+"&slide_id="+slide_id, msuccess); else jsErrorMessageBox("No slide selected?"); } function removeRotationListSlide(list_id) { var msuccess = function(txt) { refreshRotationListEdit(list_id); } var slide = jsGetValue("ctrlEDRotationListSel", 4); if (slide) { var str = slide.split("_"); jsSendPOSTRequest("action=ctrl&type=removeRotationListSlide&list_id="+list_id+ "&slide_id="+parseInt(str[0])+"&order_num="+parseInt(str[1]), msuccess); } else jsErrorMessageBox("No slide selected?"); } function editRotationList() { var id = jsGetValue("ctrlRotationListsSel", 4); if (id > 0) jsSendPOSTRequest("action=get&type=infoRotationListEdit&id="+id, jsOpenAdminPopup); else jsErrorMessageBox("No rotation list selected?"); } function newRotationList() { var msuccess = function(txt) { refreshRotationListSel(); jsOpenAdminPopup(txt); } jsSendPOSTRequest("action=ctrl&type=newRotationList", msuccess); } function deleteRotationList() { var mcb_ok = function(txt) { jsSendPOSTRequest("action=ctrl&type=deleteRotationList&id="+id, refreshRotationListSel); } var id = jsGetValue("ctrlRotationListsSel", 4); if (id > 0) { jsConfirmBox("Are you <b>sure</b> you want to delete rotation list #"+id+"?", mcb_ok, 0, 0); } else jsErrorMessageBox("No rotation list selected?"); } // // Display slide editing and handling // function refreshDisplaySlideListSel() { jsRefreshItems("ctrlDisplaySlidesSel", "infoDisplaySlides", ""); } function updateDisplaySlide(id) { var vtitle = jsGetValue("ctrlDisplaySlideTitle", 1); var vtext = jsGetValue("ctrlDisplaySlideText", 1); jsSendPOSTRequest("action=ctrl&type=updateDisplaySlide&id="+id+"&title="+vtitle+"&text="+vtext, refreshDisplaySlideListSel); jsCloseAdminPopup(); return false; } function editDisplaySlide() { var id = jsGetValue("ctrlDisplaySlidesSel", 4); if (id > 0) jsSendPOSTRequest("action=get&type=infoDisplaySlideEdit&id="+id, jsOpenAdminPopup); else jsErrorMessageBox("No display slide selected?"); } function copyDisplaySlide() { var msuccess = function(txt) { refreshDisplaySlideListSel(); jsOpenAdminPopup(txt); } var id = jsGetValue("ctrlDisplaySlidesSel", 4); if (id > 0) jsSendPOSTRequest("action=ctrl&type=copyDisplaySlide&id="+id, msuccess); else jsErrorMessageBox("No display slide selected?"); } function newDisplaySlide() { var msuccess = function(txt) { refreshDisplaySlideListSel(); jsOpenAdminPopup(txt); } jsSendPOSTRequest("action=ctrl&type=newDisplaySlide", msuccess); } function deleteDisplaySlide() { var msuccess = function(txt) { refreshDisplaySlideListSel(); refreshRotationListSel(); } var mcb_ok = function(txt) { jsSendPOSTRequest("action=ctrl&type=deleteDisplaySlide&id="+id, msuccess); } var id = jsGetValue("ctrlDisplaySlidesSel", 4); if (id > 0) { jsConfirmBox("Are you <b>sure</b> you want to delete slide list #"+id+"?", mcb_ok, 0, 0); } else jsErrorMessageBox("No display slide selected?"); } function activateTempSlide() { var id = jsGetValue("ctrlDisplaySlidesSel", 4); var duration = jsGetValue("ctrlTempSlideDuration", 2); if (id > 0) jsSendPOSTRequest("action=ctrl&type=setTempSlide&id="+id+"&duration="+duration, jsMessageBox); else jsErrorMessageBox("No slide selected?"); } function skipToNextSlide() { jsSendPOSTRequest("action=ctrl&type=skipToNextSlide"); }