Identify sticky-notes divs by vnote uid, not by msgnum.
authorArt Cancro <ajc@citadel.org>
Tue, 29 Apr 2008 14:51:50 +0000 (14:51 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 29 Apr 2008 14:51:50 +0000 (14:51 +0000)
This will make the ajax calls easier to implement.

citadel/modules/notes/serv_notes.c
webcit/notes.c
webcit/static/wclib.js
webcit/static/webcit.css

index 18ba3ad1ae4a510fc70da8bc0796aecadf5d4c44..56c1e6ee94690a9260bfcfc8753911001bf54008 100644 (file)
 #include "ctdl_module.h"
 
 
+/*
+ * Callback function for serv_notes_beforesave() hunts for a vNote in the MIME structure
+ */
+void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp,
+                  void *content, char *cbtype, char *cbcharset, size_t length,
+                  char *encoding, void *cbuserdata)
+{
+       struct vnote **v = (struct vnote **) cbuserdata;
+
+       if (!strcasecmp(cbtype, "text/vnote")) {
+
+               CtdlLogPrintf(CTDL_DEBUG, "Part %s contains a vNote!  Loading...\n", partnum);
+               if (*v != NULL) {
+                       vnote_free(*v);
+               }
+               *v = vnote_new_from_str(content);
+       }
+}
+
 
 /*
- * If we are in a "notes" view room, and the client has sent an RFC822
- * message containing an X-KOrg-Note-Id: field (Aethera does this, as
- * do some Kolab clients) then set both the Subject and the Exclusive ID
- * of the message to that.  It's going to be a UUID so we want to replace
- * any existing message containing that UUID.
+ * Before-save hook searches for two different types of notes (legacy Kolab/Aethera notes
+ * and modern vNote format notes) and does its best to learn the subject (summary)
+ * and EUID (uid) of the note for Citadel's own nefarious purposes.
  */
 int serv_notes_beforesave(struct CtdlMessage *msg)
 {
        char *p;
        int a, i;
-       char uuid[SIZ];
+       char uuid[512];
+       struct vnote *v = NULL;
 
        /* First determine if this room has the "notes" view set */
 
@@ -69,7 +87,13 @@ int serv_notes_beforesave(struct CtdlMessage *msg)
                return(0);      /* You tried to save a non-RFC822 message! */
        }
        
-       /* Find the X-KOrg-Note-Id: header */
+       /*
+        * If we are in a "notes" view room, and the client has sent an RFC822
+        * message containing an X-KOrg-Note-Id: field (Aethera does this, as
+        * do some Kolab clients) then set both the Subject and the Exclusive ID
+        * of the message to that.  It's going to be a UUID so we want to replace
+        * any existing message containing that UUID.
+        */
        strcpy(uuid, "");
        p = msg->cm_fields['M'];
        a = strlen(p);
@@ -99,6 +123,42 @@ int serv_notes_beforesave(struct CtdlMessage *msg)
                }
                p++;
        }
+
+       /* Modern clients are using vNote format.  Check for one... */
+
+       mime_parser(msg->cm_fields['M'],
+               NULL,
+               *notes_extract_vnote,
+               NULL, NULL,
+               &v,             /* user data ptr - put the vnote here */
+               0
+       );
+
+       if (v == NULL) return(0);       /* no vNotes were found in this message */
+
+       /* Set the message EUID to the vNote UID */
+
+       if (v->uid) if (!IsEmptyStr(v->uid)) {
+               CtdlLogPrintf(9, "UID of vNote is: %s\n", v->uid);
+               if (msg->cm_fields['E'] != NULL) {
+                       free(msg->cm_fields['E']);
+               }
+               msg->cm_fields['E'] = strdup(v->uid);
+       }
+
+       /* Set the message Subject to the vNote Summary */
+
+       if (v->summary) if (!IsEmptyStr(v->summary)) {
+               if (msg->cm_fields['U'] != NULL) {
+                       free(msg->cm_fields['U']);
+               }
+               msg->cm_fields['U'] = strdup(v->summary);
+               if (strlen(msg->cm_fields['U']) > 72) {
+                       strcpy(&msg->cm_fields['U'][68], "...");
+               }
+       }
+
+       vnote_free(v);
        
        return(0);
 }
index e1e3042a22616114595a5dbeed5d9db9fc957237..cfee05776dce893b4190be7eb98edcb322cd503f 100644 (file)
@@ -164,11 +164,11 @@ void updatenote(void)
 /*
  * Display a <div> containing a rendered sticky note.
  */
