-//
-// $Id: wclib.js,v 625.2 2005/09/18 04:04:32 ajc Exp $
-//
-// JavaScript function library for WebCit.
-//
-//
-
+/*
+ * JavaScript function library for WebCit.
+ *
+ * Copyright (c) 2005-2011 by the citadel.org team
+ *
+ * This program is open source software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
var browserType;
var room_is_trash = 0;
-if (document.layers) {browserType = "nn4"}
+var currentlyExpandedFloor = null;
+var roomlist = null;
+var currentDropTarget = null;
+
+var supportsAddEventListener = (!!document.addEventListener);
+var today = new Date();
+
+var wc_log = "";
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
- browserType= "gecko"
+ browserType= "gecko";
}
-
var ns6=document.getElementById&&!document.all;
+Event.observe(window, 'load', ToggleTaskDateOrNoDateActivate);
+Event.observe(window, 'load', taskViewActivate);
+//document.observe("dom:loaded", setupPrefEngine);
+document.observe("dom:loaded", setupIconBar);
+function CtdlRandomString() {
+ return((Math.random()+'').substr(3));
+}
+function strcmp ( str1, str2 ) {
+ // http://kevin.vanzonneveld.net
+ // + original by: Waldo Malqui Silva
+ // + input by: Steve Hilder
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + revised by: gorthaur
+ // * example 1: strcmp( 'waldo', 'owald' );
+ // * returns 1: 1
+ // * example 2: strcmp( 'owald', 'waldo' );
+ // * returns 2: -1
+
+ return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
+}
+
+function ToggleVisibility ($Which)
+{
+ if (document.getElementById)
+ {
+ if (document.getElementById($Which).style.display == "none")
+ document.getElementById($Which).style.display = "inline";
+ else
+ document.getElementById($Which).style.display = "none";
+ }
+}
+
+function emptyElement(element) {
+ childNodes = element.childNodes;
+ for(var i=0; i<childNodes.length; i++) {
+ try {
+ element.removeChild(childNodes[i]);
+ } catch (e) {
+ WCLog(e+"|"+e.description);
+ }
+ }
+}
+/** Implements superior internet explorer 'extract all child text from element' feature'. Falls back on buggy, patent violating standardized method */
+function getTextContent(element) {
+ if (element.textContent == undefined) {
+ return element.innerText;
+ }
+ return element.textContent;
+}
+/** Same reasons as above */
+function setTextContent(element, textContent) {
+ if(element.textContent == undefined) {
+ element.innerText = textContent;
+ } else {
+ element.textContent = textContent;
+ }
+}
// We love string tokenizers.
function extract_token(source_string, token_num, delimiter) {
for (i=0; i<token_num; ++i) {
var j = extracted_string.indexOf(delimiter);
if (j >= 0) {
- extracted_string = extracted_string.substring(j+1);
+ extracted_string = extracted_string.substr(j+1);
}
}
}
j = extracted_string.indexOf(delimiter);
if (j >= 0) {
- extracted_string = extracted_string.substring(0, j);
+ extracted_string = extracted_string.substr(0, j);
}
return extracted_string;
}
-
-
+function CtdlSpawnContextMenu(event, source) {
+ // remove any existing menus
+ disintergrateContextMenus(null);
+ var x = event.clientX-10; // cut a few pixels out so our mouseout works right
+ var y = event.clientY-10;
+ var contextDIV = document.createElement("div");
+ contextDIV.setAttribute("id", "ctdlContextMenu");
+ document.body.appendChild(contextDIV);
+ var sourceChildren = source.childNodes;
+ for(var j=0; j<sourceChildren.length; j++) {
+ contextDIV.appendChild(sourceChildren[j].cloneNode(true));
+ }
+ var leftRule = "left: "+x+"px;";
+ contextDIV.setAttribute("style", leftRule);
+ contextDIV.setAttribute("actual", leftRule);
+ contextDIV.style.top = y+"px";
+ contextDIV.style.display = "block";
+ $(contextDIV).observe('mouseout',disintergrateContextMenus);
+}
+function disintergrateContextMenus(event) {
+ var contextMenu = document.getElementById("ctdlContextMenu");
+ if (contextMenu) {
+ contextMenu.parentNode.removeChild(contextMenu);
+ }
+ Event.stopObserving(document,'click',disintergrateContextMenus);
+}
// This code handles the popups for important-messages.
function hide_imsg_popup() {
- if (browserType == "gecko" )
+ if (browserType == "gecko") {
document.poppedLayer = eval('document.getElementById(\'important_message\')');
- else if (browserType == "ie")
+ }
+ else if (browserType == "ie") {
document.poppedLayer = eval('document.all[\'important_message\']');
- else
+ }
+ else {
document.poppedLayer = eval('document.layers[\'`important_message\']');
+ }
document.poppedLayer.style.visibility = "hidden";
}
new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
}
+function activate_iconbar_wholist_populat0r()
+{
+ new Ajax.PeriodicalUpdater('online_users', 'do_template?template=who_iconbar', {method: 'get', frequency: 30});
+}
+
+function setupIconBar() {
+ /* WARNING: VILE, SLEAZY HACK. We determine the state of the box based on the image loaded. */
+ if ( $('expand_roomlist').src.substring($('expand_roomlist').src.length - 12) == "collapse.gif" ) {
+ $('roomlist').style.display = 'block';
+ $('roomlist').innerHTML = '';
+ FillRooms(IconBarRoomList);
+ }
+ else {
+ $('roomlist').style.display = 'none';
+ }
-// Toggle the icon bar between menu/roomlist...
-var which_div_expanded = null;
-var num_drop_targets = 0;
-var drop_targets_elements = new Array();
-var drop_targets_roomnames = new Array();
+ /* WARNING: VILE, SLEAZY HACK. We determine the state of the box based on the image loaded. */
+ if ( $('expand_wholist').src.substring($('expand_wholist').src.length - 12) == "collapse.gif" ) {
+ $('online_users').style.display = 'block';
+ activate_iconbar_wholist_populat0r();
+ }
+ else {
+ $('online_users').style.display = 'none';
+ }
-function switch_to_room_list() {
- $('iconbar').innerHTML = $('iconbar').innerHTML.substr(0, $('iconbar').innerHTML.indexOf('switch'));
- new Ajax.Updater('iconbar', 'iconbar_ajax_rooms', { method: 'get' } );
}
-function expand_floor(floor_div) {
- if (which_div_expanded != null) {
- if ($(which_div_expanded) != null) {
- $(which_div_expanded).style.display = 'none' ;
- }
+function GenericTreeRoomList(roomlist) {
+ var currentExpanded = ctdlLocalPrefs.readPref("rooms_expanded");
+ var curRoomName = "";
+ if (document.getElementById("rmname")) {
+ curRoomName = getTextContent(document.getElementById("rmname"));
+ }
+ currentDropTargets = new Array();
+ var iconbar = document.getElementById("iconbar");
+ var ul = document.createElement("ul");
+ roomlist.appendChild(ul);
+ // Add mailbox, because they are special
+ var mailboxLI = document.createElement("li");
+ ul.appendChild(mailboxLI);
+ var mailboxSPAN = document.createElement("span");
+ var _mailbox = getTextContent(document.getElementById("mbox_template"));
+ mailboxSPAN.appendChild(document.createTextNode(_mailbox));
+ $(mailboxSPAN).observe('click', expandFloorEvent);
+ mailboxLI.appendChild(mailboxSPAN);
+ mailboxLI.className = "floor";
+ var mailboxUL = document.createElement("ul");
+ mailboxLI.appendChild(mailboxUL);
+ var mailboxRooms = GetMailboxRooms();
+ for(var i=0; i<mailboxRooms.length; i++) {
+ var room = mailboxRooms[i];
+ currentDropTargets.push(addRoomToList(mailboxUL, room, curRoomName));
+ }
+ if (currentExpanded != null && currentExpanded == _mailbox ) {
+ expandFloor(mailboxSPAN);
+ }
+ for(var a=0; a<floors.length; a++) {
+ var floor = floors[a];
+ var floornum = floor[0];
+
+ if (floornum != -1)
+ {
+
+ var name = floor[1];
+ var floorLI = document.createElement("li");
+ ul.appendChild(floorLI);
+ var floorSPAN = document.createElement("span");
+ floorSPAN.appendChild(document.createTextNode(name));
+ $(floorSPAN).observe('click', expandFloorEvent);
+ floorLI.appendChild(floorSPAN);
+ floorLI.className = "floor";
+ var floorUL = document.createElement("ul");
+ floorLI.appendChild(floorUL);
+ var roomsForFloor = GetRoomsByFloorNum(floornum);
+ for(var b=0; b<roomsForFloor.length; b++) {
+ var room = roomsForFloor[b];
+ currentDropTargets.push(addRoomToList(floorUL, room, curRoomName));
+ }
+ if (currentExpanded != null && currentExpanded == name) {
+ expandFloor(floorSPAN);
+ }
+ }
+ }
+}
+function IconBarRoomList() {
+ roomlist = document.getElementById("roomlist");
+ GenericTreeRoomList(roomlist);
+}
+function KNRoomsRoomList() {
+ roomlist = document.getElementById("roomlist_knrooms");
+ GenericTreeRoomList(roomlist);
+}
+
+function addRoomToList(floorUL,room, roomToEmphasize) {
+ var roomName = room[RN_ROOM_NAME];
+ var flag = room[RN_ROOM_FLAG];
+ var curView = room[RN_CUR_VIEW];
+ var view = room[RN_DEF_VIEW];
+ var raflags = room[RN_RAFLAGS];
+ var isMailBox = ((flag & QR_MAILBOX) == QR_MAILBOX);
+ var hasNewMsgs = ((raflags & UA_HASNEWMSGS) == UA_HASNEWMSGS);
+ var roomLI = document.createElement("li");
+ var roomA = document.createElement("a");
+ roomA.setAttribute("href","dotgoto?room="+encodeURIComponent(roomName));
+ roomA.appendChild(document.createTextNode(roomName));
+ roomLI.appendChild(roomA);
+ floorUL.appendChild(roomLI);
+ var className = "room ";
+ if (view == VIEW_MAILBOX) {
+ className += "room-private"
+ } else if (view == VIEW_ADDRESSBOOK) {
+ className += "room-addr";
+ } else if (view == VIEW_CALENDAR || view == VIEW_CALBRIEF) {
+ className += "room-cal";
+ } else if (view == VIEW_TASKS) {
+ className += "room-tasks";
+ } else if (view == VIEW_NOTES) {
+ className += "room-notes";
+ } else {
+ className += "room-chat";
+ }
+ if (hasNewMsgs) {
+ className += " room-newmsgs";
+ }
+ if (roomName == roomToEmphasize) {
+ className += " room-emphasized";
+ }
+ roomLI.setAttribute("class", className);
+ roomA.dropTarget = true;
+ roomA.dropHandler = roomListDropHandler;
+ return roomLI;
+}
+
+function roomListDropHandler(target, dropped) {
+ if (dropped.getAttribute("citadel:msgid")) {
+ var room = getTextContent(target);
+ var msgIds = "";
+ for(msgId in currentlyMarkedRows) { //defined in summaryview.js
+ msgIds += ","+msgId;
+ if (msgIds.length > 800) {
+ var mvCommand = encodeURI("g_cmd=MOVE " + msgIds + "|"+room+"|0");
+ new Ajax.Request("ajax_servcmd", {
+ parameters: mvCommand,
+ method: 'post',
+ });
+ msgIds = "";
+ }
+
+ }
+ var mvCommand = encodeURI("g_cmd=MOVE " + msgIds + "|"+room+"|0");
+ new Ajax.Request('ajax_servcmd', {
+ method: 'post',
+ parameters: mvCommand,
+ onComplete: deleteAllMarkedRows()});
+ }
+}
+function expandFloorEvent(event) {
+ expandFloor(event.target);
+}
+function expandFloor(target) {
+ if (target.nodeName.toLowerCase() != "span") {
+ return; // ignore clicks on child UL
+ }
+ ctdlLocalPrefs.setPref("rooms_expanded", target.firstChild.nodeValue);
+ var parentUL = target.parentNode;
+ if (currentlyExpandedFloor != null) {
+ currentlyExpandedFloor.className = currentlyExpandedFloor.className.replace("floor-expanded","");
+ }
+ parentUL.className = parentUL.className + " floor-expanded";
+ currentlyExpandedFloor = parentUL;
+}
+
+// These functions handle moving sticky notes around the screen by dragging them
+
+var uid_of_note_being_dragged = 0;
+var saved_cursor_style = 'default';
+var note_was_dragged = 0;
+
+function NotesDragMouseUp(evt) {
+ document.onmouseup = null;
+ document.onmousemove = null;
+ if (document.layers) {
+ document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
}
- // clicking on the already-expanded floor causes the whole list to collapse
- if (which_div_expanded == floor_div) {
- which_div_expanded = null;
+ d = $('note-' + uid_of_note_being_dragged);
+ d.style.cursor = saved_cursor_style;
- // notify the server that no floors are expanded
+ // If any motion actually occurred, submit an ajax http call to record it to the server
+ if (note_was_dragged > 0) {
+ p = 'note_uid=' + uid_of_note_being_dragged
+ + '&left=' + d.style.left
+ + '&top=' + d.style.top
+ + '&r=' + CtdlRandomString();
new Ajax.Request(
- 'set_floordiv_expanded/-1', {
- method: 'post'
+ 'ajax_update_note',
+ {
+ method: 'post',
+ parameters: p
}
);
- return true;
}
- // expand the requested floor
- $(floor_div).style.display = 'block';
- which_div_expanded = floor_div;
-
- // notify the server of which floor is expanded
- new Ajax.Request(
- 'set_floordiv_expanded/'+floor_div, {
- method: 'post'
- }
- );
+ uid_of_note_being_dragged = '';
+ return true;
}
-function switch_to_menu_buttons() {
- which_div_expanded = null;
- num_drop_targets = 0;
- new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );
-}
+function NotesDragMouseMove(evt) {
+ x = (ns6 ? evt.clientX : event.clientX);
+ x_increment = x - saved_x;
+ y = (ns6 ? evt.clientY : event.clientY);
+ y_increment = y - saved_y;
+ // Move the div
+ d = $('note-' + uid_of_note_being_dragged);
-// Static variables for mailbox view...
-//
-var CtdlNumMsgsSelected = 0;
-var CtdlMsgsSelected = new Array();
+ divTop = parseInt(d.style.top);
+ divLeft = parseInt(d.style.left);
-// This gets called when you single click on a message in the mailbox view.
-// We know that the element id of the table row will be the letter 'm' plus the message number.
-//
-function CtdlSingleClickMsg(evt, msgnum) {
+ d.style.top = (divTop + y_increment) + 'px';
+ d.style.left = (divLeft + x_increment) + 'px';
- // Clear the preview pane until we load the new message
- $('preview_pane').innerHTML = '';
+ saved_x = x;
+ saved_y = y;
+ note_was_dragged = 1;
+ return true;
+}
- // De-select any messages that were already selected, *unless* the Ctrl key
- // is being pressed, in which case the user wants multi select.
- if (!evt.ctrlKey) {
- if (CtdlNumMsgsSelected > 0) {
- for (i=0; i<CtdlNumMsgsSelected; ++i) {
- $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
- $('m'+CtdlMsgsSelected[i]).style.color = '#000';
- }
- CtdlNumMsgsSelected = 0;
- }
- }
- // For multi select ... is the message being clicked already selected?
- already_selected = 0;
- if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
- for (i=0; i<CtdlNumMsgsSelected; ++i) {
- if (CtdlMsgsSelected[i] == msgnum) {
- already_selected = 1;
- }
- }
+function NotesDragMouseDown(evt, uid) {
+ saved_x = (ns6 ? evt.clientX : event.clientX);
+ saved_y = (ns6 ? evt.clientY : event.clientY);
+ document.onmouseup = NotesDragMouseUp;
+ document.onmousemove = NotesDragMouseMove;
+ if (document.layers) {
+ document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
}
+ uid_of_note_being_dragged = uid;
+ d = $('note-' + uid_of_note_being_dragged);
+ saved_cursor_style = d.style.cursor;
+ d.style.cursor = 'move';
+ return false; // disable the default action
+}
+
+
+// Called when the user clicks on the palette icon of a sticky note to change its color.
+// It toggles the color selector visible or invisible.
+
+function NotesClickPalette(evt, uid) {
+ uid_of_note_being_colored = uid;
+ d = $('palette-' + uid_of_note_being_colored);
- // Now select (or de-select) the message
- if ( (evt.ctrlKey) && (already_selected == 1) ) {
- $('m'+msgnum).style.backgroundColor = '#fff';
- $('m'+msgnum).style.color = '#000';
+ if (d.style.display) {
+ if (d.style.display == 'none') {
+ d.style.display = 'block';
+ }
+ else {
+ d.style.display = 'none';
+ }
}
else {
- $('m'+msgnum).style.backgroundColor='#69aaff';
- $('m'+msgnum).style.color='#fff';
- CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
- CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
+ d.style.display = 'block';
}
- // Update the preview pane
- new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
+ return true;
+}
+
+
+// Called when the user clicks on one of the colors in an open color selector.
+// Sets the desired color and then closes the color selector.
+
+function NotesClickColor(evt, uid, red, green, blue, notecolor, titlecolor) {
+ uid_of_note_being_colored = uid;
+ palette_button = $('palette-' + uid_of_note_being_colored);
+ note_div = $('note-' + uid_of_note_being_colored);
+ titlebar_div = $('titlebar-' + uid_of_note_being_colored);
- // Mark the message as read
+ // alert('FIXME red=' + red + ' green=' + green + ' blue=' + blue);
+
+ note_div.style.backgroundColor = notecolor;
+ titlebar_div.style.backgroundColor = titlecolor;
+ palette_button.style.display = 'none';
+
+ // submit an ajax http call to record it to the server
+ p = 'note_uid=' + uid_of_note_being_colored
+ + '&red=' + red
+ + '&green=' + green
+ + '&blue=' + blue
+ + '&r=' + CtdlRandomString();
new Ajax.Request(
- 'ajax_servcmd', {
+ 'ajax_update_note',
+ {
method: 'post',
- parameters: 'g_cmd=SEEN '+msgnum+'|1',
- onComplete: CtdlRemoveTheUnseenBold(msgnum)
+ parameters: p
}
);
-
- return false; // try to defeat the default click behavior
}
-// Delete selected messages.
-function CtdlDeleteSelectedMessages(evt) {
-
- if (CtdlNumMsgsSelected < 1) {
- // Nothing to delete, so exit silently.
- return false;
- }
- for (i=0; i<CtdlNumMsgsSelected; ++i) {
- if (parseInt(room_is_trash) > 0) {
- new Ajax.Request(
- 'ajax_servcmd', {
- method: 'post',
- parameters: 'g_cmd=DELE ' + CtdlMsgsSelected[i],
- onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
- }
- );
- }
- else {
- new Ajax.Request(
- 'ajax_servcmd', {
- method: 'post',
- parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
- onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
- }
- );
- }
- }
- CtdlNumMsgsSelected = 0;
- // Clear the preview pane too.
- $('preview_pane').innerHTML = '';
-}
-// Move selected messages.
-function CtdlMoveSelectedMessages(evt, target_roomname) {
-
- if (CtdlNumMsgsSelected < 1) {
- // Nothing to delete, so exit silently.
- return false;
+// These functions handle resizing sticky notes by dragging the resize handle
+
+var uid_of_note_being_resized = 0;
+var saved_cursor_style = 'default';
+var note_was_resized = 0;
+
+function NotesResizeMouseUp(evt) {
+ document.onmouseup = null;
+ document.onmousemove = null;
+ if (document.layers) {
+ document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
}
- for (i=0; i<CtdlNumMsgsSelected; ++i) {
+
+ d = $('note-' + uid_of_note_being_resized);
+ d.style.cursor = saved_cursor_style;
+
+ // If any motion actually occurred, submit an ajax http call to record it to the server
+ if (note_was_resized > 0) {
+ p = 'note_uid=' + uid_of_note_being_resized
+ + '&width=' + d.style.width
+ + '&height=' + d.style.height
+ + '&r=' + CtdlRandomString();
new Ajax.Request(
- 'ajax_servcmd', {
- method:'post',
- parameters:'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|' + target_roomname + '|0',
- onComplete:CtdlClearDeletedMsg(CtdlMsgsSelected[i])
+ 'ajax_update_note',
+ {
+ method: 'post',
+ parameters: p
}
);
}
- CtdlNumMsgsSelected = 0;
- // Clear the preview pane too.
- $('preview_pane').innerHTML = '';
+ uid_of_note_being_resized = '';
+ return false; // disable the default action
}
+function NotesResizeMouseMove(evt) {
+ x = (ns6 ? evt.clientX : event.clientX);
+ x_increment = x - saved_x;
+ y = (ns6 ? evt.clientY : event.clientY);
+ y_increment = y - saved_y;
+
+ // Move the div
+ d = $('note-' + uid_of_note_being_resized);
+
+ divTop = parseInt(d.style.height);
+ divLeft = parseInt(d.style.width);
+
+ newHeight = divTop + y_increment;
+ if (newHeight < 50) newHeight = 50;
+ newWidth = divLeft + x_increment;
+ if (newWidth < 50) newWidth = 50;
-// This gets called when the user touches the keyboard after selecting messages...
-function CtdlMsgListKeyPress(evt) {
- if(document.all) { // aIEeee
- var whichKey = window.event.keyCode;
+ d.style.height = newHeight + 'px';
+ d.style.width = newWidth + 'px';
+
+ saved_x = x;
+ saved_y = y;
+ note_was_resized = 1;
+ return false; // disable the default action
+}
+
+
+function NotesResizeMouseDown(evt, uid) {
+ saved_x = (ns6 ? evt.clientX : event.clientX);
+ saved_y = (ns6 ? evt.clientY : event.clientY);
+ document.onmouseup = NotesResizeMouseUp;
+ document.onmousemove = NotesResizeMouseMove;
+ if (document.layers) {
+ document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
}
- else { // non-sux0r browsers
- var whichKey = evt.which;
+ uid_of_note_being_resized = uid;
+ d = $('note-' + uid_of_note_being_resized);
+ saved_cursor_style = d.style.cursor;
+ d.style.cursor = 'move';
+ return false; // disable the default action
+}
+
+
+function DeleteStickyNote(evt, uid, confirmation_prompt) {
+ uid_of_note_being_deleted = uid;
+ d = $('note-' + uid_of_note_being_deleted);
+
+ if (confirm(confirmation_prompt)) {
+ new Effect.Puff(d);
+
+ // submit an ajax http call to delete it on the server
+ p = 'note_uid=' + uid_of_note_being_deleted
+ + '&deletenote=yes'
+ + '&r=' + CtdlRandomString();
+ new Ajax.Request(
+ 'ajax_update_note',
+ {
+ method: 'post',
+ parameters: p
+ }
+ );
}
- if (whichKey == 46) { // DELETE key
- CtdlDeleteSelectedMessages(evt);
+}
+
+function ctdl_ts_getInnerText(el) {
+ if (typeof el == "string") return el;
+ if (typeof el == "undefined") { return el };
+ if (el.innerText) return el.innerText; //Not needed but it is faster
+ var str = "";
+
+ var cs = el.childNodes;
+ var l = cs.length;
+ for (var i = 0; i < l; i++) {
+ switch (cs[i].nodeType) {
+ case 1: //ELEMENT_NODE
+ str += ts_getInnerText(cs[i]);
+ break;
+ case 3: //TEXT_NODE
+ str += cs[i].nodeValue;
+ break;
+ }
}
- return true;
+ return str;
}
-// Take the boldface away from a message to indicate that it has been seen.
-function CtdlRemoveTheUnseenBold(msgnum) {
- $('m'+msgnum).style.fontWeight='normal';
+
+// Place a gradient loadscreen on an element, e.g to use before Ajax.updater
+function CtdlLoadScreen(elementid) {
+var elem = document.getElementById(elementid);
+elem.innerHTML = "<div align=center><br><table border=0 cellpadding=10 bgcolor=\"#ffffff\"><tr><td><img src=\"static/throbber.gif\" /><font color=\"#AAAAAA\"> Loading....</font></td></tr></table><br></div>";
}
-// A message has been deleted, so yank it from the list.
-// (IE barfs on m9999.innerHTML='' so we use a script.aculo.us effect instead.)
-function CtdlClearDeletedMsg(msgnum) {
- new Effect.Squish('m'+msgnum);
+
+
+// Pop open the address book (target_input is the INPUT field to populate)
+
+function PopOpenAddressBook(target_input) {
+ $('address_book_popup').style.display = 'block';
+ p = 'target_input=' + target_input + '&r=' + CtdlRandomString();
+ new Ajax.Updater(
+ 'address_book_popup_middle_div',
+ 'display_address_book_middle_div',
+ {
+ method: 'get',
+ parameters: p,
+ evalScripts: true
+ }
+ );
}
+function PopulateAddressBookInnerDiv(which_addr_book, target_input) {
+ $('address_book_inner_div').innerHTML = "<div align=center><br><table border=0 cellpadding=10 bgcolor=\"#ffffff\"><tr><td><img src=\"static/throbber.gif\" /><font color=\"#AAAAAA\"> Loading....</font></td></tr></table><br></div>";
+ p = 'which_addr_book=' + which_addr_book
+ + '&target_input=' + target_input
+ + '&r=' + CtdlRandomString();
+ new Ajax.Updater(
+ 'address_book_inner_div',
+ 'display_address_book_inner_div',
+ {
+ method: 'get',
+ parameters: p
+ }
+ );
+}
-// These functions called when the user down-clicks on the message list resizer bar
+// What happens when a contact is selected from the address book popup
+// (populate the specified target)
-var saved_x = 0;
-var saved_y = 0;
+function AddContactsToTarget(target, whichaddr) {
+ while (whichaddr.selectedIndex != -1) {
+ if (target.value.length > 0) {
+ target.value = target.value + ', ';
+ }
+ target.value = target.value + whichaddr.value;
+ whichaddr.options[whichaddr.selectedIndex].selected = false;
+ }
+}
-function CtdlResizeMsgListMouseUp(evt) {
- document.onmouseup = null;
- document.onmousemove = null;
- if (document.layers) {
- document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
+// Respond to a meeting invitation
+function RespondToInvitation(question_divname, title_divname, msgnum, cal_partnum, sc) {
+ p = 'msgnum=' + msgnum + '&cal_partnum=' + cal_partnum + '&sc=' + sc ;
+ new Ajax.Updater(title_divname, 'respond_to_request', { method: 'post', parameters: p } );
+ Effect.Fade(question_divname, { duration: 0.5 });
+}
+
+// Handle a received RSVP
+function HandleRSVP(question_divname, title_divname, msgnum, cal_partnum, sc) {
+ p = 'msgnum=' + msgnum + '&cal_partnum=' + cal_partnum + '&sc=' + sc ;
+ new Ajax.Updater(title_divname, 'handle_rsvp', { method: 'post', parameters: p } );
+ Effect.Fade(question_divname, { duration: 0.5 });
+}
+/* var fakeMouse = document.createEvent("MouseEvents");
+ fakeMouse.initMouseEvent("click", true, true, window,
+ 0,0,0,0,0, false, false, false, false, 0, null); */
+// TODO: Collapse into one function
+function toggleTaskDtStart(event) {
+ var checkBox = $('nodtstart');
+ var checkBoxTime = $('dtstart_time_assoc');
+ var dtstart = document.getElementById("dtstart");
+ var dtstart_date = document.getElementById("dtstart_date");
+ var dtstart_time = document.getElementById("dtstart_time");
+ if (checkBox.checked) {
+ dtstart_date.style.visibility = "hidden";
+ dtstart_time.style.visibility = "hidden";
+ } else {
+ if (checkBoxTime.checked) {
+ dtstart_time.style.visibility = "visible";
+ } else {
+ dtstart_time.style.visibility = "hidden";
+ }
+ dtstart_date.style.visibility = "visible";
+ if (dtstart.value.length == 0)
+ dtstart.dpck._initCurrentDate();
+ }
+}
+function toggleTaskDue(event) {
+ var checkBox = $('nodue');
+ var checkBoxTime = $('due_time_assoc');
+ var due = document.getElementById("due");
+ var due_date = document.getElementById("due_date");
+ var due_time = document.getElementById("due_time");
+ if (checkBox.checked) {
+ due_date.style.visibility = "hidden";
+ due_time.style.visibility = "hidden";
+ } else {
+ if (checkBoxTime.checked) {
+ due_time.style.visibility = "visible";
+ } else {
+ due_time.style.visibility = "hidden";
+ }
+ due_date.style.visibility = "visible";
+ if (due.value.length == 0)
+ due.dpck._initCurrentDate();
+ }
+}
+function ToggleTaskDateOrNoDateActivate(event) {
+ var dtstart = document.getElementById("nodtstart");
+ if (dtstart != null) {
+ toggleTaskDtStart(null);
+ toggleTaskDue(null);
+ $('nodtstart').observe('click', toggleTaskDtStart);
+ $('dtstart_time_assoc').observe('click', toggleTaskDtStart);
+ $('nodue').observe('click', toggleTaskDue);
+ $('due_time_assoc').observe('click', toggleTaskDue);
+ }
+}
+function TaskViewGatherCategoriesFromTable() {
+ var table = $('taskview');
+
+}
+function attachDatePicker(relative) {
+ var dpck = new DatePicker({
+ relative: relative,
+ language: 'en', //wclang.substr(0,2),
+ disableFutureDate: false,
+ dateFormat: [ ["yyyy", "mm", "dd"], "-"],
+ showDuration: 0.2
+ });
+ document.getElementById(relative).dpck = dpck; // attach a ref to it
+}
+function eventEditAllDay() {
+ var allDayCheck = document.getElementById("alldayevent");
+ var dtend_time = document.getElementById("dtend_time");
+ var dtstart_time = document.getElementById("dtstart_time");
+ if(allDayCheck.checked) {
+ dtstart_time.style.visibility = "hidden";
+ dtend_time.style.visibility = "hidden";
+ } else {
+ dtstart_time.style.visibility = "visible";
+ dtend_time.style.visibility = "visible";
}
- return true;
}
-function CtdlResizeMsgListMouseMove(evt) {
- y = (ns6 ? evt.clientY : event.clientY);
- increment = y - saved_y;
+// Functions which handle show/hide of various elements in the recurrence editor
+
+function RecurrenceShowHide() {
- // First move the bottom of the message list...
- d = $('message_list');
- if (d.offsetHeight){
- divHeight = d.offsetHeight;
+ if ($('is_recur').checked) {
+ $('rrule_div').style.display = 'block';
}
- else if (d.style.pixelHeight) {
- divHeight = d.style.pixelHeight;
+ else {
+ $('rrule_div').style.display = 'none';
}
- d.style.height = (divHeight + increment) + 'px';
- // Then move the top of the preview pane...
- d = $('preview_pane');
- if (d.offsetTop){
- divTop = d.offsetTop;
+ if ($('freq_selector').selectedIndex == 4) {
+ $('weekday_selector').style.display = 'block';
}
- else if (d.style.pixelTop) {
- divTop = d.style.pixelTop;
+ else {
+ $('weekday_selector').style.display = 'none';
}
- d.style.top = (divTop + increment) + 'px';
- // Resize the bottom of the preview pane...
- d = $('preview_pane');
- if (d.offsetHeight){
- divHeight = d.offsetHeight;
+ if ($('freq_selector').selectedIndex == 5) {
+ $('monthday_selector').style.display = 'block';
}
- else if (d.style.pixelHeight) {
- divHeight = d.style.pixelHeight;
+ else {
+ $('monthday_selector').style.display = 'none';
}
- d.style.height = (divHeight - increment) + 'px';
- // Then move the top of the slider bar.
- d = $('resize_msglist');
- if (d.offsetTop){
- divTop = d.offsetTop;
+ if ($('rrend_count').checked) {
+ $('rrcount').disabled = false;
}
- else if (d.style.pixelTop) {
- divTop = d.style.pixelTop;
+ else {
+ $('rrcount').disabled = true;
}
- d.style.top = (divTop + increment) + 'px';
- saved_y = y;
- return true;
-}
+ if ($('rrend_until').checked) {
+ $('rruntil').disabled = false;
+ }
+ else {
+ $('rruntil').disabled = true;
+ }
-function CtdlResizeMsgListMouseDown(evt) {
- saved_y = (ns6 ? evt.clientY : event.clientY);
- document.onmouseup = CtdlResizeMsgListMouseUp;
- document.onmousemove = CtdlResizeMsgListMouseMove;
- if (document.layers) {
- document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
+ if ($('rrmonthtype_mday').checked) {
+ $('rrmday').disabled = false;
+ }
+ else {
+ $('rrmday').disabled = true;
}
- return false; // disable the default action
-}
+ if ($('rrmonthtype_wday').checked) {
+ $('rrmweek').disabled = false;
+ $('rrmweekday').disabled = false;
+ }
+ else {
+ $('rrmweek').disabled = true;
+ $('rrmweekday').disabled = true;
+ }
+ if ($('freq_selector').selectedIndex == 6) {
+ $('yearday_selector').style.display = 'block';
+ }
+ else {
+ $('yearday_selector').style.display = 'none';
+ }
-// These functions handle drag and drop message moving
+ $('ymday').innerHTML = 'XXXX-' + $('dtstart').value.substr(5);
+ $('rrmday').innerHTML = $('dtstart').value.substr(8);
-var mm_div = null;
+ if ($('rryeartype_ywday').checked) {
+ $('rrymweek').disabled = false;
+ $('rrymweekday').disabled = false;
+ $('rrymonth').disabled = false;
+ }
+ else {
+ $('rrymweek').disabled = true;
+ $('rrymweekday').disabled = true;
+ $('rrymonth').disabled = true;
+ }
-function CtdlMoveMsgMouseDown(evt, msgnum) {
+}
- // do the highlight first
- CtdlSingleClickMsg(evt, msgnum);
- // Now handle the possibility of dragging
- saved_x = (ns6 ? evt.clientX : event.clientX);
- saved_y = (ns6 ? evt.clientY : event.clientY);
- document.onmouseup = CtdlMoveMsgMouseUp;
- document.onmousemove = CtdlMoveMsgMouseMove;
- if (document.layers) {
- document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
+// Enable or disable the 'check attendee availability' button depending on whether
+// the attendees list is empty
+function EnableOrDisableCheckButton()
+{
+ if ($('attendees_box').value.length == 0) {
+ $('check_button').disabled = true;
+ }
+ else {
+ $('check_button').disabled = false;
}
-
- return false;
}
-function CtdlMoveMsgMouseMove(evt) {
- x = (ns6 ? evt.clientX : event.clientX);
- y = (ns6 ? evt.clientY : event.clientY);
- if ( (x == saved_x) && (y == saved_y) ) {
- return true;
- }
- if (CtdlNumMsgsSelected < 1) {
- return true;
- }
- if (!mm_div) {
+function launchChat(event) {
+window.open('chat', 'ctdl_chat_window', 'toolbar=no,location=no,directories=no,copyhistory=no,status=no,scrollbars=yes,resizable=yes');
+}
+// logger
+function WCLog(msg) {
+ if (!!window.console && !!console.log) {
+ console.log(msg);
+ } else if (!!window.opera && !!opera.postError) {
+ opera.postError(msg);
+ } else {
+ wc_log += msg + "\r\n";
+ }
+}
+function RefreshSMTPqueueDisplay() {
+ new Ajax.Updater('smtpqueue_inner_div',
+ 'display_smtpqueue_inner_div', { method: 'get',
+ parameters: Math.random() } );
+}
- drag_o_text = "<div style=\"overflow:none; background-color:#fff; color:#000; border: 1px solid black; filter:alpha(opacity=75); -moz-opacity:.75; opacity:.75;\"><tr><td>";
- for (i=0; i<CtdlNumMsgsSelected; ++i) {
- drag_o_text = drag_o_text +
- ctdl_ts_getInnerText(
- $('m'+CtdlMsgsSelected[i]).cells[0]
- ) + '<br>';
+function DeleteSMTPqueueMsg(msgnum1, msgnum2) {
+ var p = encodeURI('g_cmd=DELE ' + msgnum1 + ',' + msgnum2);
+ new Ajax.Request(
+ 'ajax_servcmd', {
+ method: 'post',
+ parameters: p,
+ onComplete: RefreshSMTPqueueDisplay()
}
- drag_o_text = drag_o_text + "<div>";
+ );
+}
- mm_div = document.createElement("DIV");
- mm_div.style.position='absolute';
- mm_div.style.top = y + 'px';
- mm_div.style.left = x + 'px';
- mm_div.style.pixelHeight = '300';
- mm_div.style.pixelWidth = '300';
- mm_div.innerHTML = drag_o_text;
- document.body.appendChild(mm_div);
- }
- else {
- mm_div.style.top = y + 'px';
- mm_div.style.left = x + 'px';
- }
- return false; // prevent the default mouse action from happening?
+function ConfirmLogoff() {
+ new Ajax.Updater(
+ 'md-content',
+ 'do_template?template=confirmlogoff',
+ {
+ method: 'get',
+ evalScripts: true,
+ onSuccess: function(cl_success) {
+ toggleModal(1);
+ }
+ }
+ );
}
-function CtdlMoveMsgMouseUp(evt) {
- document.onmouseup = null;
- document.onmousemove = null;
- if (document.layers) {
- document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
- }
- if (mm_div) {
- document.body.removeChild(mm_div);
- mm_div = null;
- }
+function switch_to_lang(new_lang) {
+ p = 'push?url=' + encodeURI(window.location);
+ new Ajax.Request(p, { method: 'get' } );
+ window.location = 'switch_language?lang=' + new_lang ;
+}
+
- if (num_drop_targets < 1) { // nowhere to drop
- return true;
+function toggle_roomlist()
+{
+ /* WARNING: VILE, SLEAZY HACK. We determine the state of the box based on the image loaded. */
+ if ( $('expand_roomlist').src.substring($('expand_roomlist').src.length - 12) == "collapse.gif" ) {
+ $('roomlist').style.display = 'none';
+ $('expand_roomlist').src = 'static/webcit_icons/expand.gif';
+ wstate=0;
}
- // Did we release the mouse button while hovering over a drop target?
- // NOTE: this only works cross-browser because the iconbar div is always
- // positioned at 0,0. Browsers differ in whether the 'offset'
- // functions return pos relative to the document or parent.
+ else {
+ $('roomlist').style.display = 'block';
+ $('expand_roomlist').src = 'static/webcit_icons/collapse.gif';
+ $('roomlist').innerHTML = '';
+ FillRooms(IconBarRoomList);
+ wstate=1;
+ }
- for (i=0; i<num_drop_targets; ++i) {
+ // tell the server what I did
+ p = 'toggle_roomlist_expanded_state?wstate=' + wstate + '?rand=' + Math.random() ;
+ new Ajax.Request(p, { method: 'get' } );
- x = (ns6 ? evt.clientX : event.clientX);
- y = (ns6 ? evt.clientY : event.clientY);
+ return false; /* this prevents the click from registering as a roomlist button press */
+}
- l = parseInt(drop_targets_elements[i].offsetLeft);
- t = parseInt(drop_targets_elements[i].offsetTop);
- r = parseInt(drop_targets_elements[i].offsetLeft)
- + parseInt(drop_targets_elements[i].offsetWidth);
- b = parseInt(drop_targets_elements[i].offsetTop)
- + parseInt(drop_targets_elements[i].offsetHeight);
- /* alert('Offsets are: ' + l + ' ' + t + ' ' + r + ' ' + b + '.'); */
-
- if ( (x >= l) && (x <= r) && (y >= t) && (y <= b) ) {
- // Yes, we dropped it on a hotspot.
- CtdlMoveSelectedMessages(evt, drop_targets_roomnames[i]);
- return true;
- }
+function toggle_wholist()
+{
+ /* WARNING: VILE, SLEAZY HACK. We determine the state of the box based on the image loaded. */
+ if ( $('expand_wholist').src.substring($('expand_wholist').src.length - 12) == "collapse.gif" ) {
+ $('online_users').style.display = 'none';
+ $('expand_wholist').src = 'static/webcit_icons/expand.gif';
+ wstate=0;
}
- return true;
-}
+ else {
+ $('online_users').style.display = 'block';
+ $('expand_wholist').src = 'static/webcit_icons/collapse.gif';
+ activate_iconbar_wholist_populat0r();
+ wstate=1;
+ }
+ // tell the server what I did
+ p = 'toggle_wholist_expanded_state?wstate=' + wstate + '?rand=' + Math.random() ;
+ new Ajax.Request(p, { method: 'get' } );
-function ctdl_ts_getInnerText(el) {
- if (typeof el == "string") return el;
- if (typeof el == "undefined") { return el };
- if (el.innerText) return el.innerText; //Not needed but it is faster
- var str = "";
-
- var cs = el.childNodes;
- var l = cs.length;
- for (var i = 0; i < l; i++) {
- switch (cs[i].nodeType) {
- case 1: //ELEMENT_NODE
- str += ts_getInnerText(cs[i]);
- break;
- case 3: //TEXT_NODE
- str += cs[i].nodeValue;
- break;
- }
- }
- return str;
+ return false; /* this prevents the click from registering as a wholist button press */
}