comparison admajax.js.php @ 1069:5f92fa5e683a

Refactor how the "AJAX" stuff works.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 24 Jan 2017 17:25:48 +0200
parents
children e23057465ca2
comparison
equal deleted inserted replaced
1068:50d005dd22d8 1069:5f92fa5e683a
1 <?php
2 //
3 // FAPWeb - Simple Web-based Demoparty Management System
4 // Party administration page AJAX javascript module
5 // (C) Copyright 2012-2017 Tecnic Software productions (TNSP)
6 //
7 $sessionType = "admin";
8 header("Content-Type: application/javascript");
9 require_once "mconfig.inc.php";
10 require_once "msite.inc.php";
11 require_once "msession.inc.php";
12
13 // Initiate SQL database connection
14 if (!stConnectSQLDB())
15 {
16 // Error occured, bail out early
17 cmPrintPageFooter();
18 exit;
19 }
20
21 // Fetch non-"hardcoded" settings from SQL database
22 stReloadSettings();
23
24 // Check if sessions are enabled
25 if (!stChkSetting("admPassword") || !stAdmSessionAuth(FALSE))
26 exit;
27
28 echo
29 "\n".
30 "var jsSettingsArgs = [];\n";
31
32 foreach (stExecSQL("SELECT * FROM settings_groups") as $group)
33 {
34 $args = array();
35 if (($res = stExecSQL("SELECT * FROM settings WHERE vgroup=".$group["id"])) !== false)
36 {
37 foreach ($res as $item)
38 {
39 switch ($item["vtype"])
40 {
41 case VT_STR:
42 case VT_TEXT: $type = 1; break;
43 case VT_INT: $type = 2; break;
44 case VT_BOOL: $type = 3; break;
45 }
46 $args[] = "\"".$item["key"]."\":".$type;
47 }
48 }
49
50 echo "jsSettingsArgs[".$group["id"]."] = {".implode(",", $args)."};\n";
51 }
52
53 echo
54 "\n".
55 "function jsUpdateSettings(id)\n".
56 "{\n".
57 " if (id in jsSettingsArgs)\n".
58 " jsSendPOSTRequest(\"action=update&type=settings&id=\"+id+\"&\"+jsMakePostArgs(jsSettingsArgs[id], \"st\", \"\"));\n".
59 " return false;\n".
60 "}\n".
61 "\n";
62
63 stCommonAJAX("admajax.php", "admlogout.php");
64 ?>
65
66 var activeAttendee = -1, prevAttendee = -1, activeAttendeeTmp = "";
67 var activeEntry = -1, prevEntry = -1, activeEntryTmp = "";
68
69 var registeredTabs = Object();
70 var activeTabs = Object();
71
72
73 //
74 // Tab related code
75 //
76 function jsUpdateTabList(tabset, extra)
77 {
78 var tabs = "";
79 var content = "";
80
81 // Update the tab header list for this tabset
82 for (var id in registeredTabs[tabset])
83 {
84 var thead = registeredTabs[tabset][id];
85 tabs += "<a id=\"tabHead"+ tabset + id +
86 "\" href=\"#\" onClick=\"jsSwitchActiveTab('"+tabset+"', '"+id+
87 "')\">"+ thead +"</a> ";
88
89 content += "<div id=\"tabCont"+ tabset + id +"\"></div>";
90 }
91
92 // Update the DOM elements
93 var item = document.getElementById("tabHeaders"+ tabset);
94 if (item) item.innerHTML = tabs + extra;
95
96 item = document.getElementById("tabContents"+ tabset);
97 if (item) item.innerHTML = content;
98 }
99
100
101 function jsRegisterTab(tabset, id, name)
102 {
103 // Create tabset object "array" if it does not exist
104 if (!registeredTabs[tabset])
105 registeredTabs[tabset] = Object();
106
107 // Register tab
108 registeredTabs[tabset][id] = name;
109 }
110
111
112 function jsSwitchActiveTab(tabset, tab)
113 {
114 // Go through all registered tabs to update their state
115 for (var id in registeredTabs[tabset])
116 {
117 var tabContent = document.getElementById("tabCont"+ tabset + id);
118 var tabHead = document.getElementById("tabHead"+ tabset + id);
119 if (tabContent && tabHead)
120 {
121 tabContent.style.display = (tab == id) ? "block" : "none";
122 tabHead.className = (tab == id) ? "active" : "inactive";
123 if (tab == id)
124 {
125 // Set active tab and refresh contents
126 activeTabs[tabset] = id;
127 setTimeout(function(qtabset, qid) {
128 switch (qtabset)
129 {
130 case "CM": refreshDispatchCM(qid); break;
131 case "CC": refreshDispatchCC(qid); break;
132 case "CS": refreshDispatchCS(qid); break;
133 default: jsMessageBox("Invalid tabset value: '"+ qtabset +"'.");
134 }
135 }, 10, tabset, id);
136 jsCancelUploadCBS();
137 }
138 else
139 {
140 // Clear inactive tabs
141 tabContent.innerHTML = "";
142 }
143 }
144 }
145 }
146
147
148 //
149 // Admin interface specific popups
150 //
151 function jsHandleAdminPopupKeys(ev)
152 {
153 ev = ev || window.event;
154 var key = ev.keyCode ? ev.keyCode : ev.which;
155 if (key == 27)
156 {
157 jsCloseAdminPopup();
158 return false;
159 }
160 else
161 return true;
162 }
163
164
165 function jsCloseAdminPopup()
166 {
167 var nitem = document.getElementById("adminPopup");
168 if (nitem)
169 {
170 document.onkeydown = null;
171
172 nitem.innerHTML = "";
173 nitem.style.display = "none";
174 }
175 }
176
177
178 function jsOpenAdminPopup(txt)
179 {
180 var nitem = document.getElementById("adminPopup");
181 if (nitem)
182 {
183 document.onkeydown = jsHandleAdminPopupKeys;
184
185 nitem.innerHTML = txt;
186 nitem.style.display = "block";
187 }
188 }
189
190
191 //
192 // Generic element refresh
193 //
194 function jsRefreshItems(id,name,extra)
195 {
196 var msuccess = function(txt)
197 {
198 var nitem = document.getElementById(id);
199 if (nitem) nitem.innerHTML = txt;
200 }
201
202 jsSendPOSTRequest("action=get&type="+name+extra, msuccess);
203 }
204
205
206 function jsDeleteItem(id,prefix,type,func,dsc,dsc2)
207 {
208 var msuccess = function(txt)
209 {
210 var item = document.getElementById(prefix+id);
211 item.style.display = "none";
212 setTimeout(func, 50);
213 }
214
215 // Clearly mark the element when asking confirmation
216 var item = document.getElementById(prefix+id);
217 var tmp = item.className;
218 item.className += " deleteWarning";
219
220 // Ask confirmation for deletion
221 var mcb_ok = function (data)
222 {
223 jsSendPOSTRequest("action=delete&type="+type+"&id="+id, msuccess);
224 item.className = tmp;
225 }
226
227 var mcb_cancel = function (data)
228 {
229 item.className = tmp;
230 }
231
232 if (dsc)
233 jsConfirmBox("Are you sure you want to delete "+dsc+" #"+id+"?", mcb_ok, mcb_cancel, 0);
234 else
235 jsConfirmBox(dsc2, mcb_ok, mcb_cancel, 0);
236 }
237
238
239 function jsRefreshPanels(id, tab, args, set_default)
240 {
241 var msuccess = function(txt)
242 {
243 var nitem = document.getElementById(tab);
244 if (nitem)
245 {
246 if (nitem.innerHTML == "")
247 {
248 nitem.innerHTML =
249 "<div id=\"tabHeaders"+id+"\" class=\"tabHeadersSub\"></div>" +
250 "<div id=\"tabContents"+id+"\" class=\"tabContentsSub\"></div>";
251 }
252
253 try {
254 var tmp = JSON.parse("{"+ txt +"}");
255 registeredTabs[id] = tmp;
256 jsUpdateTabList(id, "");
257 if (activeTabs[id])
258 jsSwitchActiveTab(id, activeTabs[id]);
259 else
260 if (set_default == "*")
261 {
262 for (var nid in registeredTabs[id])
263 {
264 jsSwitchActiveTab(id, nid);
265 break;
266 }
267 }
268 else
269 if (set_default != "")
270 jsSwitchActiveTab(id, set_default);
271 }
272 catch (err) {
273 jsErrorMessageBox("JSON.parse("+ txt +") failure: "+ err);
274 }
275 }
276 }
277
278 jsSendPOSTRequest("action=get&type="+args, msuccess);
279 }
280
281
282 function refreshDispatchCC(id)
283 {
284 switch (id)
285 {
286 case "News" : jsRefreshItems("tabContCCNews", "news", ""); break;
287 case "Attendees" : jsRefreshItems("tabContCCAttendees", "attendees", ""); activeAttendee = -1; break;
288 case "Voting" : jsRefreshItems("tabContCCVoting", "voters", ""); break;
289 case "Compos" : jsRefreshItems("tabContCCCompos", "compos", ""); break;
290 case "InfoSys" : jsRefreshItems("tabContCCInfoSys", "infoMain", ""); break;
291 case "Settings" : jsRefreshPanels("CS", "tabContCCSettings", "settingslist", "*"); break;
292 case "Entries" : jsRefreshPanels("CM", "tabContCCEntries", "compolist", ""); break;
293 default : alert("Invalid id: '"+ id +"'.'");
294 }
295 }
296
297
298 function refreshDispatchCS(id)
299 {
300 jsRefreshItems("tabContCS"+ id, "settings", "&id="+ id);
301 }
302
303
304 function refreshDispatchCM(id)
305 {
306 prevEntry = activeEntry = -1;
307 jsRefreshItems("tabContCM"+ id, "entries", "&id="+ id);
308 }
309
310
311 //
312 // Site news management
313 //
314 function addNews()
315 {
316 var args = jsMakePostArgs({"title":1,"text":1,"author":1}, "nn", "");
317
318 var msuccess = function(txt)
319 {
320 setTimeout(function () { refreshDispatchCC("News"); }, 50);
321 }
322
323 if (args != "")
324 jsSendPOSTRequest("action=add&type=news&"+args, msuccess);
325
326 return false;
327 }
328
329
330 function deleteNews(id)
331 {
332 jsDeleteItem(id, "news", "news", function() { refreshDispatchCC("News"); }, "news item");
333 }
334
335
336 function updateNews(id)
337 {
338 var args = jsMakePostArgs({"title":1,"text":1,"author":1}, "ne", id);
339
340 var msuccess = function(txt)
341 {
342 jsRefreshItems("news"+id, "newsitem", "&id="+id);
343 }
344
345 if (args != "")
346 jsSendPOSTRequest("action=update&type=news&id="+id+"&"+args, msuccess);
347 }
348
349
350 //
351 // Visitor/attendee management
352 //
353 function addAttendee()
354 {
355 var args = jsMakePostArgs({"name":1,"groups":1,"oneliner":1,"email":1}, "ne", "x");
356
357 var msuccess = function(txt)
358 {
359 setTimeout(function() { refreshDispatchCC("Attendees"); }, 50);
360 }
361
362 if (args != "")
363 jsSendPOSTRequest("action=add&type=attendees&"+args, msuccess);
364
365 return false;
366 }
367
368
369 function deleteAttendee(id)
370 {
371 jsDeleteItem(id, "attendee", "attendees", function () { refreshDispatchCC("Attendees"); }, "attendee");
372 }
373
374
375 function updateAttendee(id)
376 {
377 var args = jsMakePostArgs({"name":1,"groups":1,"oneliner":1,"email":1,"reghost":1}, "at", id);
378
379 var msuccess = function(txt)
380 {
381 activateAttendee(-1);
382 }
383
384 if (args != "")
385 jsSendPOSTRequest("action=update&type=attendees&id="+id+"&"+args, msuccess);
386 }
387
388
389 function activateAttendee(id)
390 {
391 var msuccess1 = function(txt)
392 {
393 var nitem = document.getElementById("attendee"+prevAttendee);
394 if (nitem)
395 {
396 nitem.innerHTML = txt;
397 nitem.className = activeAttendeeTmp;
398 }
399 }
400
401 var msuccess2 = function(txt)
402 {
403 var nitem = document.getElementById("attendee"+activeAttendee);
404 if (nitem)
405 {
406 nitem.innerHTML = txt;
407 activeAttendeeTmp = nitem.className;
408 nitem.className += " active";
409 activeAttendee = id;
410 }
411 }
412
413 if (activeAttendee != id)
414 {
415 prevAttendee = activeAttendee;
416 activeAttendee = id;
417
418 if (prevAttendee != -1)
419 jsSendPOSTRequest("action=get&type=attendee&id="+prevAttendee+"&edit=0", msuccess1);
420
421 if (activeAttendee != -1)
422 jsSendPOSTRequest("action=get&type=attendee&id="+activeAttendee+"&edit=1", msuccess2);
423 }
424 }
425
426
427 //
428 // Compo management
429 //
430 function addCompo()
431 {
432 var args = jsMakePostArgs({"name":1, "description":1}, "nc", "");
433
434 var msuccess = function(txt)
435 {
436 setTimeout(function () { refreshDispatchCC("Compos"); }, 50);
437 }
438
439 if (args != "")
440 jsSendPOSTRequest("action=add&type=compo&"+args, msuccess);
441 return false;
442 }
443
444
445 function updateCompoType(id)
446 {
447 var msuccess = function(txt)
448 {
449 jsRefreshItems("compo"+id, "compo", "&id="+id);
450 }
451
452 jsSendPOSTRequest("action=update&type=compotype&id="+id+"&ctype="+jsGetValue("cotype"+id+"Sel", 4), msuccess);
453 }
454
455
456 function updateCompoVoting(id)
457 {
458 var msuccess = function(txt)
459 {
460 jsRefreshItems("covoting"+id, "compovoting", "&id="+id);
461 }
462
463 jsSendPOSTRequest("action=update&type=compovoting&id="+id+"&voting="+jsGetValue("covotingbutton"+id, 3), msuccess);
464 }
465
466
467 function updateCompo(id)
468 {
469 var args = jsMakePostArgs({"name":1, "description":1, "notes":1, "visible":3, "voting":3, "show_authors":3, "cpath":1, "preview_type":4}, "co", id, true);
470
471 var msuccess = function(txt)
472 {
473 jsRefreshItems("compo"+id, "compo", "&id="+id);
474 }
475
476 if (args != "")
477 jsSendPOSTRequest("action=update&type=compo&id="+id+"&"+args, msuccess);
478 }
479
480
481 function deleteCompo(id)
482 {
483 jsDeleteItem(id, "compo", "compo", function () { refreshDispatchCC("Compos"); }, 0,
484 "Are you ABSOLUTELY sure you want to delete compo #"+id+"? "+
485 "This will delete all votes AND entries related to it!");
486 }
487
488
489 //
490 // Entry management
491 //
492 function refreshEntryCompos()
493 {
494 setTimeout(function () { refreshDispatchCC("Entries"); }, 50);
495 }
496
497
498 function activateEntry(id, force)
499 {
500 var msuccess1 = function(txt)
501 {
502 var nitem = document.getElementById("entry"+prevEntry);
503 if (nitem)
504 {
505 nitem.innerHTML = txt;
506 nitem.className = activeEntryTmp;
507 }
508 }
509
510 var msuccess2 = function(txt)
511 {
512 var nitem = document.getElementById("entry"+activeEntry);
513 if (nitem)
514 {
515 nitem.innerHTML = txt;
516 activeEntryTmp = nitem.className;
517 nitem.className += " active";
518 activeEntry = id;
519 }
520 }
521
522 if (activeEntry != id || force)
523 {
524 jsCancelUploadCBS();
525
526 prevEntry = activeEntry;
527 activeEntry = id;
528
529 if (prevEntry != -1)
530 jsSendPOSTRequest("action=get&type=entry&id="+prevEntry+"&edit=0", msuccess1);
531
532 if (activeEntry != -1)
533 jsSendPOSTRequest("action=get&type=entry&id="+activeEntry+"&edit=1", msuccess2);
534 }
535 }
536
537
538 function addEntry(id)
539 {
540 var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1, "notes":1, "evalue":2}, "ne", id, true);
541
542 jsCancelUploadCBS();
543
544 var msuccess = function(txt)
545 {
546 setTimeout(function (q) { refreshDispatchCM(qid); }, 50, id);
547 refreshEntryCompos();
548 }
549
550 if (args != "")
551 jsSendPOSTRequest("action=add&type=entry&compo_id="+id+"&"+args, msuccess);
552
553 return false;
554 }
555
556
557 function updateEntry(cid, id, edit)
558 {
559 var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1, "notes":1, "compo_id":4, "evalue":2, "preview_type":4}, "en", id, true);
560 var has_id = "compo_id" in lastPostArgs;
561 var compo_id = lastPostArgs["compo_id"];
562
563 jsCancelUploadCBS();
564
565 if (!("compo_id" in lastPostArgs))
566 {
567 args += "&compo_id=" + cid;
568 compo_id = cid;
569 }
570
571 var msuccess = function(txt)
572 {
573 if (cid != compo_id)
574 {
575 var nitem = document.getElementById("entry"+ id);
576 if (nitem)
577 nitem.style.display = "none";
578 }
579 else
580 activateEntry(edit ? id : -1, true);
581 refreshEntryCompos();
582 }
583
584 var mcb_ok = function(data)
585 {
586 jsSendPOSTRequest("action=update&type=entry&id="+id+"&edit="+edit+"&"+args, msuccess);
587 refreshEntryCompos();
588 }
589
590 var mcb_cancel = function(data)
591 {
592 activeEntry = -1;
593 }
594
595 if (args != "")
596 {
597 if (cid != compo_id)
598 {
599 jsConfirmBox("Are you sure you want to change entry #"+id+
600 "'s compo from "+cid+" to "+compo_id+"?", mcb_ok, mcb_cancel);
601 }
602 else
603 mcb_ok();
604 }
605 }
606
607
608 function deleteEntry(cid, id)
609 {
610 jsCancelUploadCBS();
611 jsDeleteItem(id, "entry", "entries", function() { refreshDispatchCM(cid); refreshEntryCompos(); }, "entry");
612 }
613
614
615 //
616 // Votekey management
617 //
618 function voteKeyInfoRefresh()
619 {
620 jsRefreshItems("vkeyInfo", "votekey", "info");
621 }
622
623
624 function voteKeyRefresh(id)
625 {
626 var msuccess2 = function(txt)
627 {
628 var nitem = document.getElementById("vkey"+id);
629 if (nitem)
630 nitem.className = txt;
631 voteKeyInfoRefresh();
632 }
633
634 var msuccess1 = function(txt)
635 {
636 var nitem = document.getElementById("vkey"+id);
637 if (nitem)
638 nitem.innerHTML = txt;
639 voteKeyInfoRefresh();
640 }
641
642 jsSendPOSTRequest("action=get&type=votekey&id="+id, msuccess1);
643 jsSendPOSTRequest("action=get&type=votekeyclass&id="+id, msuccess2);
644 }
645
646
647 function voteKeyUpdate(id, type, args)
648 {
649 var msuccess = function(txt)
650 {
651 voteKeyRefresh(id);
652 voteKeyInfoRefresh();
653 }
654
655 jsSendPOSTRequest("action=votekey&type="+type+"&id="+id+"&"+args, msuccess);
656 }
657
658
659 function voteKeySetActive(id)
660 {
661 var args = jsMakePostArgs({"active":3}, "vk", id);
662
663 var mcb_ok = function (data)
664 {
665 voteKeyUpdate(id, "active", args);
666 }
667
668 var mcb_cancel = function (data)
669 {
670 voteKeyRefresh(id);
671 }
672
673 if (lastPostArgs["active"] == 0)
674 jsConfirmBox("Are you sure you want to deactivate vote key #"+id+"?", mcb_ok, mcb_cancel, 0);
675 else
676 mcb_ok(0);
677 }
678
679
680 function voteKeyAssign(id, mode)
681 {
682 var args = jsMakePostArgs({"key_id":2}, "vk", id);
683
684 var mcb_ok = function (data)
685 {
686 voteKeyUpdate(id, (mode ? "assign" : "clear"), args);
687 }
688
689 if (mode == 0)
690 jsConfirmBox("Are you sure you want to clear vote key assign #"+id+"?", mcb_ok, 0, 0);
691 else
692 mcb_ok(0);
693 }
694
695
696 //
697 // Misc functions
698 //
699 function showScreenCmd(str)
700 {
701 jsSendPOSTRequest("action=screencmd&cmd="+str);
702 }
703
704
705 function performSystemCheck()
706 {
707 jsSendPOSTRequest("action=check", jsMessageBox);
708 }
709
710
711 function generateEntryPositions(id, patch)
712 {
713 var msuccess = function (data)
714 {
715 refreshDispatchCM(id);
716 refreshCurrEntryData();
717 refreshCurrEntryListData();
718 }
719
720 var mcb_ok = function (data)
721 {
722 if (id == 0)
723 jsSendPOSTRequest("action=randomize&type=all&patch="+patch, msuccess);
724 else
725 jsSendPOSTRequest("action=randomize&type=compo&id="+id+"&patch="+patch, msuccess);
726 }
727
728 if (patch == 0)
729 {
730 jsConfirmBox("Are you <b>ABSOLUTELY CERTAIN</b> you want to delete and regenerate entry show positions "+
731 (id == 0 ? "for ALL compos" : "for this compo") +"? "+
732 "<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);
733 }
734 else
735 mcb_ok(0);
736 }
737
738
739 //
740 // Competition control
741 //
742 function setShowMode(mode)
743 {
744 jsSendPOSTRequest("action=ctrl&type=setShowMode&mode="+mode);
745 }
746
747
748 function refreshCurrEntryData()
749 {
750 jsRefreshItems("ctrlCurrCompoData", "infoCurrCompoData", "");
751 }
752
753
754 function refreshCurrEntryListData()
755 {
756 jsRefreshItems("ctrlEntryList", "infoCurrEntryList", "");
757 refreshCurrEntryData();
758 }
759
760
761 function activateCompo()
762 {
763 jsSendPOSTRequest("action=ctrl&type=setCompoID&id="+jsGetValue("ctrlCompoListSel", 4), refreshCurrEntryListData);
764 }
765
766
767 function setSelectedEntry()
768 {
769 jsSendPOSTRequest("action=ctrl&type=setEntry&index="+jsGetValue("ctrlEntryListSel", 4), refreshCurrEntryData);
770 }
771
772
773 function switchEntry(dir)
774 {
775 jsSendPOSTRequest("action=ctrl&type="+ (dir < 0 ? "prevEntry" : "nextEntry"), refreshCurrEntryListData);
776 }
777
778
779 //
780 // Rotation list editing and handling
781 //
782 function refreshRotationListSel()
783 {
784 jsRefreshItems("ctrlRotationListsSel", "infoRotationLists", "");
785 }
786
787
788 function refreshRotationListEdit(id)
789 {
790 jsRefreshItems("ctrlRotationListEdit", "infoRotationListEdit", "&id="+id+"&full=0");
791 refreshRotationListSel();
792 }
793
794
795 function refreshActiveRotationList()
796 {
797 jsRefreshItems("ctrlActiveRotationList", "infoActiveRotationList", "");
798 }
799
800
801 function setRotateDuration()
802 {
803 var duration = jsGetValue("ctrlRotSlideDuration", 2);
804 jsSendPOSTRequest("action=ctrl&type=setRotateDuration&duration="+duration);
805 }
806
807
808 function setActiveRotationList()
809 {
810 var id = jsGetValue("ctrlRotationListsSel", 4);
811 if (id > 0)
812 jsSendPOSTRequest("action=ctrl&type=setActiveRotationList&id="+id, refreshActiveRotationList);
813 else
814 jsErrorMessageBox("No rotation list selected?");
815 }
816
817
818 function updateRotationList(id)
819 {
820 var name = jsGetValue("ctrlEDRotationListName", 1);
821 jsSendPOSTRequest("action=ctrl&type=updateRotationList&id="+id+"&name="+name, refreshRotationListSel);
822 }
823
824
825 function moveRotationListSlide(list_id, dir)
826 {
827 var msuccess = function(txt)
828 {
829 refreshRotationListEdit(list_id);
830 }
831
832 var slide = jsGetValue("ctrlEDRotationListSel", 4);
833 if (slide)
834 {
835 var str = slide.split("_");
836 jsSendPOSTRequest("action=ctrl&type=moveRotationListSlide&list_id="+list_id+
837 "&slide_id="+parseInt(str[0])+"&order_num="+parseInt(str[1])+"&dir="+dir, msuccess);
838 }
839 else
840 jsErrorMessageBox("No slide selected?");
841 }
842
843
844 function addRotationListSlide(list_id)
845 {
846 var msuccess = function(txt)
847 {
848 refreshRotationListEdit(list_id);
849 }
850
851 var slide_id = jsGetValue("ctrlEDDisplaySlidesSel", 4);
852 if (slide_id > 0)
853 jsSendPOSTRequest("action=ctrl&type=addRotationListSlide&list_id="+list_id+"&slide_id="+slide_id, msuccess);
854 else
855 jsErrorMessageBox("No slide selected?");
856 }
857
858
859 function removeRotationListSlide(list_id)
860 {
861 var msuccess = function(txt)
862 {
863 refreshRotationListEdit(list_id);
864 }
865
866 var slide = jsGetValue("ctrlEDRotationListSel", 4);
867 if (slide)
868 {
869 var str = slide.split("_");
870 jsSendPOSTRequest("action=ctrl&type=removeRotationListSlide&list_id="+list_id+
871 "&slide_id="+parseInt(str[0])+"&order_num="+parseInt(str[1]), msuccess);
872 }
873 else
874 jsErrorMessageBox("No slide selected?");
875 }
876
877
878 function editRotationList()
879 {
880 var id = jsGetValue("ctrlRotationListsSel", 4);
881 if (id > 0)
882 jsSendPOSTRequest("action=get&type=infoRotationListEdit&id="+id, jsOpenAdminPopup);
883 else
884 jsErrorMessageBox("No rotation list selected?");
885 }
886
887
888 function newRotationList()
889 {
890 var msuccess = function(txt)
891 {
892 refreshRotationListSel();
893 jsOpenAdminPopup(txt);
894 }
895
896 jsSendPOSTRequest("action=ctrl&type=newRotationList", msuccess);
897 }
898
899
900 function deleteRotationList()
901 {
902 var mcb_ok = function(txt)
903 {
904 jsSendPOSTRequest("action=ctrl&type=deleteRotationList&id="+id, refreshRotationListSel);
905 }
906
907 var id = jsGetValue("ctrlRotationListsSel", 4);
908 if (id > 0)
909 {
910 jsConfirmBox("Are you <b>sure</b> you want to delete rotation list #"+id+"?",
911 mcb_ok, 0, 0);
912 }
913 else
914 jsErrorMessageBox("No rotation list selected?");
915 }
916
917
918 //
919 // Display slide editing and handling
920 //
921 function refreshDisplaySlideListSel()
922 {
923 jsRefreshItems("ctrlDisplaySlidesSel", "infoDisplaySlides", "");
924 }
925
926
927 function updateDisplaySlide(id)
928 {
929 var vtitle = jsGetValue("ctrlDisplaySlideTitle", 1);
930 var vtext = jsGetValue("ctrlDisplaySlideText", 1);
931 jsSendPOSTRequest("action=ctrl&type=updateDisplaySlide&id="+id+"&title="+vtitle+"&text="+vtext, refreshDisplaySlideListSel);
932 jsCloseAdminPopup();
933 return false;
934 }
935
936
937 function editDisplaySlide()
938 {
939 var id = jsGetValue("ctrlDisplaySlidesSel", 4);
940 if (id > 0)
941 jsSendPOSTRequest("action=get&type=infoDisplaySlideEdit&id="+id, jsOpenAdminPopup);
942 else
943 jsErrorMessageBox("No display slide selected?");
944 }
945
946
947 function copyDisplaySlide()
948 {
949 var msuccess = function(txt)
950 {
951 refreshDisplaySlideListSel();
952 jsOpenAdminPopup(txt);
953 }
954
955 var id = jsGetValue("ctrlDisplaySlidesSel", 4);
956 if (id > 0)
957 jsSendPOSTRequest("action=ctrl&type=copyDisplaySlide&id="+id, msuccess);
958 else
959 jsErrorMessageBox("No display slide selected?");
960 }
961
962
963 function newDisplaySlide()
964 {
965 var msuccess = function(txt)
966 {
967 refreshDisplaySlideListSel();
968 jsOpenAdminPopup(txt);
969 }
970
971 jsSendPOSTRequest("action=ctrl&type=newDisplaySlide", msuccess);
972 }
973
974
975 function deleteDisplaySlide()
976 {
977 var msuccess = function(txt)
978 {
979 refreshDisplaySlideListSel();
980 refreshRotationListSel();
981 }
982
983 var mcb_ok = function(txt)
984 {
985 jsSendPOSTRequest("action=ctrl&type=deleteDisplaySlide&id="+id, msuccess);
986 }
987
988 var id = jsGetValue("ctrlDisplaySlidesSel", 4);
989 if (id > 0)
990 {
991 jsConfirmBox("Are you <b>sure</b> you want to delete slide list #"+id+"?",
992 mcb_ok, 0, 0);
993 }
994 else
995 jsErrorMessageBox("No display slide selected?");
996 }
997
998
999 function activateTempSlide()
1000 {
1001 var id = jsGetValue("ctrlDisplaySlidesSel", 4);
1002 var duration = jsGetValue("ctrlTempSlideDuration", 2);
1003 if (id > 0)
1004 jsSendPOSTRequest("action=ctrl&type=setTempSlide&id="+id+"&duration="+duration, jsMessageBox);
1005 else
1006 jsErrorMessageBox("No slide selected?");
1007 }
1008
1009
1010 function skipToNextSlide()
1011 {
1012 jsSendPOSTRequest("action=ctrl&type=skipToNextSlide");
1013 }