10 int pastel_palette[9][3] = {
24 * Display a <div> containing a rendered sticky note.
26 void display_vnote_div(struct vnote *v) {
30 wprintf("<div id=\"note-%s\" ", v->uid); /* begin outer div */
31 wprintf("class=\"stickynote_outer\" ");
33 wprintf("left: %dpx; ", v->pos_left);
34 wprintf("top: %dpx; ", v->pos_top);
35 wprintf("width: %dpx; ", v->pos_width);
36 wprintf("height: %dpx; ", v->pos_height);
37 wprintf("background-color: #%02X%02X%02X ", v->color_red, v->color_green, v->color_blue);
44 wprintf("<div id=\"titlebar-%s\" ", v->uid); /* begin title bar div */
45 wprintf("class=\"stickynote_titlebar\" ");
46 wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
48 wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2);
51 wprintf("<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>");
53 wprintf("<td align=left valign=middle>");
54 wprintf("<img onclick=\"NotesClickPalette(event,'%s')\" ", v->uid);
55 wprintf("src=\"static/8paint16.gif\">");
59 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
61 wprintf("<td align=right valign=middle>");
62 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
63 wprintf("src=\"static/closewindow.gif\">");
64 wprintf("</td></tr></table>");
66 wprintf("</div>\n"); // end title bar div
72 wprintf("<div id=\"notebody-%s\" ", v->uid); // begin body div
73 wprintf("class=\"stickynote_body\"");
76 wprintf("</div>\n"); // end body div
78 StrBufAppendPrintf(WC->trailing_javascript,
79 " new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
80 "{rows:%d,cols:%d,onEnterHover:false,onLeaveHover:false,"
81 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
84 (v->pos_height / 16) - 5,
85 (v->pos_width / 9) - 1,
88 _("Click on any note to edit it.")
91 wprintf("<div id=\"resize-%s\" ", v->uid); // begin resize handle div
92 wprintf("class=\"stickynote_resize\" ");
93 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
94 wprintf("> </div>"); // end resize handle div
99 /* embed color selector - it doesn't have to be inside the title bar html because
100 * it's a separate div placed by css
102 wprintf("<div id=\"palette-%s\" ", v->uid); // begin stickynote_palette div
103 wprintf("class=\"stickynote_palette\">");
105 wprintf("<table border=0 cellpadding=0 cellspacing=0>");
106 for (i=0; i<9; ++i) {
107 if ((i%3)==0) wprintf("<tr>");
109 wprintf("onClick=\"NotesClickColor(event,'%s',%d,%d,%d,'#%02x%02x%02x','#%02x%02x%02x')\" ",
111 pastel_palette[i][0], // color values to pass to ajax call
112 pastel_palette[i][1],
113 pastel_palette[i][2],
114 pastel_palette[i][0], // new color of note
115 pastel_palette[i][1],
116 pastel_palette[i][2],
117 pastel_palette[i][0] / 2, // new color of title bar
118 pastel_palette[i][1] / 2,
119 pastel_palette[i][2] / 2
121 wprintf("bgcolor=\"#%02x%02x%02x\"> </td>",
122 pastel_palette[i][0],
123 pastel_palette[i][1],
126 if (((i+1)%3)==0) wprintf("</tr>");
130 wprintf("</div>"); // end stickynote_palette div
136 wprintf("</div>\n"); // end outer div
142 * Fetch a message from the server and extract a vNote from it
144 struct vnote *vnote_new_from_msg(long msgnum,int unread)
151 char uid_from_headers[256];
152 char mime_partnum[256];
153 char mime_filename[256];
154 char mime_content_type[256];
155 char mime_disposition[256];
157 char relevant_partnum[256];
158 int phase = 0; /* 0 = citadel headers, 1 = mime headers, 2 = body */
159 char msg4_content_type[256] = "";
160 char msg4_content_encoding[256] = "";
161 int msg4_content_length = 0;
162 struct vnote *vnote_from_body = NULL;
164 relevant_partnum[0] = '\0';
165 serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */
167 StrBuf_ServGetlnBuffered(Buf);
168 if (GetServerStatus(Buf, NULL) != 1) {
172 while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) {
173 if ( (StrLength(Buf)==3) &&
174 !strcmp(ChrPtr(Buf), "000")) {
181 if (!strncasecmp(bptr, "exti=", 5)) {
182 safestrncpy(uid_from_headers, &(ChrPtr(Buf)[5]), sizeof uid_from_headers);
184 else if (!strncasecmp(bptr, "part=", 5)) {
185 extract_token(mime_filename, &bptr[5], 1, '|', sizeof mime_filename);
186 extract_token(mime_partnum, &bptr[5], 2, '|', sizeof mime_partnum);
187 extract_token(mime_disposition, &bptr[5], 3, '|', sizeof mime_disposition);
188 extract_token(mime_content_type, &bptr[5], 4, '|', sizeof mime_content_type);
189 mime_length = extract_int(&bptr[5], 5);
191 if ( (!strcasecmp(mime_content_type, "text/calendar"))
192 || (!strcasecmp(mime_content_type, "application/ics"))
193 || (!strcasecmp(mime_content_type, "text/vtodo"))
195 strcpy(relevant_partnum, mime_partnum);
198 else if (!strncasecmp(bptr, "from=", 4)) {
199 extract_token(from, bptr, 1, '=', sizeof(from));
201 else if ((phase == 0) && (!strncasecmp(bptr, "text", 4))) {
206 if (!IsEmptyStr(bptr)) {
207 if (!strncasecmp(bptr, "Content-type: ", 14)) {
208 safestrncpy(msg4_content_type, &bptr[14], sizeof msg4_content_type);
209 striplt(msg4_content_type);
211 else if (!strncasecmp(bptr, "Content-transfer-encoding: ", 27)) {
212 safestrncpy(msg4_content_encoding, &bptr[27], sizeof msg4_content_encoding);
213 striplt(msg4_content_type);
215 else if ((!strncasecmp(bptr, "Content-length: ", 16))) {
216 msg4_content_length = atoi(&bptr[16]);
223 if ((msg4_content_length > 0)
224 && ( !strcasecmp(msg4_content_encoding, "7bit"))
225 && ((!strcasecmp(mime_content_type, "text/calendar"))
226 || (!strcasecmp(mime_content_type, "application/ics"))
227 || (!strcasecmp(mime_content_type, "text/vtodo"))
234 Data = NewStrBufPlain(NULL, msg4_content_length * 2);
235 if (msg4_content_length > 0) {
236 StrBuf_ServGetBLOBBuffered(Data, msg4_content_length);
240 StrBufAppendBuf(Data, Buf, 0);
241 StrBufAppendBufPlain(Data, "\r\n", 1, 0);
244 StrBufAppendBuf(Data, Buf, 0);
249 /* If MSG4 didn't give us the part we wanted, but we know that we can find it
250 * as one of the other MIME parts, attempt to load it now.
252 if ((Data == NULL) && (!IsEmptyStr(relevant_partnum))) {
253 Data = load_mimepart(msgnum, relevant_partnum);
257 if ((IsEmptyStr(relevant_partnum)) && (StrLength(Data) > 0 )) {
258 if (!IsEmptyStr(uid_from_headers)) {
259 // Convert an old-style note to a vNote
260 vnote_from_body = vnote_new();
261 vnote_from_body->uid = strdup(uid_from_headers);
262 vnote_from_body->color_red = pastel_palette[3][0];
263 vnote_from_body->color_green = pastel_palette[3][1];
264 vnote_from_body->color_blue = pastel_palette[3][2];
265 vnote_from_body->body = malloc(StrLength(Data) + 1);
266 vnote_from_body->body[0] = 0;
267 memcpy(vnote_from_body->body, ChrPtr(Data), StrLength(Data) + 1);
268 return vnote_from_body;
271 struct vnote *v = vnote_new_from_str(ChrPtr(Data));
281 * Serialize a vnote and write it to the server
283 void write_vnote_to_server(struct vnote *v)
288 serv_puts("ENT0 1|||4");
289 serv_getln(buf, sizeof buf);
291 serv_puts("Content-type: text/vnote");
293 pch = vnote_serialize(v);
304 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
306 void ajax_update_note(void) {
310 struct vnote *v = NULL;
312 if (!havebstr("note_uid")) {
313 begin_ajax_response();
314 wprintf("Received ajax_update_note() request without a note UID.");
319 // lprintf(9, "Note UID = %s\n", bstr("note_uid"));
320 serv_printf("EUID %s", bstr("note_uid"));
321 serv_getln(buf, sizeof buf);
323 begin_ajax_response();
324 wprintf("Cannot find message containing vNote with the requested uid!");
328 msgnum = atol(&buf[4]);
329 // lprintf(9, "Note msg = %ld\n", msgnum);
331 // Was this request a delete operation? If so, nuke it...
332 if (havebstr("deletenote")) {
333 if (!strcasecmp(bstr("deletenote"), "yes")) {
334 serv_printf("DELE %d", msgnum);
335 serv_getln(buf, sizeof buf);
336 begin_ajax_response();
343 // If we get to this point it's an update, not a delete
344 v = vnote_new_from_msg(msgnum, 0);
346 begin_ajax_response();
347 wprintf("Cannot locate a vNote within message %d\n", msgnum);
352 /* Make any requested changes */
353 if (havebstr("top")) {
354 v->pos_top = atoi(bstr("top"));
356 if (havebstr("left")) {
357 v->pos_left = atoi(bstr("left"));
359 if (havebstr("height")) {
360 v->pos_height = atoi(bstr("height"));
362 if (havebstr("width")) {
363 v->pos_width = atoi(bstr("width"));
365 if (havebstr("red")) {
366 v->color_red = atoi(bstr("red"));
368 if (havebstr("green")) {
369 v->color_green = atoi(bstr("green"));
371 if (havebstr("blue")) {
372 v->color_blue = atoi(bstr("blue"));
374 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
375 if (v->body) free(v->body);
376 v->body = strdup(bstr("value"));
379 /* Serialize it and save it to the message base. Server will delete the old one. */
380 write_vnote_to_server(v);
382 begin_ajax_response();
395 * display sticky notes
397 * msgnum = Message number on the local server of the note to be displayed
399 void display_note(message_summary *Msg, int unread) {
403 memset(&TP, 0, sizeof(WCTemplputParams));
404 TP.Filter.ContextType = CTX_VNOTE;
405 v = vnote_new_from_msg(Msg->msgnum, unread);
407 // display_vnote_div(v);
409 DoTemplate(HKEY("vnoteitem"),
413 /* uncomment these lines to see ugly debugging info
414 StrBufAppendPrintf(WC->trailing_javascript,
415 "document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
416 StrBufAppendPrintf(WC->trailing_javascript,
417 "document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
418 StrBufAppendPrintf(WC->trailing_javascript,
419 "document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
420 StrBufAppendPrintf(WC->trailing_javascript,
421 "document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
433 void add_new_note(void) {
438 v->uid = malloc(128);
439 generate_uuid(v->uid);
440 v->color_red = pastel_palette[3][0];
441 v->color_green = pastel_palette[3][1];
442 v->color_blue = pastel_palette[3][2];
443 v->body = strdup(_("Click on any note to edit it."));
444 write_vnote_to_server(v);
452 void tmpl_vcard_put_posleft(StrBuf *Target, WCTemplputParams *TP)
454 struct vnote *v = (struct vnote *) CTX;
455 StrBufAppendPrintf(Target, "%d", v->pos_left);
458 void tmpl_vcard_put_postop(StrBuf *Target, WCTemplputParams *TP)
460 struct vnote *v = (struct vnote *) CTX;
461 StrBufAppendPrintf(Target, "%d", v->pos_top);
464 void tmpl_vcard_put_poswidth(StrBuf *Target, WCTemplputParams *TP)
466 struct vnote *v = (struct vnote *) CTX;
467 StrBufAppendPrintf(Target, "%d", v->pos_width);
470 void tmpl_vcard_put_posheight(StrBuf *Target, WCTemplputParams *TP)
472 struct vnote *v = (struct vnote *) CTX;
473 StrBufAppendPrintf(Target, "%d", v->pos_height);
476 void tmpl_vcard_put_posheight2(StrBuf *Target, WCTemplputParams *TP)
478 struct vnote *v = (struct vnote *) CTX;
479 StrBufAppendPrintf(Target, "%d", (v->pos_height / 16) - 5);
482 void tmpl_vcard_put_width2(StrBuf *Target, WCTemplputParams *TP)
484 struct vnote *v = (struct vnote *) CTX;
485 StrBufAppendPrintf(Target, "%d", (v->pos_width / 9) - 1);
488 void tmpl_vcard_put_color(StrBuf *Target, WCTemplputParams *TP)
490 struct vnote *v = (struct vnote *) CTX;
491 StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red, v->color_green, v->color_blue);
494 void tmpl_vcard_put_bgcolor(StrBuf *Target, WCTemplputParams *TP)
496 struct vnote *v = (struct vnote *) CTX;
497 StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red/2, v->color_green/2, v->color_blue/2);
500 void tmpl_vcard_put_message(StrBuf *Target, WCTemplputParams *TP)
502 struct vnote *v = (struct vnote *) CTX;
503 StrEscAppend(Target, NULL, v->body, 0, 0); ///TODO?
506 void tmpl_vcard_put_uid(StrBuf *Target, WCTemplputParams *TP)
508 struct vnote *v = (struct vnote *) CTX;
509 StrBufAppendBufPlain(Target, v->uid, -1, 0);
516 WebcitAddUrlHandler(HKEY("add_new_note"), add_new_note, 0);
517 WebcitAddUrlHandler(HKEY("ajax_update_note"), ajax_update_note, 0);
519 RegisterNamespace("VNOTE:POS:LEFT", 0, 0, tmpl_vcard_put_posleft, CTX_VNOTE);
520 RegisterNamespace("VNOTE:POS:TOP", 0, 0, tmpl_vcard_put_postop, CTX_VNOTE);
521 RegisterNamespace("VNOTE:POS:WIDTH", 0, 0, tmpl_vcard_put_poswidth, CTX_VNOTE);
522 RegisterNamespace("VNOTE:POS:HEIGHT", 0, 0, tmpl_vcard_put_posheight, CTX_VNOTE);
523 RegisterNamespace("VNOTE:POS:HEIGHT2", 0, 0, tmpl_vcard_put_posheight2, CTX_VNOTE);
524 RegisterNamespace("VNOTE:POS:WIDTH2", 0, 0, tmpl_vcard_put_width2, CTX_VNOTE);
525 RegisterNamespace("VNOTE:COLOR", 0, 0, tmpl_vcard_put_color, CTX_VNOTE);
526 RegisterNamespace("VNOTE:BGCOLOR", 0, 0,tmpl_vcard_put_bgcolor, CTX_VNOTE);
527 RegisterNamespace("VNOTE:MSG", 0, 1, tmpl_vcard_put_message, CTX_VNOTE);
528 RegisterNamespace("VNOTE:UID", 0, 0, tmpl_vcard_put_uid, CTX_VNOTE);