Color selector for sticky notes is now opaque instead
[citadel.git] / webcit / static / wclib.js
index 6f1c0a1cbcdb8d9e863dc64a55d53dfc8e4d2449..41d8232fe5ba3be285836e94616d5bf777402d50 100644 (file)
@@ -16,8 +16,8 @@ if (window.navigator.userAgent.toLowerCase().match("gecko")) {
 }
 
 var ns6=document.getElementById&&!document.all;
-
-
+Event.observe(window, 'load', ToggleTaskDateOrNoDateActivate);
+Event.observe(window, 'load', taskViewActivate);
 function CtdlRandomString()  {
        return((Math.random()+'').substr(3));
 }
@@ -422,6 +422,213 @@ function CtdlResizeMsgListMouseDown(evt) {
 
 
 
+
+
+// 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
+}
+
+
+
+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;
+}
+
+
+
+
+
+// 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;
@@ -552,22 +759,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\">'
-               + '<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");
@@ -636,32 +827,6 @@ elem.innerHTML = "<div align=center><br><table border=0 cellpadding=10 bgcolor=\
 }
 
 
-// Show info for a user, basically replaces showuser()
-// matt@comalies is to blame for this poorly coded masterpiece. 
-function CtdlShowUserInfoPopup(Element) {
-       try {
-               // hopefully no one needs to use the class attribute... could be better done 
-               // with xmlns though..
-               var user = Element.getAttribute("class");
-               var updname = "biospace_"+user;
-               if (document.getElementById(updname) == null) {
-                       // insert a space for the bio
-                       var pNode = Element.parentNode;
-                       var newdiv = document.createElement("div");
-                       newdiv.id = updname;
-                       newdiv.innerHTML = "Getting user info....";
-                       pNode.appendChild(newdiv);
-                       CtdlLoadScreen(updname);
-                       new Ajax.Updater(updname, 'showuser_ajax?who='+user, { method: 'get' } );
-               }
-       }
-       catch(err) {
-               return true;
-       }
-       return false;
-}
-
-
 
 // Pop open the address book (target_input is the INPUT field to populate)
 
@@ -677,7 +842,6 @@ function PopOpenAddressBook(target_input) {
                        evalScripts: true
                }
        );
-       Nifty('div#address_book_popup_container_div','big transparent');
 }
 
 function PopulateAddressBookInnerDiv(which_addr_book, target_input) {
@@ -721,4 +885,65 @@ 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.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 = "";
+       }
+}