//
-// $Id: wclib.js,v 625.2 2005/09/18 04:04:32 ajc Exp $
+// $Id$
//
// JavaScript function library for WebCit.
//
}
var ns6=document.getElementById&&!document.all;
+Event.observe(window, 'load', ToggleTaskDateOrNoDateActivate);
+Event.observe(window, 'load', taskViewActivate);
+function CtdlRandomString() {
+ return((Math.random()+'').substr(3));
+}
function switch_to_room_list() {
$('iconbar').innerHTML = $('iconbar').innerHTML.substr(0, $('iconbar').innerHTML.indexOf('switch'));
+ CtdlLoadScreen('iconbar');
new Ajax.Updater('iconbar', 'iconbar_ajax_rooms', { method: 'get' } );
}
function switch_to_menu_buttons() {
which_div_expanded = null;
num_drop_targets = 0;
+ CtdlLoadScreen('iconbar');
new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );
}
//
var CtdlNumMsgsSelected = 0;
var CtdlMsgsSelected = new Array();
+var CtdlLastMsgnumSelected = 0;
// 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.
// Clear the preview pane until we load the new message
$('preview_pane').innerHTML = '';
- // 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) {
+ // De-select any messages that were already selected, *unless* the Ctrl or
+ // Shift key is being pressed, in which case the user wants multi select
+ // or group select.
+ if ( (!evt.ctrlKey) && (!evt.shiftKey) ) {
if (CtdlNumMsgsSelected > 0) {
for (i=0; i<CtdlNumMsgsSelected; ++i) {
$('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
for (i=0; i<CtdlNumMsgsSelected; ++i) {
if (CtdlMsgsSelected[i] == msgnum) {
already_selected = 1;
+ already_selected_pos = i;
}
}
}
// Now select (or de-select) the message
if ( (evt.ctrlKey) && (already_selected == 1) ) {
+
+ // Deselect: first un-highlight it...
$('m'+msgnum).style.backgroundColor = '#fff';
$('m'+msgnum).style.color = '#000';
- // FIXME pull the message out of the selected list here, stupid.
- // this will fix Bugzilla #173
+
+ // Then remove it from the selected messages list.
+ for (i=already_selected_pos; i<(CtdlNumMsgsSelected-1); ++i) {
+ CtdlMsgsSelected[i] = CtdlMsgsSelected[i+1];
+ }
+ CtdlNumMsgsSelected = CtdlNumMsgsSelected - 1;
+
+ }
+
+ else if (evt.shiftKey) {
+
+ // Group select: first clear everything out...
+ if (CtdlNumMsgsSelected > 0) {
+ for (i=0; i<CtdlNumMsgsSelected; ++i) {
+ $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
+ $('m'+CtdlMsgsSelected[i]).style.color = '#000';
+ }
+ }
+ CtdlNumMsgsSelected = 0;
+
+ // Then highlight and select the group.
+ // Traverse the table looking for a row whose ID contains the desired msgnum
+
+ var in_the_group = 0;
+ var is_edge = 0;
+ var table = $('summary_headers');
+ if (table) {
+ for (var r = 0; r < table.rows.length; r++) {
+ var thename = table.rows[r].id;
+ if ( (thename.substr(1) == msgnum) || (thename.substr(1) == CtdlLastMsgnumSelected) ) {
+ in_the_group = 1 - in_the_group;
+ is_edge = 1;
+ }
+ else {
+ is_edge = 0;
+ }
+ if ( (in_the_group == 1) || (is_edge == 1) ) {
+ // Highlight it...
+ table.rows[r].style.backgroundColor='#69aaff';
+ table.rows[r].style.color='#fff';
+
+ // And add it to the selected messages list.
+ CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
+ CtdlMsgsSelected[CtdlNumMsgsSelected-1] = thename.substr(1);
+ }
+ }
+ }
}
+
else {
+ // Select: first highlight it...
$('m'+msgnum).style.backgroundColor='#69aaff';
$('m'+msgnum).style.color='#fff';
+
+ // Then add it to the selected messages list.
CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
- }
-
- // Update the preview pane
- new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
- // Mark the message as read
- new Ajax.Request(
- 'ajax_servcmd', {
- method: 'post',
- parameters: 'g_cmd=SEEN '+msgnum+'|1',
- onComplete: CtdlRemoveTheUnseenBold(msgnum)
- }
- );
+ // Gradient
+ CtdlLoadScreen('preview_pane');
+ // Update the preview pane
+ new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
+
+ // Mark the message as read
+ new Ajax.Request(
+ 'ajax_servcmd', {
+ method: 'post',
+ parameters: 'g_cmd=SEEN '+msgnum+'|1',
+ onComplete: CtdlRemoveTheUnseenBold(msgnum)
+ }
+ );
+ }
+
+ // Save the selected position in case the user does a group select next time.
+ CtdlLastMsgnumSelected = msgnum;
return false; // try to defeat the default click behavior
}
+
+
+// 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);
+ }
+
+ d = $('note-' + uid_of_note_being_dragged);
+ 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_dragged > 0) {
+ p = 'note_uid=' + uid_of_note_being_dragged
+ + '&left=' + d.style.left
+ + '&top=' + d.style.top
+ + '&r=' + CtdlRandomString();
+ new Ajax.Request(
+ 'ajax_update_note',
+ {
+ method: 'post',
+ parameters: p
+ }
+ );
+ }
+
+ uid_of_note_being_dragged = '';
+ return true;
+}
+
+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);
+
+ divTop = parseInt(d.style.top);
+ divLeft = parseInt(d.style.left);
+
+ d.style.top = (divTop + y_increment) + 'px';
+ d.style.left = (divLeft + x_increment) + 'px';
+
+ saved_x = x;
+ saved_y = y;
+ note_was_dragged = 1;
+ return true;
+}
+
+
+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);
+
+ if (d.style.display) {
+ if (d.style.display == 'none') {
+ d.style.display = 'block';
+ }
+ else {
+ d.style.display = 'none';
+ }
+ }
+ else {
+ d.style.display = 'block';
+ }
+
+ 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) {
+ uid_of_note_being_colored = uid;
+ d = $('palette-' + uid_of_note_being_colored);
+
+ alert('FIXME red=' + red + ' green=' + green + ' blue=' + blue);
+
+ d.style.display = 'none';
+}
+
+
+
+
+// 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);
+ }
+
+ 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_update_note',
+ {
+ method: 'post',
+ parameters: p
+ }
+ );
+ }
+
+ uid_of_note_being_resized = '';
+ return true;
+}
+
+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);
+
+ d.style.height = (divTop + y_increment) + 'px';
+ d.style.width = (divLeft + x_increment) + 'px';
+
+ saved_x = x;
+ saved_y = y;
+ note_was_resized = 1;
+ return true;
+}
+
+
+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);
+ }
+ 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
+ }
+ );
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// These functions handle drag and drop message moving
var mm_div = null;
}
+function CtdlShowRaw(msgnum) {
+var customnav = document.createElement("span");
+var mode_citadel = document.createElement("a");
+mode_citadel.appendChild(document.createTextNode("Citadel Source"));
+var mode_rfc822 = document.createElement("a");
+mode_rfc822.appendChild(document.createTextNode(" RFC822 Source"));
+mode_citadel.setAttribute("href","#");
+mode_rfc822.setAttribute("href","#");
+mode_rfc822.setAttribute("onclick","rawSwitch822('" + msgnum + "');");
+mode_citadel.setAttribute("onclick","rawSwitchCitadel('" + msgnum + "');");
+customnav.appendChild(mode_citadel);
+customnav.appendChild(mode_rfc822);
+customnav.setAttribute("class","floatcustomnav");
+floatwindow("headerscreen","pre",customnav);
+rawSwitch822(msgnum);
+}
-// This function handles the creation of new notes in the "Notes" view.
-//
-function add_new_note() {
+function rawSwitch822(msgnum) {
+CtdlLoadScreen("headerscreen");
+new Ajax.Updater("headerscreen",
+'ajax_servcmd_esc',
+ { method: 'post',parameters: 'g_cmd=MSG2 ' +msgnum } );
+
+}
+
+function rawSwitchCitadel(msgnum) {
+CtdlLoadScreen("headerscreen");
+new Ajax.Updater("headerscreen",
+'ajax_servcmd_esc',
+ { method: 'post',parameters: 'g_cmd=MSG0 ' +msgnum } );
+
+}
+
+function floatwindow(newdivid,contentelementtype,customnav) {
+var windiv = document.createElement("div");
+windiv.setAttribute("class","floatwindow");
+var winid = newdivid+"_window";
+windiv.setAttribute("id",winid);
+var nav = document.createElement("div");
+if (customnav != null) {
+nav.appendChild(customnav);
+}
+var minimizeA = document.createElement("a");
+var minimizeButton = document.createTextNode("Close");
+minimizeA.appendChild(minimizeButton);
+minimizeA.setAttribute("onclick","killFloatWindow(this);");
+minimizeA.setAttribute("href","#");
+nav.appendChild(minimizeA);
+nav.setAttribute("class","floatnav");
+windiv.appendChild(nav);
+var contentarea = document.createElement("pre");
+contentarea.setAttribute("class","floatcontent");
+contentarea.setAttribute("id",newdivid);
+windiv.appendChild(contentarea);
+document.body.appendChild(windiv);
+}
+function killFloatWindow(caller) {
+var span = caller.parentNode;
+var fwindow = span.parentNode;
+fwindow.parentNode.removeChild(fwindow);
+}
+// 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>";
+}
- new_eid = Math.random() + '';
- new_eid = new_eid.substr(3);
- $('new_notes_here').innerHTML = $('new_notes_here').innerHTML
- + '<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">'
- + '<span id=\"note' + new_eid + '\">' + Date() + '</span><br />'
- ;
- new Ajax.InPlaceEditor('note' + new_eid,
- 'updatenote?eid=' + new_eid , {rows:5,cols:72});
+// 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
+ }
+ );
+}
+
+// What happens when a contact is selected from the address book popup
+// (populate the specified target)
+
+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;
+ }
+}
+
+// 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');
+ dtStart = document.getElementById("dtstart");
+ if (checkBox.checked) {
+ dtStart.disabled = true;
+ dtStart.style.textDecoration = "line-through";
+ } else {
+ dtStart.disabled = false;
+ dtStart.style.textDecoration = "";
+ if (dtStart.value.length == 0)
+ dtStart.dpck._initCurrentDate();
+ }
+}
+function toggleTaskDue(event) {
+ var checkBox = $('nodue');
+ dueField = document.getElementById("due");
+ if (checkBox.checked) {
+ dueField.disabled = true;
+ dueField.style.textDecoration = "line-through";
+ } else {
+ dueField.disabled = false;
+ dueField.style.textDecoration = "";
+ if (dueField.value.length == 0)
+ dueField.dpck._initCurrentDate();
+ }
+}
+function ToggleTaskDateOrNoDateActivate(event) {
+ var dtstart = document.getElementById("nodtstart");
+ if (dtstart != null) {
+ toggleTaskDtStart(null);
+ toggleTaskDue(null);
+ $('nodtstart').observe('click', toggleTaskDtStart);
+ $('nodue').observe('click', toggleTaskDue);
+ }
+}
+function TaskViewGatherCategoriesFromTable() {
+ var table = $('taskview');
+
+}
+function attachDatePicker(relative) {
+ var dpck = new DatePicker({
+ relative: relative,
+ language: 'en', // fix please
+ disableFutureDate: false
+ });
+ document.getElementById(relative).dpck = dpck; // attach a ref to it
+}
+function eventEditAllDay() {
+ var allDayCheck = document.getElementById("alldayevent");
+ var dtend= document.getElementById("dtendcell");
+ if(allDayCheck.checked) {
+ //dtend.disabled = true;
+ dtend.style.textDecoration = "line-through";
+ } else {
+ //dtend_day.disabled = false;
+ dtend.style.textDecoration = "";
+ }
}