e9f88042e302e7eb6f0ec5e655d32c645acc1435
[citadel] / webcit / static / wclib.js
1 /*jshint strict: false, bitwise: false */
2 /*global document, window, Ajax, currentlyMarkedRows, Event, event, taskViewActivate, setTimeout, fillRooms, $, ctdlLocalPrefs, currentDropTargets, iconBarRoomList, confirm, Effect */
3 /*
4  * JavaScript function library for WebCit.
5  *
6  * Copyright (c) 2005-2012 by the citadel.org team
7  *
8  * This program is open source software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License, version 3.
10  * the Free Software Foundation, either version 3 of the License, or
11  * 
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * 
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 var browserType;
23 var room_is_trash = 0;
24
25 var currentlyExpandedFloor = null;
26 var roomlist = null;
27
28 var supportsAddEventListener = (!!document.addEventListener);
29 var today = new Date();
30
31 var wc_log = "";
32 if (document.all) {browserType = "ie";}
33 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
34         browserType= "gecko";
35 }
36 var ns6=document.getElementById&&!document.all;
37 Event.observe(window, 'load', ToggleTaskDateOrNoDateActivate);
38 Event.observe(window, 'load', taskViewActivate);
39 //document.observe("dom:loaded", setupPrefEngine);
40 document.observe("dom:loaded", setupIconBar);
41 function ctdlRandomString()  {
42         return((Math.random()+'').substr(3));
43 }
44 function strcmp ( str1, str2 ) {
45     // http://kevin.vanzonneveld.net
46     // +   original by: Waldo Malqui Silva
47     // +      input by: Steve Hilder
48     // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
49     // +    revised by: gorthaur
50     // *     example 1: strcmp( 'waldo', 'owald' );
51     // *     returns 1: 1
52     // *     example 2: strcmp( 'owald', 'waldo' );
53     // *     returns 2: -1
54  
55     return ( ( str1 === str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
56 }
57
58 function ctdlMarkLog(Which, Status)
59 {
60     if (Status) {
61         document.getElementById(Which).checked = false;
62     }
63     else {
64         document.getElementById(Which).checked = true;
65     }
66  
67 }
68 function ToggleLogEnable(Which)
69 {
70     var p;
71     var element = document.getElementById(Which);
72     if (element.hasOwnProperty('checked')) {
73         var Status = element.checked;
74         if (!Status) {
75             p = encodeURI('g_cmd=LOGS ' + Which + '|0');
76         }
77         else {
78             p = encodeURI('g_cmd=LOGS ' + Which + '|1');
79         }
80         new Ajax.Request('ajax_servcmd', {
81             method: 'post',
82             parameters: p,
83             onComplete: ctdlMarkLog(Which, Status)
84         });
85     }
86 }
87
88 function SMTPRunQueue()
89 {
90     var p;
91
92     p= encodeURI('g_cmd=SMTP runqueue');
93     new Ajax.Request('ajax_servcmd', {
94         method: 'post',
95         parameters: p,
96         onComplete: function(transport) { ajax_important_message(transport.responseText.substr(4));}
97     });
98 }
99
100 function NetworkSynchronizeRoom(NodeName)
101 {
102     var p;
103
104     p= encodeURI('g_cmd=NSYN ' + NodeName);
105     new Ajax.Request('ajax_servcmd', {
106         method: 'post',
107         parameters: p,
108         onComplete: function(transport) { ajax_important_message(transport.responseText.substr(4));}
109     });
110 }
111 function ToggleVisibility ($Which)
112 {
113     if (document.getElementById)
114     {
115         if (document.getElementById($Which).style.display  === "none") {
116             document.getElementById($Which).style.display  = "inline";
117         }
118         else {
119             document.getElementById($Which).style.display  = "none";
120         }
121     }
122 }
123
124 function emptyElement(element) {
125   var childNodes = element.childNodes;
126   for(var i=0; i<childNodes.length; i++) {
127     try {
128     element.removeChild(childNodes[i]);
129     } catch (e) {
130       wCLog(e+"|"+e.description);
131     }
132   }
133 }
134 // Implements superior internet explorer 'extract all child text from element' feature'.
135 // Falls back on buggy, patent violating standardized method
136 function getTextContent(element) {
137   if (element.textContent === undefined) {
138     return element.innerText;
139   }
140   return element.textContent;
141 }
142 /** Same reasons as above */
143 function setTextContent(element, textContent) {
144   if(element.textContent === undefined) {
145     element.innerText = textContent;
146   } else {
147   element.textContent = textContent;
148   }
149 }
150
151 // We love string tokenizers.
152 function extract_token(source_string, token_num, delimiter) {
153     var j, i = 0;
154     var extracted_string = source_string;
155
156     if (token_num > 0) {
157         for (i=0; i<token_num; ++i) {
158             j = extracted_string.indexOf(delimiter);
159             if (j >= 0) {
160                 extracted_string = extracted_string.substr(j+1);
161             }
162         }
163     }
164
165     j = extracted_string.indexOf(delimiter);
166     if (j >= 0) {
167         extracted_string = extracted_string.substr(0, j);
168     }
169
170     return extracted_string;
171 }
172
173 function CtdlSpawnContextMenu(event, source) {
174   // remove any existing menus
175   disintergrateContextMenus(null);
176   var x = event.clientX-10; // cut a few pixels out so our mouseout works right
177   var y = event.clientY-10;
178   var contextDIV = document.createElement("div");
179   contextDIV.setAttribute("id", "ctdlContextMenu");
180   document.body.appendChild(contextDIV);
181   var sourceChildren = source.childNodes;
182   for(var j=0; j<sourceChildren.length; j++) {
183     contextDIV.appendChild(sourceChildren[j].cloneNode(true));
184   }
185   var leftRule = "left: "+x+"px;";
186   contextDIV.setAttribute("style", leftRule);
187   contextDIV.setAttribute("actual", leftRule);
188   contextDIV.style.top = y+"px";
189   contextDIV.style.display = "block";
190   $(contextDIV).observe('mouseout',disintergrateContextMenus);
191 }
192 function disintergrateContextMenus(event) {
193   var contextMenu = document.getElementById("ctdlContextMenu");
194   if (contextMenu) {
195     contextMenu.parentNode.removeChild(contextMenu);
196   }
197   Event.stopObserving(document,'click',disintergrateContextMenus);
198 }
199 // This code handles the popups for important-messages.
200 function hide_imsg_popup() {
201     if (browserType === "gecko") {
202         document.poppedLayer = eval('document.getElementById(\'important_message\')');
203     }
204     else if (browserType === "ie") {
205         document.poppedLayer = eval('document.all[\'important_message\']');
206     }
207     else {
208         document.poppedLayer = eval('document.layers[\'`important_message\']');
209     }
210
211     document.poppedLayer.style.visibility = "hidden";
212 }
213 function remove_something(what_to_search, new_visibility) {
214     if (browserType === "gecko") {
215         document.poppedLayer = eval('document.getElementById(\'' + what_to_search + '\')');
216     }
217     else if (browserType === "ie") {
218         document.poppedLayer = eval('document.all[\'' + what_to_search + '\']');
219     }
220     else {
221         document.poppedLayer = eval('document.layers[\'`' + what_to_search + '\']');
222     }
223     if (document.poppedLayer !== null) {
224         document.poppedLayer.innerHTML = "";
225     }
226 }
227
228 function unhide_imsg_popup() {
229     if (browserType === "gecko") {
230         document.poppedLayer = eval('document.getElementById(\'important_message\')');
231     }
232     else if (browserType === "ie") {
233         document.poppedLayer = eval('document.all[\'important_message\']');
234     }
235     else {
236         document.poppedLayer = eval('document.layers[\'`important_message\']');
237     }
238
239     document.poppedLayer.style.visibility = "visible";
240     setTimeout('hide_imsg_popup()', 5000);
241 }
242
243 function ajax_important_message(messagetext)
244 {
245     if (browserType === "gecko") {
246         document.poppedLayer = eval('document.getElementById(\'important_message\')');
247     }
248     else if (browserType === "ie") {
249         document.poppedLayer = eval('document.all[\'important_message\']');
250     }
251     else {
252         document.poppedLayer = eval('document.layers[\'`important_message\']');
253     }
254     document.poppedLayer.style.visibility = "visible";
255     setTimeout('hide_imsg_popup()', 5000);
256     document.poppedLayer.innerHTML = messagetext;
257 }
258
259 // This function activates the ajax-powered recipient autocompleters on the message entry screen.
260 function activate_entmsg_autocompleters() {
261         new Ajax.Autocompleter('cc_id', 'cc_name_choices', 'cc_autocomplete', {} );
262         new Ajax.Autocompleter('bcc_id', 'bcc_name_choices', 'bcc_autocomplete', {} );
263         new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
264 }
265
266 function activate_iconbar_wholist_populat0r() 
267 {
268         new Ajax.PeriodicalUpdater('online_users', 'do_template?template=who_iconbar', {method: 'get', frequency: 30});
269 }
270
271 function setupIconBar() {
272
273         /* WARNING: VILE, SLEAZY HACK.  We determine the state of the box based on the image loaded. */
274         if ( $('expand_roomlist').src.substring($('expand_roomlist').src.length - 12) === "collapse.gif" ) {
275                 $('roomlist').style.display = 'block';
276                 $('roomlist').innerHTML = '';
277                 fillRooms(iconBarRoomList);
278         }
279         else {
280                 $('roomlist').style.display = 'none';
281         }
282
283         /* WARNING: VILE, SLEAZY HACK.  We determine the state of the box based on the image loaded. */
284         if ( $('expand_wholist').src.substring($('expand_wholist').src.length - 12) === "collapse.gif" ) {
285                 $('online_users').style.display = 'block';
286                 activate_iconbar_wholist_populat0r();
287         }
288         else {
289                 $('online_users').style.display = 'none';
290         }
291
292 }
293
294
295 // These functions handle moving sticky notes around the screen by dragging them
296
297 var uid_of_note_being_dragged = 0;
298 var saved_cursor_style = 'default';
299 var note_was_dragged = 0;
300
301 function NotesDragMouseUp(evt) {
302     document.onmouseup = null;
303     document.onmousemove = null;
304     if (document.layers) {
305         document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
306     }
307
308     var d = $('note-' + uid_of_note_being_dragged);
309     d.style.cursor = saved_cursor_style;
310
311     // If any motion actually occurred, submit an ajax http call to record it to the server
312     if (note_was_dragged > 0) {
313         var p = 'note_uid=' + uid_of_note_being_dragged
314             + '&left=' + d.style.left
315             + '&top=' + d.style.top
316             + '&r=' + ctdlRandomString();
317         new Ajax.Request(
318             'ajax_update_note',
319             {
320                 method: 'post',
321                 parameters: p
322             }
323         );
324     }
325
326     uid_of_note_being_dragged = '';
327     return true;
328 }
329 var saved_x, saved_y;
330 function NotesDragMouseMove(evt) {
331     var x = (ns6 ? evt.clientX : event.clientX);
332     var x_increment = x - saved_x;
333     var y = (ns6 ? evt.clientY : event.clientY);
334     var y_increment = y - saved_y;
335
336     // Move the div
337     var d = $('note-' + uid_of_note_being_dragged);
338
339     var divTop = parseInt(d.style.top);
340     var divLeft = parseInt(d.style.left);
341
342     d.style.top = (divTop + y_increment) + 'px';
343     d.style.left = (divLeft + x_increment) + 'px';
344
345     saved_x = x;
346     saved_y = y;
347     note_was_dragged = 1;
348     return true;
349 }
350
351
352 function NotesDragMouseDown(evt, uid) {
353     saved_x = (ns6 ? evt.clientX : event.clientX);
354     saved_y = (ns6 ? evt.clientY : event.clientY);
355     document.onmouseup = NotesDragMouseUp;
356     document.onmousemove = NotesDragMouseMove;
357     if (document.layers) {
358         document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
359     }
360     uid_of_note_being_dragged = uid;
361     var d = $('note-' + uid_of_note_being_dragged);
362     saved_cursor_style = d.style.cursor;
363     d.style.cursor = 'move';
364     return false;               // disable the default action
365 }
366
367
368 // Called when the user clicks on the palette icon of a sticky note to change its color.
369 // It toggles the color selector visible or invisible.
370
371 function NotesClickPalette(evt, uid) {
372     var uid_of_note_being_colored = uid;
373     var d = $('palette-' + uid_of_note_being_colored);
374
375     if (d.style.display) {
376         if (d.style.display === 'none') {
377             d.style.display = 'block';
378         }
379         else {
380             d.style.display = 'none';
381         }
382     }
383     else {
384         d.style.display = 'block';
385     }
386
387     return true;
388 }
389
390
391 // Called when the user clicks on one of the colors in an open color selector.
392 // Sets the desired color and then closes the color selector.
393
394 function NotesClickColor(evt, uid, red, green, blue, notecolor, titlecolor) {
395     var uid_of_note_being_colored = uid;
396     var palette_button = $('palette-' + uid_of_note_being_colored);
397     var note_div = $('note-' + uid_of_note_being_colored);
398     var titlebar_div = $('titlebar-' + uid_of_note_being_colored);
399
400     // alert('FIXME red=' + red + ' green=' + green + ' blue=' + blue);
401
402     note_div.style.backgroundColor = notecolor;
403     titlebar_div.style.backgroundColor = titlecolor;
404     palette_button.style.display = 'none';
405
406     // submit an ajax http call to record it to the server
407     var p = 'note_uid=' + uid_of_note_being_colored
408         + '&red=' + red
409         + '&green=' + green
410         + '&blue=' + blue
411         + '&r=' + ctdlRandomString();
412     new Ajax.Request(
413         'ajax_update_note',
414         {
415             method: 'post',
416             parameters: p
417         }
418     );
419 }
420
421
422
423
424 // These functions handle resizing sticky notes by dragging the resize handle
425
426 var uid_of_note_being_resized = 0;
427 var saved_cursor_style = 'default';
428 var note_was_resized = 0;
429
430 function NotesResizeMouseUp(evt) {
431     document.onmouseup = null;
432     document.onmousemove = null;
433     if (document.layers) {
434         document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
435     }
436
437     var d = $('note-' + uid_of_note_being_resized);
438     d.style.cursor = saved_cursor_style;
439
440     // If any motion actually occurred, submit an ajax http call to record it to the server
441     if (note_was_resized > 0) {
442         var p = 'note_uid=' + uid_of_note_being_resized
443             + '&width=' + d.style.width
444             + '&height=' + d.style.height
445             + '&r=' + ctdlRandomString();
446         new Ajax.Request(
447             'ajax_update_note',
448             {
449                 method: 'post',
450                 parameters: p
451             }
452         );
453     }
454
455     uid_of_note_being_resized = '';
456     return false;               // disable the default action
457 }
458
459 function NotesResizeMouseMove(evt) {
460     var x = (ns6 ? evt.clientX : event.clientX);
461     var x_increment = x - saved_x;
462     var y = (ns6 ? evt.clientY : event.clientY);
463     var y_increment = y - saved_y;
464
465     // Move the div
466     var d = $('note-' + uid_of_note_being_resized);
467
468     var divTop = parseInt(d.style.height);
469     var divLeft = parseInt(d.style.width);
470
471     var newHeight = divTop + y_increment;
472     if (newHeight < 50) {
473         newHeight = 50;
474     }
475
476     var newWidth = divLeft + x_increment;
477     if (newWidth < 50) {
478         newWidth = 50;
479     }
480     d.style.height = newHeight + 'px';
481     d.style.width = newWidth + 'px';
482
483     saved_x = x;
484     saved_y = y;
485     note_was_resized = 1;
486     return false;               // disable the default action
487 }
488
489
490 function NotesResizeMouseDown(evt, uid) {
491     var saved_x = (ns6 ? evt.clientX : event.clientX);
492     var saved_y = (ns6 ? evt.clientY : event.clientY);
493     document.onmouseup = NotesResizeMouseUp;
494     document.onmousemove = NotesResizeMouseMove;
495     if (document.layers) {
496         document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
497     }
498     uid_of_note_being_resized = uid;
499     var d = $('note-' + uid_of_note_being_resized);
500     saved_cursor_style = d.style.cursor;
501     d.style.cursor = 'move';
502     return false;               // disable the default action
503 }
504
505
506 function DeleteStickyNote(evt, uid, confirmation_prompt) {
507     var uid_of_note_being_deleted = uid;
508     var d = $('note-' + uid_of_note_being_deleted);
509
510     if (confirm(confirmation_prompt)) {
511         new Effect.Puff(d);
512
513         // submit an ajax http call to delete it on the server
514         var p = 'note_uid=' + uid_of_note_being_deleted
515             + '&deletenote=yes'
516             + '&r=' + ctdlRandomString();
517         new Ajax.Request(
518             'ajax_update_note',
519             {
520                 method: 'post',
521                 parameters: p
522             }
523         );
524     }
525 }
526
527 function ctdl_ts_getInnerText(el) {
528     if (typeof el === "string") {
529         return el;
530     }
531     if (typeof el === "undefined") {
532         return el;
533     }
534     if (el.innerText) {
535         return el.innerText;    //Not needed but it is faster
536     }
537     var str = "";
538     
539     var cs = el.childNodes;
540     var l = cs.length;
541     for (var i = 0; i < l; i++) {
542         switch (cs[i].nodeType) {
543         case 1: //ELEMENT_NODE
544             str += ts_getInnerText(cs[i]);
545             break;
546         case 3: //TEXT_NODE
547             str += cs[i].nodeValue;
548             break;
549         }
550     }
551     return str;
552 }
553
554
555 // Place a gradient loadscreen on an element, e.g to use before Ajax.updater
556 function CtdlLoadScreen(elementid) {
557 var elem = document.getElementById(elementid);
558     elem.innerHTML = "<div align=center><br>" + 
559         "<table border=0 cellpadding=10 bgcolor=\"#ffffff\">" + 
560         " <tr><td><img src=\"static/throbber.gif\" />" + 
561         " <font color=\"#AAAAAA\">&nbsp;&nbsp;Loading....</font>" + 
562         "</td></tr></table><br></div>";
563 }
564
565
566
567 // Pop open the address book (target_input is the INPUT field to populate)
568
569 function PopOpenAddressBook(target_input) {
570         $('address_book_popup').style.display = 'block';
571         p = 'target_input=' + target_input + '&r=' + ctdlRandomString();
572         new Ajax.Updater(
573                 'address_book_popup_middle_div',
574                 'do_template?template=addressbook_list',
575                 {
576                         method: 'get',
577                         parameters: p,
578                         evalScripts: true
579                 }
580         );
581 }
582
583 function PopulateAddressBookInnerDiv(which_addr_book, target_input) {
584
585     $('address_book_inner_div').innerHTML =
586         "<div align=center><br>" + 
587         "<table border=0 cellpadding=10 bgcolor=\"#ffffff\">" + 
588         "<tr><td><img src=\"static/throbber.gif\" />" + 
589         "<font color=\"#AAAAAA\">" +
590         "&nbsp;&nbsp;Loading...." + 
591         "</font></td></tr></table><br></div>";
592
593     p = 'which_addr_book=' + which_addr_book
594         + '&target_input=' + target_input
595         + '&r=' + ctdlRandomString()
596         + "&template=addressbook_namelist";
597     new Ajax.Updater(
598         'address_book_inner_div',
599         'do_template',
600         {
601             method: 'get',
602             parameters: p
603         }
604     );
605 }
606
607 // What happens when a contact is selected from the address book popup
608 // (populate the specified target)
609
610 function AddContactsToTarget(target, whichaddr) {
611         while (whichaddr.selectedIndex !== -1) {
612                 if (target.value.length > 0) {
613                         target.value = target.value + ', ';
614                 }
615                 target.value = target.value + whichaddr.value;
616                 whichaddr.options[whichaddr.selectedIndex].selected = false;
617         }
618 }
619
620 // Respond to a meeting invitation
621 function RespondToInvitation(question_divname, title_divname, msgnum, cal_partnum, sc) {
622         p = 'msgnum=' + msgnum + '&cal_partnum=' + cal_partnum + '&sc=' + sc ;
623         new Ajax.Updater(title_divname, 'respond_to_request', { method: 'post', parameters: p } );
624         Effect.Fade(question_divname, { duration: 0.5 });
625 }
626
627 // Handle a received RSVP
628 function HandleRSVP(question_divname, title_divname, msgnum, cal_partnum, sc) {
629         p = 'msgnum=' + msgnum + '&cal_partnum=' + cal_partnum + '&sc=' + sc ;
630         new Ajax.Updater(title_divname, 'handle_rsvp', { method: 'post', parameters: p } );
631         Effect.Fade(question_divname, { duration: 0.5 });
632 }
633 /* var fakeMouse = document.createEvent("MouseEvents");
634  fakeMouse.initMouseEvent("click", true, true, window, 
635    0,0,0,0,0, false, false, false, false, 0, null); */
636 // TODO: Collapse into one function
637 function toggleTaskDtStart(event) {
638     var checkBox = $('nodtstart');
639     var checkBoxTime = $('dtstart_time_assoc');
640     var dtstart = document.getElementById("dtstart");
641     var dtstart_date = document.getElementById("dtstart_date");
642     var dtstart_time = document.getElementById("dtstart_time");
643     if (checkBox.checked) {
644         dtstart_date.style.visibility = "hidden";
645         dtstart_time.style.visibility = "hidden";
646     } else {
647         if (checkBoxTime.checked) {
648             dtstart_time.style.visibility = "visible";
649         } else {
650             dtstart_time.style.visibility = "hidden";
651         }
652         dtstart_date.style.visibility = "visible";
653         if (dtstart.value.length === 0) {
654             dtstart.dpck._initCurrentDate();
655         }
656     }
657 }
658 function toggleTaskDue(event) {
659     var checkBox = $('nodue');
660     var checkBoxTime = $('due_time_assoc');
661     var due = document.getElementById("due");
662     var due_date = document.getElementById("due_date");
663     var due_time = document.getElementById("due_time");
664     if (checkBox.checked) {
665         due_date.style.visibility = "hidden";
666         due_time.style.visibility = "hidden";
667     } else {
668         if (checkBoxTime.checked) {
669             due_time.style.visibility = "visible";
670         } else {
671             due_time.style.visibility = "hidden";
672         }
673         due_date.style.visibility = "visible";
674         if (due.value.length === 0) {
675             due.dpck._initCurrentDate();
676         }
677     }
678 }
679 function ToggleTaskDateOrNoDateActivate(event) {
680         var dtstart = document.getElementById("nodtstart");
681         if (dtstart !== null) {
682                 toggleTaskDtStart(null);
683                 toggleTaskDue(null);
684                 $('nodtstart').observe('click', toggleTaskDtStart);
685                 $('dtstart_time_assoc').observe('click', toggleTaskDtStart);
686                 $('nodue').observe('click', toggleTaskDue);
687                 $('due_time_assoc').observe('click', toggleTaskDue);
688         } 
689 }
690 function TaskViewGatherCategoriesFromTable() {
691         var table = $('taskview');
692         
693 }
694 function attachDatePicker(relative) {
695         var dpck = new DatePicker({
696         relative: relative,
697               language: 'en', //wclang.substr(0,2),
698               disableFutureDate: false,
699               dateFormat: [ ["yyyy", "mm", "dd"], "-"],
700               showDuration: 0.2
701         });
702         document.getElementById(relative).dpck = dpck; // attach a ref to it
703 }
704 function eventEditAllDay() {
705         var allDayCheck = document.getElementById("alldayevent");
706         var dtend_time = document.getElementById("dtend_time");
707         var dtstart_time = document.getElementById("dtstart_time");
708         if(allDayCheck.checked) {
709                 dtstart_time.style.visibility = "hidden";
710                 dtend_time.style.visibility = "hidden";
711         } else {
712                 dtstart_time.style.visibility = "visible";
713                 dtend_time.style.visibility = "visible";
714         }
715 }
716
717 // Functions which handle show/hide of various elements in the recurrence editor
718
719 function RecurrenceShowHide() {
720
721         if ($('is_recur').checked) {
722                 $('rrule_div').style.display = 'block';
723         }
724         else {
725                 $('rrule_div').style.display = 'none';
726         }
727
728         if ($('freq_selector').selectedIndex === 4) {
729                 $('weekday_selector').style.display = 'block';
730         }
731         else {
732                 $('weekday_selector').style.display = 'none';
733         }
734
735         if ($('freq_selector').selectedIndex === 5) {
736                 $('monthday_selector').style.display = 'block';
737         }
738         else {
739                 $('monthday_selector').style.display = 'none';
740         }
741
742         if ($('rrend_count').checked) {
743                 $('rrcount').disabled = false;
744         }
745         else {
746                 $('rrcount').disabled = true;
747         }
748
749         if ($('rrend_until').checked) {
750                 $('rruntil').disabled = false;
751         }
752         else {
753                 $('rruntil').disabled = true;
754         }
755
756         if ($('rrmonthtype_mday').checked) {
757                 $('rrmday').disabled = false;
758         }
759         else {
760                 $('rrmday').disabled = true;
761         }
762
763         if ($('rrmonthtype_wday').checked) {
764                 $('rrmweek').disabled = false;
765                 $('rrmweekday').disabled = false;
766         }
767         else {
768                 $('rrmweek').disabled = true;
769                 $('rrmweekday').disabled = true;
770         }
771
772         if ($('freq_selector').selectedIndex === 6) {
773                 $('yearday_selector').style.display = 'block';
774         }
775         else {
776                 $('yearday_selector').style.display = 'none';
777         }
778
779         $('ymday').innerHTML = 'XXXX-' + $('dtstart').value.substr(5);
780         $('rrmday').innerHTML = $('dtstart').value.substr(8);
781
782         if ($('rryeartype_ywday').checked) {
783                 $('rrymweek').disabled = false;
784                 $('rrymweekday').disabled = false;
785                 $('rrymonth').disabled = false;
786         }
787         else {
788                 $('rrymweek').disabled = true;
789                 $('rrymweekday').disabled = true;
790                 $('rrymonth').disabled = true;
791         }
792
793 }
794
795
796 // Enable or disable the 'check attendee availability' button depending on whether
797 // the attendees list is empty
798 function EnableOrDisableCheckButton()
799 {
800         if ($('attendees_box').value.length === 0) {
801                 $('check_button').disabled = true;
802         }
803         else {
804                 $('check_button').disabled = false;
805         }
806 }
807
808
809
810
811 function launchChat(event) {
812     window.open('chat',
813                 'ctdl_chat_window',
814                 'toolbar=no,location=no,directories=no,copyhistory=no,status=no,scrollbars=yes,resizable=yes');
815 }
816 // logger
817 function wCLog(msg) {
818   if (!!window.console && !!console.log) {
819     console.log(msg);
820   } else if (!!window.opera && !!opera.postError) {
821     opera.postError(msg);
822   } else {
823     wc_log += msg + "\r\n";
824   }
825 }
826
827 function RefreshSMTPqueueDisplay() {
828         new Ajax.Updater('mailqueue_list',
829         'dotskip?room=__CitadelSMTPspoolout__&view=11&ListOnly=yes', { method: 'get',
830                 parameters: Math.random() } );
831 }
832
833 function DeleteSMTPqueueMsg(msgnum1, msgnum2) {
834     var p = encodeURI('g_cmd=DELE ' + msgnum1 + ',' + msgnum2);
835     new Ajax.Request(
836         'ajax_servcmd', {
837             method: 'post',
838             parameters: p,
839             onComplete: function(transport) {
840                 ajax_important_message(transport.responseText.substr(4));
841                 RefreshSMTPqueueDisplay();}
842         }
843     );
844 }
845
846
847 function ConfirmLogoff() {
848     new Ajax.Updater(
849         'md-content',
850         'do_template?template=confirmlogoff',
851         {
852             method: 'get',
853             evalScripts: true,
854             onSuccess: function(cl_success) {
855                 toggleModal(1);
856             }
857         }
858     );
859 }
860
861
862 function switch_to_lang(new_lang) {
863         p = 'push?url=' + encodeURI(window.location);
864         new Ajax.Request(p, { method: 'get' } );
865         window.location = 'switch_language?lang=' + new_lang ;
866 }
867
868
869 function toggle_roomlist() 
870 {
871         /* WARNING: VILE, SLEAZY HACK.  We determine the state of the box based on the image loaded. */
872         if ( $('expand_roomlist').src.substring($('expand_roomlist').src.length - 12) === "collapse.gif" ) {
873                 $('roomlist').style.display = 'none';
874                 $('expand_roomlist').src = 'static/webcit_icons/expand.gif';
875                 wstate=0;
876         }
877
878         else {
879                 $('roomlist').style.display = 'block';
880                 $('expand_roomlist').src = 'static/webcit_icons/collapse.gif';
881                 $('roomlist').innerHTML = '';
882                 fillRooms(iconBarRoomList);
883                 wstate=1;
884         }
885
886         // tell the server what I did
887         p = 'toggle_roomlist_expanded_state?wstate=' + wstate + '?rand=' + Math.random() ;
888         new Ajax.Request(p, { method: 'get' } );
889
890         return false;   /* this prevents the click from registering as a roomlist button press */
891 }
892
893
894 function toggle_wholist() 
895 {
896         /* WARNING: VILE, SLEAZY HACK.  We determine the state of the box based on the image loaded. */
897         if ( $('expand_wholist').src.substring($('expand_wholist').src.length - 12) === "collapse.gif" ) {
898                 $('online_users').style.display = 'none';
899                 $('expand_wholist').src = 'static/webcit_icons/expand.gif';
900                 wstate=0;
901         }
902
903         else {
904                 $('online_users').style.display = 'block';
905                 $('expand_wholist').src = 'static/webcit_icons/collapse.gif';
906                 activate_iconbar_wholist_populat0r();
907                 wstate=1;
908         }
909
910         // tell the server what I did
911         p = 'toggle_wholist_expanded_state?wstate=' + wstate + '?rand=' + Math.random() ;
912         new Ajax.Request(p, { method: 'get' } );
913
914         return false;   /* this prevents the click from registering as a wholist button press */
915 }
916
917 function getBlogStartText(wikitype) {
918     var wikitext = document.getElementById("wikitext").innerHTML;
919     var wikipublish = document.getElementById("wikipublish").innerHTML;
920     var wikilinktext = document.getElementById("wikilinktext").innerHTML;
921     var wikilinkmore = document.getElementById("wikilinkmore").innerHTML;
922     var wikilinkembedmedia = document.getElementById("wikilinkembedmedia").innerHTML;
923     if (wikitype) {
924         return "<html><head></head><body>\n" +
925             "<h1>" + wikitext + "</h1>\n" + 
926             "<p>" + wikipublish + "</p>\n" +
927             "<a href='wiki?page=firstarticle'>" + wikilinktext + "</a>" +
928             "<p>" + wikilinkmore + "</p>\n" + 
929             "<p>" + wikilinkembedmedia + " </p>\n<p><img src='/download_file/test.jpg' alt=\"alttext\"></p>\n" + 
930             "</body></html>";
931     }
932     else {
933         return "#" + wikitext + "\n" + 
934             wikipublish + "\n\n" + 
935             "[" + wikilinktext + "](wiki?page=firstarticle)\n\n" +
936             wikilinkmore + "\n\n" + 
937             wikilinkembedmedia + "\n\n ![alttext](/download_file/test.jpg)";
938     }
939 }
940
941 function create_blog()
942 {
943     var er_view_blog = document.getElementById('er_view_blog');
944     var Nonce = document.getElementById('Nonce');
945     var roomname = document.getElementById('er_name').value;
946     var editroomname = roomname + '\\edit';
947     var filePath = "files_" + roomname;
948     var floorID = document.getElementById('er_floor').value;
949
950     var selects = document.getElementById("er_floor");
951     var selectedFloor = selects.options[selects.selectedIndex].value;
952     var selectedFloorName = selects.options[selects.selectedIndex].text;
953
954     var vselects = document.getElementById("er_view");
955     var vselectedMarkup = vselects.options[vselects.selectedIndex].value;
956     var vselectedMarkupName = vselects.options[vselects.selectedIndex].text;
957
958     var adminPW = document.getElementById('adminlist_passworded').checked;
959
960     var passvoid = document.getElementById('er_password').value;
961     var roomtypeWiki = document.getElementById('er_blog_markup_html').value;
962
963     var isHtmlWiki = vselectedMarkup === roomtypeWiki;
964     var starttext = getBlogStartText(isHtmlWiki);
965
966     ToggleVisibility('er_password');
967     var type_edit;
968     if (adminPW) {
969         type_edit = document.getElementById('adminlist_passworded').value;
970         ToggleVisibility('li_adminlist_invonly');
971         ToggleVisibility('adminlist_passworded');
972         
973     }
974     else {
975         type_edit = document.getElementById('adminlist_invonly').value;
976         ToggleVisibility('adminlist_invonly');
977         ToggleVisibility('li_adminlist_passworded');
978     }
979
980     ToggleVisibility('er_floor');
981     document.getElementById('er_floor_fixed').innerHTML = selectedFloorName;
982     ToggleVisibility('er_floor_fixed');
983
984     ToggleVisibility('er_name');
985     document.getElementById('er_name_fixed').innerHTML = roomname;
986     ToggleVisibility('er_name_fixed');
987
988     ToggleVisibility('er_view');
989     document.getElementById('er_view_fixed').innerHTML = vselectedMarkupName;
990     ToggleVisibility('er_view_fixed');
991
992     ToggleVisibility('create_buttons');
993
994     ToggleVisibility('edit_info');
995     ToggleVisibility('throbber');
996     
997
998     var roomdata = {
999         create_blog_room: {
1000             nonce:       Nonce,
1001             er_name:     roomname,
1002             type:        'public',
1003             er_view:     er_view_blog,
1004             er_floor:    floorID,
1005             template:    "room_result_json",
1006             ok_button:   1
1007         },
1008         setflags_blog_room: {
1009             nonce:       Nonce,
1010             er_name:     roomname,
1011             go:          roomname,
1012             type:        'public',
1013             er_floor:    floorID,
1014
1015             directory:   "yes",
1016             er_dirname:  filePath,
1017             ulallowed:   "no",
1018             dlallowed:   "yes",
1019             ulmsg:       "no",
1020             visdir:      "no",
1021
1022             anon:        "no",
1023             last_tabsel: 1,
1024             er_view:     er_view_blog,
1025             template:    "room_result_json",
1026             ok_button:   1
1027         },
1028         create_blog_edit_room: {
1029             nonce:       Nonce,
1030             er_name:     editroomname,
1031             type:        type_edit,
1032             er_view:     vselectedMarkup,
1033             er_floor:    floorID,
1034             er_password: passvoid,
1035             template:    "room_result_json",
1036             ok_button:   1
1037         },
1038         setflags_blog_edit_room: {
1039             nonce:       Nonce,
1040             er_name:     editroomname,
1041             go:          editroomname,
1042             type:        type_edit,
1043             er_floor:    floorID,
1044
1045             directory:   "yes",
1046             er_dirname:  filePath,
1047             ulallowed:   "yes",
1048             dlallowed:   "yes",
1049             ulmsg:       "no",
1050             visdir:      "yes",
1051
1052             anon:        "no",
1053             last_tabsel: 1,
1054             er_view:     er_view_blog,
1055             template:    "room_result_json",
1056             ok_button:   1
1057         },
1058         blog_wiki_startmessage : {
1059             nonce:       Nonce,
1060             force_room:  editroomname,
1061             page:        "home",
1062             markdown:    (isHtmlWiki)?0:1,
1063             msgtext:     starttext
1064
1065         }
1066     };
1067
1068     /* promises anyone?
1069      *  - create the blog room
1070      *  - set the blog rooms file flags
1071      *  - create the edit room
1072      *  - set the blog edit room flags
1073      */
1074     new Ajax.Request("/entroom",
1075                      { method: 'post',
1076                        parameters: $H(roomdata.create_blog_room).toQueryString(),
1077                        onComplete: function(transport) {
1078                            new Ajax.Request("/editroom",
1079                                             { method: 'post',
1080                                               parameters: $H(roomdata.setflags_blog_room).toQueryString(),
1081                                               onComplete: function(transport) {
1082                                                   new Ajax.Request("/entroom",
1083                                                                    { method: 'post',
1084                                                                      parameters: $H(roomdata.create_blog_edit_room).toQueryString(),
1085                                                                      onComplete: function(transport) {
1086                                                                          new Ajax.Request("/editroom",
1087                                                                                           { method: 'post',
1088                                                                                             parameters: $H(roomdata.setflags_blog_edit_room).toQueryString(),
1089                                                                                             onComplete: function(transport) {
1090                                                                                                 ToggleVisibility('throbber');
1091                                                                                                 new Ajax.Request("/post",
1092                                                                                                                  { method: 'post',
1093                                                                                                                    parameters: $H(roomdata.blog_wiki_startmessage).toQueryString(),
1094                                                                                                                    onComplete: function(transport) {
1095
1096                                                                                                                    }
1097                                                                                                                  }
1098                                                                                                                 );
1099                                                                                             }
1100                                                                                           }
1101                                                                                          );
1102                                                                      }
1103                                                                    }
1104                                                                   );
1105                                               }
1106                                             }
1107                                            )
1108                        }
1109                      }
1110                     );
1111
1112     return false;
1113 }
1114
1115
1116 function deleteAllSelectedMessages() {
1117
1118 }
1119
1120
1121 function publishMessage()
1122 {
1123     var messages = document.getElementsByClassName("message");
1124     var messageIdParts = messages[0].id.split('|');
1125     var editRoomName = getTextContent(document.getElementById("rmname"));
1126     var roomName = editRoomName.substring(0, editRoomName.length - 5);
1127
1128     var publish = {
1129         editRoom: editRoomName,
1130         blogRoom: roomName,
1131         msgNo : messageIdParts[1],
1132         msgIdStr : messageIdParts[2]
1133     }
1134
1135     mvCommand = encodeURI("g_cmd=MOVE " + publish.msgNo + "|" + publish.blogRoom + "|1");
1136     
1137     new Ajax.Request("ajax_servcmd", {
1138         parameters: mvCommand,
1139         method: 'post',
1140         onSuccess: function(transport) {
1141             wCLog(transport.responseText);
1142         }
1143     });
1144 }