This will make the ajax calls easier to implement.
#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 */
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);
}
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);
}
/*
* 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);
/* 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> </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';\" "
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);
}
}
}
// 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;
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
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;
}
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);
}
-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;
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
top: 0px;
left: 0px;
background-color: #888800;
+ font-size: 6px;
}