12 * Uncomment this #define in order to get the new vNote-based sticky notes view.
13 * We're keeping both versions here so that I can work on the new view without breaking
14 * the existing implementation prior to completion.
17 /* #define NEW_NOTES_VIEW */
20 #ifndef NEW_NOTES_VIEW
22 * display sticky notes
24 * msgnum = Message number on the local server of the note to be displayed
26 void display_note(long msgnum, int unread)
30 char display_notetext[SIZ];
35 serv_printf("MSG0 %ld", msgnum);
36 serv_getln(buf, sizeof buf);
38 wprintf("%s<br />\n", &buf[4]);
44 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
47 if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
48 strcat(notetext, buf);
51 if ( (!in_text) && (!strncasecmp(buf, "exti=", 5)) ) {
52 safestrncpy(eid, &buf[5], sizeof eid);
55 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
60 /* Now sanitize the buffer */
61 len = strlen(notetext);
62 for (i=0; i<len; ++i) {
63 if (isspace(notetext[i])) notetext[i] = ' ';
66 /* Make it HTML-happy and print it. */
67 stresc(display_notetext, SIZ, notetext, 0, 0);
69 /* Lets try it as a draggable */
70 if (!IsEmptyStr(eid)) {
71 wprintf ("<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\" id=\"note_%s\" alt=\"Note\" ", eid);
72 wprintf ("class=\"notes\">\n");
73 wprintf ("<script type=\"text/javascript\">\n");
74 wprintf ("new Draggable (\"note_%s\", {revert:true})\n", eid);
75 wprintf ("</script>\n");
78 wprintf ("<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\" id=\"note_%ld\" ", msgnum);
79 wprintf ("class=\"notes\">\n");
80 wprintf ("<script type=\"text/javascript\">\n");
81 wprintf ("new Draggable (\"note_%ld\", {revert:true})\n", msgnum);
82 wprintf ("</script>\n");
85 if (!IsEmptyStr(eid)) {
86 wprintf("<span id=\"note%s\">%s</span><br />\n", eid, display_notetext);
89 wprintf("<span id=\"note%ld\">%s</span><br />\n", msgnum, display_notetext);
92 /* Offer in-place editing. */
93 if (!IsEmptyStr(eid)) {
94 wprintf("<script type=\"text/javascript\">"
95 "new Ajax.InPlaceEditor('note%s', 'updatenote?nonce=%ld?eid=%s', {rows:5,cols:72});"
107 * This gets called by the Ajax.InPlaceEditor when we save a note.
109 void updatenote(void)
113 char display_notetext[SIZ];
118 serv_printf("ENT0 1||0|0||||||%s", bstr("eid"));
119 serv_getln(buf, sizeof buf);
121 text_to_server(bstr("value"));
125 begin_ajax_response();
126 msgnum = locate_message_by_uid(bstr("eid"));
128 serv_printf("MSG0 %ld", msgnum);
129 serv_getln(buf, sizeof buf);
131 strcpy(notetext, "");
132 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
134 /* Fill the buffer */
135 if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
136 strcat(notetext, buf);
139 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
143 /* Now sanitize the buffer */
144 len = strlen(notetext);
145 for (i=0; i<len; ++i) {
146 if (isspace(notetext[i])) notetext[i] = ' ';
149 /* Make it HTML-happy and print it. */
150 stresc(display_notetext, SIZ, notetext, 0, 0);
151 wprintf("%s\n", display_notetext);
155 wprintf("%s", _("An error has occurred."));
166 * Display a <div> containing a rendered sticky note.
168 void display_vnote_div(struct vnote *v) {
170 /* begin outer div */
172 wprintf("<div id=\"note-%s\" ", v->uid);
173 wprintf("class=\"stickynote_outer\" ");
175 wprintf("left: %dpx; ", v->pos_left);
176 wprintf("top: %dpx; ", v->pos_top);
177 wprintf("width: %dpx; ", v->pos_width);
178 wprintf("height: %dpx; ", v->pos_height);
179 wprintf("background-color: #%02X%02X%02X ", v->color_red, v->color_green, v->color_blue);
182 /* begin title bar */
184 wprintf("<div id=\"titlebar-%s\" ", v->uid);
185 wprintf("class=\"stickynote_titlebar\" ");
186 wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
188 wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2);
191 wprintf("<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>");
192 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
194 wprintf("<td align=right valign=middle "
195 // "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
196 "><img src=\"static/closewindow.gif\">");
197 wprintf("</td></tr></table>");
201 /* begin note body */
203 wprintf("<div id=\"notebody-%s\" ", v->uid);
204 wprintf("class=\"stickynote_body\"");
209 wprintf("<script type=\"text/javascript\">");
210 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
211 "{rows:%d,cols:%d,highlightcolor:'#%02X%02X%02X',highlightendcolor:'#%02X%02X%02X',"
212 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
215 (v->pos_height / 16) - 5,
216 (v->pos_width / 9) - 1,
217 v->color_red, v->color_green, v->color_blue,
218 v->color_red, v->color_green, v->color_blue,
221 _("Click on any note to edit it.")
223 wprintf("</script>\n");
225 /* begin resize handle */
227 wprintf("<div id=\"resize-%s\" ", v->uid);
228 wprintf("class=\"stickynote_resize\" ");
229 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
232 wprintf("<img src=\"static/resizecorner.png\">");
244 * Fetch a message from the server and extract a vNote from it
246 struct vnote *vnote_new_from_msg(long msgnum) {
248 char mime_partnum[256];
249 char mime_filename[256];
250 char mime_content_type[256];
251 char mime_disposition[256];
253 char relevant_partnum[256];
254 char *relevant_source = NULL;
255 char uid_from_headers[256];
257 int body_line_len = 0;
259 struct vnote *vnote_from_body = NULL;
261 relevant_partnum[0] = 0;
262 uid_from_headers[0] = 0;
263 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
265 serv_getln(buf, sizeof buf);
266 if (buf[0] != '1') return NULL;
268 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
269 if (!strncasecmp(buf, "exti=", 5)) {
270 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
272 else if (!strncasecmp(buf, "part=", 5)) {
273 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
274 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
275 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
276 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
277 mime_length = extract_int(&buf[5], 5);
279 if (!strcasecmp(mime_content_type, "text/vnote")) {
280 strcpy(relevant_partnum, mime_partnum);
283 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
284 // Convert an old-style note to a vNote
285 if (!vnote_from_body) {
286 vnote_from_body = vnote_new();
287 vnote_from_body->uid = strdup(uid_from_headers);
288 vnote_from_body->body = malloc(32768);
289 vnote_from_body->body[0] = 0;
292 body_line_len = strlen(buf);
293 if ((body_len + body_line_len + 10) < 32768) {
294 strcpy(&vnote_from_body->body[body_len++], " ");
295 strcpy(&vnote_from_body->body[body_len], buf);
296 body_len += body_line_len;
299 else if (IsEmptyStr(buf)) {
304 if (!IsEmptyStr(relevant_partnum)) {
305 relevant_source = load_mimepart(msgnum, relevant_partnum);
306 if (relevant_source != NULL) {
307 struct vnote *v = vnote_new_from_str(relevant_source);
308 free(relevant_source);
313 if (vnote_from_body) {
314 return(vnote_from_body);
321 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
323 void ajax_update_note(void) {
327 struct vnote *v = NULL;
329 if (!havebstr("note_uid")) {
330 begin_ajax_response();
331 wprintf("Received ajax_update_note() request without a note UID.");
336 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
337 serv_printf("EUID %s", bstr("note_uid"));
338 serv_getln(buf, sizeof buf);
340 begin_ajax_response();
341 wprintf("Cannot find message containing vNote with the requested uid!");
345 msgnum = atol(&buf[4]);
346 v = vnote_new_from_msg(msgnum);
348 begin_ajax_response();
349 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
354 /* Make any requested changes */
355 if (havebstr("top")) {
356 v->pos_top = atoi(bstr("top"));
358 if (havebstr("left")) {
359 v->pos_left = atoi(bstr("left"));
361 if (havebstr("height")) {
362 v->pos_height = atoi(bstr("height"));
364 if (havebstr("width")) {
365 v->pos_width = atoi(bstr("width"));
367 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
368 if (v->body) free(v->body);
369 v->body = strdup(bstr("value"));
372 /* Serialize it and save it to the message base. Server will delete the old one. */
373 serv_puts("ENT0 1|||4");
374 serv_getln(buf, sizeof buf);
376 serv_puts("Content-type: text/vnote");
378 serv_puts(vnote_serialize(v));
382 begin_ajax_response();
396 #ifdef NEW_NOTES_VIEW
399 * display sticky notes
401 * msgnum = Message number on the local server of the note to be displayed
403 void display_note(long msgnum, int unread) {
406 v = vnote_new_from_msg(msgnum);
408 display_vnote_div(v);
410 /* uncomment these lines to see ugly debugging info
411 wprintf("<script type=\"text/javascript\">");
412 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
413 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
414 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
415 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
416 wprintf("</script>");