Mercurial > hg > fapweb
diff admin.php @ 599:eebbc96d7fe5
Move javascript code from admin.php to a separate file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 26 Oct 2014 22:46:36 +0200 |
parents | b09fdf99b54b |
children | a42efdc2cca7 |
line wrap: on
line diff
--- a/admin.php Sun Oct 26 22:09:32 2014 +0200 +++ b/admin.php Sun Oct 26 22:46:36 2014 +0200 @@ -104,702 +104,8 @@ ?> <script type="text/javascript"> // <? stCreateSettingsData(); stCommonAJAX("admajax.php", "admlogout.php", FALSE, TRUE); ?> - - -var activeAttendee = -1, prevAttendee = -1; -var activeTmp = ""; - - -function jsCloseAdminPopup() -{ - var nitem = document.getElementById("adminPopup"); - if (nitem) - { - nitem.innerHTML = ""; - nitem.style.display = "none"; - } -} - - -function jsOpenAdminPopup(txt) -{ - var nitem = document.getElementById("adminPopup"); - if (nitem) - { - nitem.innerHTML = txt; - nitem.style.display = "block"; - } -} - - -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) -{ - 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.style.background; - item.style.background = "red"; - - // Ask confirmation for deletion - var mcb_ok = function (data) - { - jsSendPOSTRequest("action=delete&type="+type+"&id="+id, msuccess); - item.style.background = tmp; - } - - var mcb_cancel = function (data) - { - item.style.background = tmp; - } - - jsConfirmBox("Are you sure you want to delete "+dsc+" #"+id+"?", mcb_ok, mcb_cancel, 0); -} - - -function refreshDispatchCC(id) -{ - switch (id) - { - case "Settings": jsRefreshItems("tabContCCSettings", "settings", ""); break; - case "News": jsRefreshItems("tabContCCNews", "news", ""); break; - case "Attendees": jsRefreshItems("tabContCCAttendees", "attendees", ""); break; - case "Voting": jsRefreshItems("tabContCCVoting", "voters", ""); break; - case "Compos": jsRefreshItems("tabContCCCompos", "compos", ""); break; - case "InfoSys": jsRefreshItems("tabContCCInfoSys", "infoMain", ""); break; - case "Entries": refreshCCEntries(); break; - } -} - - -function refreshCCAttendee(id) -{ - jsRefreshItems("attendee"+ id, "attendee", "&id="+ id); -} - - -function refreshCCEntries() -{ - var msuccess = function(txt) - { - var nitem = document.getElementById("tabContCCEntries"); - if (nitem) - { - if (nitem.innerHTML == "") - { - nitem.innerHTML = - "<div id=\"tabHeadersCM\" class=\"tabHeadersSub\"></div>" + - "<div id=\"tabContentsCM\" class=\"tabContentsSub\"></div>"; - } - - try { - var tmp = JSON.parse("{"+ txt +"}"); - registeredTabs["CM"] = tmp; - jsUpdateTabList("CM", ""); - if (activeTabs["CM"]) - jsSwitchActiveTab("CM", activeTabs["CM"]); - } - catch (err) { - jsMessageBox("JSON.parse("+ txt +") failure: "+ err); - } - } - } - - jsSendPOSTRequest("action=get&type=compolist", msuccess); -} - - -function refreshCMEntry(id) -{ - jsRefreshItems("entry"+ id, "entry", "&id="+ id); -} - - -function refreshDispatchCM(id) -{ - jsRefreshItems("tabContCM"+ id, "entries", "&id="+ id); -} - - -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); -} - - -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}, "at", id); - - var msuccess = function(txt) - { - jsRefreshItems("attendee"+id, "attendee", "&id="+id+"&edit=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.style.background = activeTmp; - } - } - - var msuccess2 = function(txt) - { - var nitem = document.getElementById("attendee"+id); - if (nitem) - { - nitem.innerHTML = txt; - activeTmp = nitem.style.background; - nitem.style.background = "green"; - activeAttendee = id; - } - } - - if (activeAttendee != id) - { - prevAttendee = activeAttendee; - activeAttendee = id; - - if (prevAttendee != -1) - jsSendPOSTRequest("action=get&type=attendee&id="+prevAttendee+"&edit=0", msuccess1); - - jsSendPOSTRequest("action=get&type=attendee&id="+id+"&edit=1", msuccess2); - } -} - - -function addCompo() -{ - var args = jsMakePostArgs({"name":1, "description":1}, "nc", ""); - - var msuccess = function(txt) - { - setTimeout("refreshDispatchCC('Compos');", 50); - } - - if (args != "") - jsSendPOSTRequest("action=add&type=compo&"+args, msuccess); - return false; -} - - -function updateCompo(id) -{ - var args = jsMakePostArgs({"name":1, "description":1, "visible":3, "voting":3, "show_authors":3}, "co", id); - - var msuccess = function(txt) - { - jsRefreshItems("compo"+id, "compo", "&id="+id); - } - - if (args != "") - jsSendPOSTRequest("action=update&type=compo&id="+id+"&"+args, msuccess); -} - - -function addEntry(id) -{ - var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1}, "ne", id); - - 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) -{ - var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1, "compo_id":2}, "en", id); - var compo_id = lastPostArgs["compo_id"]; - - var msuccess = function(txt) - { - if (cid != compo_id) - { - var nitem = document.getElementById("entry"+ id); - if (nitem) - nitem.style.display = "none"; - } - else - setTimeout("refreshCMEntry("+ id +");", 50); - } - - if (args != "") - jsSendPOSTRequest("action=update&type=entry&id="+id+"&"+args, msuccess); -} - - -function deleteEntry(cid, id) -{ - jsDeleteItem(id, "entry", "entries", "refreshDispatchCM("+ cid +");", "entry"); -} - - -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); -} - - -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>sure</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!</b>", mcb_ok, 0, 0); - } - else - mcb_ok(0); -} - - -// -// Competition control -// -function setShowMode(mode) -{ - jsSendPOSTRequest("action=ctrl&type=setShowMode&mode="+mode); -} - - -function refreshCurrEntryData() -{ - jsRefreshItems("ctrlCurrEntryData", "infoCurrEntryData", ""); -} - - -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 - jsMessageBox("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 - jsMessageBox("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 - jsMessageBox("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 - jsMessageBox("No slide selected?"); -} - - -function editRotationList() -{ - var id = jsGetValue("ctrlRotationListsSel", 4); - if (id > 0) - jsSendPOSTRequest("action=get&type=infoRotationListEdit&id="+id, jsOpenAdminPopup); - else - jsMessageBox("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 - jsMessageBox("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 - jsMessageBox("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 - jsMessageBox("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 - jsMessageBox("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 - jsMessageBox("No slide selected?"); -} - -function skipToNextSlide() -{ - jsSendPOSTRequest("action=ctrl&type=skipToNextSlide"); -} - </script> +<script type="text/javascript" src="admin.js"></script> <!-- ========================== -->