-void display_vnote_div(struct vnote *v, long msgnum) {
+void display_vnote_div(struct vnote *v) {
 
        /* begin outer div */
 
-       wprintf("<div id=\"note%ld\" ", msgnum);
+       wprintf("<div id=\"note-%s\" ", v->uid);
        wprintf("class=\"stickynote_outer\" ");
        wprintf("style=\"");
        wprintf("left: %dpx; ", v->pos_left);
@@ -180,15 +180,15 @@ void display_vnote_div(struct vnote *v, long msgnum) {
 
        /* begin title bar */
 
-       wprintf("<div id=\"titlebar%ld\" ", msgnum);
+       wprintf("<div id=\"titlebar-%s\" ", v->uid);
        wprintf("class=\"stickynote_titlebar\" ");
-       wprintf("onMouseDown=\"NotesDragMouseDown(event,%ld)\" ", msgnum);
+       wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
        wprintf("style=\"");
        wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2);
        wprintf("\">");
 
        wprintf("<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>");
-       wprintf("<td>&nbsp;</td>", msgnum);
+       wprintf("<td></td>");   // nothing in the title bar, it's just for dragging
 
        wprintf("<td align=right valign=middle "
                // "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
@@ -245,16 +245,16 @@ void display_note(long msgnum, int unread) {
                if (relevant_source != NULL) {
                        struct vnote *v = vnote_new_from_str(relevant_source);
                        free(relevant_source);
-                       display_vnote_div(v, msgnum);
-                       vnote_free(v);
-
+                       display_vnote_div(v);
                        /* FIXME remove these debugging messages when finished */
                        wprintf("<script type=\"text/javascript\">");
-                       wprintf("document.write('L: ' + $('note%ld').style.left + '<br>');", msgnum);
-                       wprintf("document.write('T: ' + $('note%ld').style.top + '<br>');", msgnum);
-                       wprintf("document.write('W: ' + $('note%ld').style.width + '<br>');", msgnum);
-                       wprintf("document.write('H: ' + $('note%ld').style.height + '<br>');", msgnum);
+                       wprintf("document.write('L: ' + $('note-%s').style.left + '<br>');", v->uid);
+                       wprintf("document.write('T: ' + $('note-%s').style.top + '<br>');", v->uid);
+                       wprintf("document.write('W: ' + $('note-%s').style.width + '<br>');", v->uid);
+                       wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
                        wprintf("</script>");
+                       /* */
+                       vnote_free(v);
                }
        }
 }
index fca12b2fbe54a68e8db7cd9941e1fdf2ce1168b1..e6a57cfaa96951badb4efe67fe06f8b850d415a4 100644 (file)
@@ -426,7 +426,7 @@ function CtdlResizeMsgListMouseDown(evt) {
 
 // These functions handle moving sticky notes around the screen by dragging them
 
-var msgnum_of_note_being_dragged = 0;
+var uid_of_note_being_dragged = 0;
 var saved_cursor_style = 'default';
 var note_was_dragged = 0;
 
@@ -437,7 +437,7 @@ function NotesDragMouseUp(evt) {
                document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
        }
 
-       d = $('note' + msgnum_of_note_being_dragged);
+       d = $('note-' + uid_of_note_being_dragged);
        d.style.cursor = saved_cursor_style;
 
        // Only submit the change if motion actually happened
@@ -445,7 +445,7 @@ function NotesDragMouseUp(evt) {
                alert('FIXME do ajax call to move position x=' + d.style.left + ' y=' + d.style.top);
        }
 
-       msgnum_of_note_being_dragged = 0;
+       uid_of_note_being_dragged = '';
        return true;
 }
 
@@ -456,7 +456,7 @@ function NotesDragMouseMove(evt) {
        y_increment = y - saved_y;
 
        // Move the div
-       d = $('note' + msgnum_of_note_being_dragged);
+       d = $('note-' + uid_of_note_being_dragged);
 
        divTop = parseInt(d.style.top);
        divLeft = parseInt(d.style.left);
@@ -471,7 +471,7 @@ function NotesDragMouseMove(evt) {
 }
 
 
-function NotesDragMouseDown(evt, msgnum) {
+function NotesDragMouseDown(evt, uid) {
        saved_x = (ns6 ? evt.clientX : event.clientX);
        saved_y = (ns6 ? evt.clientY : event.clientY);
        document.onmouseup = NotesDragMouseUp;
@@ -479,8 +479,8 @@ function NotesDragMouseDown(evt, msgnum) {
        if (document.layers) {
                document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
        }
-       msgnum_of_note_being_dragged = msgnum;
-       d = $('note' + msgnum_of_note_being_dragged);
+       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
index 537a2ce7ff99b6c04ea9706a1c2a6b76a9c78727..8c6cb18efcf12a1bc1756d4cd9e82cbd8b3c294c 100644 (file)
@@ -1338,4 +1338,5 @@ li.event_unread span, a.event_read_title {
        top: 0px;
        left: 0px;
        background-color: #888800;
+        font-size: 6px;     
 }