* move some more vars from the session context to strbuf (the use of StrBufAppendTemp...
[citadel.git] / webcit / static / wclib.js
index 931d8e241893ec66731233dbfb613ed8380b8d33..1d04a9e50fc516d8c5c5669c238253f62ed4e855 100644 (file)
@@ -9,10 +9,14 @@
 var browserType;
 var room_is_trash = 0;
 
-if (document.layers) {browserType = "nn4"}
-if (document.all) {browserType = "ie"}
+if (document.layers) {
+       browserType = "nn4";
+}
+if (document.all) {
+       browserType = "ie";
+}
 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
-       browserType= "gecko"
+       browserType= "gecko";
 }
 
 var ns6=document.getElementById&&!document.all;
@@ -50,12 +54,15 @@ function extract_token(source_string, token_num, delimiter) {
 
 // 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";
 }
@@ -497,6 +504,61 @@ function NotesDragMouseDown(evt, uid) {
 }
 
 
+// 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, 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);
+
+       // 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_update_note',
+               {
+                       method: 'post',
+                       parameters: p
+               }
+       );
+}
+
+
+
 
 // These functions handle resizing sticky notes by dragging the resize handle
 
@@ -530,7 +592,7 @@ function NotesResizeMouseUp(evt) {
        }
 
        uid_of_note_being_resized = '';
-       return true;
+       return false;           // disable the default action
 }
 
 function NotesResizeMouseMove(evt) {
@@ -551,7 +613,7 @@ function NotesResizeMouseMove(evt) {
        saved_x = x;
        saved_y = y;
        note_was_resized = 1;
-       return true;
+       return false;           // disable the default action
 }
 
 
@@ -571,13 +633,26 @@ function NotesResizeMouseDown(evt, uid) {
 }
 
 
+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
+                       }
+               );
+       }
+}
 
 
 
@@ -723,23 +798,6 @@ function ctdl_ts_getInnerText(el) {
 }
 
 
-
-// This function handles the creation of new notes in the "Notes" view.
-//
-function add_new_note() {
-
-       new_eid = CtdlRandomString();
-
-       $('new_notes_here').innerHTML = $('new_notes_here').innerHTML
-               + '<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\" id=\"' + new_eid + '\" alt=\"Note\" class=\"notes\">'
-               + '<script type=\"text/javascript\">new Draggable (\"%s\", {revert:true})</script>'
-               + '<span id=\"note' + new_eid + '\">' + Date() + '</span><br />'
-       ;
-
-       new Ajax.InPlaceEditor('note' + new_eid,
-               'updatenote?eid=' + new_eid , {rows:5,cols:72});
-}
-
 function CtdlShowRaw(msgnum) {
 var customnav = document.createElement("span");
 var mode_citadel = document.createElement("a");
@@ -866,24 +924,34 @@ 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);
 // TODO: Collapse into one function
 function toggleTaskDtStart(event) {
        var checkBox = $('nodtstart');
+       dtStart = document.getElementById("dtstart");
        if (checkBox.checked) {
-               $('dtstart').disabled = true;
-               $('dtstart').value = "";
+               dtStart.disabled = true;
+               dtStart.style.textDecoration = "line-through";
        } else {
-               $('dtstart').disabled = false;
+               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) {
-               $('due').disabled = true;
-               $('due').value = "";
+               dueField.disabled = true;
+               dueField.style.textDecoration = "line-through";
        } else {
-               $('due').disabled = false;
+               dueField.disabled = false;
+               dueField.style.textDecoration = "";
+               if (dueField.value.length == 0)
+                       dueField.dpck._initCurrentDate();
        }
 }
 function ToggleTaskDateOrNoDateActivate(event) {
@@ -899,3 +967,22 @@ 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 = "";
+       }
+}