]> code.citadel.org Git - citadel.git/blobdiff - webcit/static/wclib.js
Implemented the ajax call for updating notes.
[citadel.git] / webcit / static / wclib.js
index fbe50fde5a673aa3f427d4940b7ebee76a730c04..f1e7eaf9f501c2273ce0b3b4e808e9491716f956 100644 (file)
@@ -1,5 +1,5 @@
 //
-// $Id: wclib.js,v 625.2 2005/09/18 04:04:32 ajc Exp $
+// $Id$
 //
 // JavaScript function library for WebCit.
 //
@@ -18,6 +18,11 @@ if (window.navigator.userAgent.toLowerCase().match("gecko")) {
 var ns6=document.getElementById&&!document.all;
 
 
+function CtdlRandomString()  {
+       return((Math.random()+'').substr(3));
+}
+
+
 
 // We love string tokenizers.
 function extract_token(source_string, token_num, delimiter) {
@@ -417,6 +422,93 @@ 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
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 // These functions handle drag and drop message moving
 
 var mm_div = null;
@@ -552,11 +644,11 @@ function ctdl_ts_getInnerText(el) {
 //
 function add_new_note() {
 
-       new_eid = Math.random() + '';
-       new_eid = new_eid.substr(3);
+       new_eid = CtdlRandomString();
 
        $('new_notes_here').innerHTML = $('new_notes_here').innerHTML
-               + '<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">'
+               + '<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 />'
        ;
 
@@ -580,6 +672,7 @@ customnav.setAttribute("class","floatcustomnav");
 floatwindow("headerscreen","pre",customnav);
 rawSwitch822(msgnum);
 }
+
 function rawSwitch822(msgnum) {
 CtdlLoadScreen("headerscreen");
 new Ajax.Updater("headerscreen", 
@@ -587,6 +680,7 @@ new Ajax.Updater("headerscreen",
  { method: 'post',parameters: 'g_cmd=MSG2 ' +msgnum  } );
 
 }
+
 function rawSwitchCitadel(msgnum) {
 CtdlLoadScreen("headerscreen");
 new Ajax.Updater("headerscreen", 
@@ -594,6 +688,7 @@ new Ajax.Updater("headerscreen",
  { method: 'post',parameters: 'g_cmd=MSG0 ' +msgnum  } );
 
 }
+
 function floatwindow(newdivid,contentelementtype,customnav) {
 var windiv = document.createElement("div");
 windiv.setAttribute("class","floatwindow");
@@ -625,29 +720,92 @@ 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 = "<b>Loading....</b> <img src=\"/static/gradientanim.gif\"/>";
+elem.innerHTML = "<div align=center><br><table border=0 cellpadding=10 bgcolor=\"#ffffff\"><tr><td><img src=\"static/throbber.gif\" /><font color=\"#AAAAAA\">&nbsp;&nbsp;Loading....</font></td></tr></table><br /></div>";
 }
+
+
 // 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;
+       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)
+
+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\">&nbsp;&nbsp;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 });
+}
+