X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Fstatic%2Fwclib.js;h=e8c0c4ee72c2aa1cd2df3f9e8132c02c284d9552;hp=bccc22debc77430a3d66d0d859b0c836e5dde8a9;hb=fc08ae6465b6da1d9008ce4b20b3cc2c2a5781af;hpb=5061e5a66dad94933e0545bd0655fd94a2815add diff --git a/webcit/static/wclib.js b/webcit/static/wclib.js index bccc22deb..e8c0c4ee7 100644 --- a/webcit/static/wclib.js +++ b/webcit/static/wclib.js @@ -1,28 +1,99 @@ -// -// $Id$ -// -// 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ 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 0) { - for (i=0; i 0) ) { - for (i=0; i 0) { - for (i=0; i 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]) - } - ); - } + $('roomlist').style.display = 'none'; } - 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; + /* 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(); } - for (i=0; i 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; @@ -600,8 +515,14 @@ function NotesResizeMouseMove(evt) { divTop = parseInt(d.style.height); divLeft = parseInt(d.style.width); - d.style.height = (divTop + y_increment) + 'px'; - d.style.width = (divLeft + x_increment) + 'px'; + newHeight = divTop + y_increment; + if (newHeight < 50) newHeight = 50; + + newWidth = divLeft + x_increment; + if (newWidth < 50) newWidth = 50; + + d.style.height = newHeight + 'px'; + d.style.width = newWidth + 'px'; saved_x = x; saved_y = y; @@ -647,128 +568,6 @@ function DeleteStickyNote(evt, uid, confirmation_prompt) { } } - - - - - - - - - - - - - - -// These functions handle drag and drop message moving - -var mm_div = null; - -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); - } - - 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) { - - - drag_o_text = "
"; - for (i=0; i'; - } - drag_o_text = drag_o_text + "
"; - - 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 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; - } - - if (num_drop_targets < 1) { // nowhere to drop - return true; - } - - // 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. - - for (i=0; i= l) && (x <= r) && (y >= t) && (y <= b) ) { - // Yes, we dropped it on a hotspot. - CtdlMoveSelectedMessages(evt, drop_targets_roomnames[i]); - return true; - } - } - - return true; -} - - function ctdl_ts_getInnerText(el) { if (typeof el == "string") return el; if (typeof el == "undefined") { return el }; @@ -791,71 +590,10 @@ function ctdl_ts_getInnerText(el) { } -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); -} - -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 = "

  Loading....

"; +elem.innerHTML = "

  Loading....

"; } @@ -877,7 +615,7 @@ function PopOpenAddressBook(target_input) { } function PopulateAddressBookInnerDiv(which_addr_book, target_input) { - $('address_book_inner_div').innerHTML = "

  Loading....

"; + $('address_book_inner_div').innerHTML = "

  Loading....

"; p = 'which_addr_book=' + which_addr_book + '&target_input=' + target_input + '&r=' + CtdlRandomString(); @@ -917,34 +655,48 @@ function HandleRSVP(question_divname, title_divname, msgnum, cal_partnum, 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); +/* 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"); + 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.disabled = true; - dtStart.style.textDecoration = "line-through"; + dtstart_date.style.visibility = "hidden"; + dtstart_time.style.visibility = "hidden"; } else { - dtStart.disabled = false; - dtStart.style.textDecoration = ""; - if (dtStart.value.length == 0) - dtStart.dpck._initCurrentDate(); + 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'); - dueField = document.getElementById("due"); + 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) { - dueField.disabled = true; - dueField.style.textDecoration = "line-through"; + due_date.style.visibility = "hidden"; + due_time.style.visibility = "hidden"; } else { - dueField.disabled = false; - dueField.style.textDecoration = ""; - if (dueField.value.length == 0) - dueField.dpck._initCurrentDate(); + 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) { @@ -953,41 +705,38 @@ function ToggleTaskDateOrNoDateActivate(event) { 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, wclang) { +function attachDatePicker(relative) { var dpck = new DatePicker({ relative: relative, - language: wclang.substr(0,2), - disableFutureDate: false, - dateFormat: [ ["yyyy", "mm", "dd"], "-"], - showDuration: 0.2, - closeEffectDuration: 0.2 + 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 = $('alldayevent'); - var dtend = $('dtendcell'); - - if (allDayCheck.checked) { - //dtend.disabled = true; - dtend.style.textDecoration = "line-through"; + 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 { - //dtend_day.disabled = false; - dtend.style.textDecoration = ""; + dtstart_time.style.visibility = "visible"; + dtend_time.style.visibility = "visible"; } } - - - // Functions which handle show/hide of various elements in the recurrence editor function RecurrenceShowHide() { @@ -1006,6 +755,13 @@ function RecurrenceShowHide() { $('weekday_selector').style.display = 'none'; } + if ($('freq_selector').selectedIndex == 5) { + $('monthday_selector').style.display = 'block'; + } + else { + $('monthday_selector').style.display = 'none'; + } + if ($('rrend_count').checked) { $('rrcount').disabled = false; } @@ -1020,4 +776,161 @@ function RecurrenceShowHide() { $('rruntil').disabled = true; } + if ($('rrmonthtype_mday').checked) { + $('rrmday').disabled = false; + } + else { + $('rrmday').disabled = true; + } + + 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'; + } + + $('ymday').innerHTML = 'XXXX-' + $('dtstart').value.substr(5); + $('rrmday').innerHTML = $('dtstart').value.substr(8); + + if ($('rryeartype_ywday').checked) { + $('rrymweek').disabled = false; + $('rrymweekday').disabled = false; + $('rrymonth').disabled = false; + } + else { + $('rrymweek').disabled = true; + $('rrymweekday').disabled = true; + $('rrymonth').disabled = true; + } + } + + +// 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; + } +} + + + + +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() } ); +} + +function DeleteSMTPqueueMsg(msgnum1, msgnum2) { + var p = encodeURI('g_cmd=DELE ' + msgnum1 + ',' + msgnum2); + new Ajax.Request( + 'ajax_servcmd', { + method: 'post', + parameters: p, + onComplete: RefreshSMTPqueueDisplay() + } + ); +} + + +function ConfirmLogoff() { + new Ajax.Updater( + 'md-content', + 'do_template?template=confirmlogoff', + { + method: 'get', + evalScripts: true, + onSuccess: function(cl_success) { + toggleModal(1); + } + } + ); +} + + +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 ; +} + + +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; + } + + else { + $('roomlist').style.display = 'block'; + $('expand_roomlist').src = 'static/webcit_icons/collapse.gif'; + $('roomlist').innerHTML = ''; + FillRooms(IconBarRoomList); + wstate=1; + } + + // tell the server what I did + p = 'toggle_roomlist_expanded_state?wstate=' + wstate + '?rand=' + Math.random() ; + new Ajax.Request(p, { method: 'get' } ); + + return false; /* this prevents the click from registering as a roomlist button press */ +} + + +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; + } + + 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' } ); + + return false; /* this prevents the click from registering as a wholist button press */ +} + +