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."));
163 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
165 void ajax_update_note(void) {
167 begin_ajax_response();
168 wprintf("Updating."); // Browser ignores the response, so nothing is necessary.
171 if (!havebstr("note_uid")) {
172 lprintf(5, "Received ajax_update_note() request without a note UID.\n");
176 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
177 if (havebstr("top")) lprintf(9, "Top = %s\n", bstr("top"));
178 if (havebstr("left")) lprintf(9, "Left = %s\n", bstr("left"));
179 if (havebstr("height")) lprintf(9, "Height = %s\n", bstr("height"));
180 if (havebstr("width")) lprintf(9, "Width = %s\n", bstr("width"));
182 /* FIXME finish this */
188 #ifdef NEW_NOTES_VIEW
191 * Display a <div> containing a rendered sticky note.
193 void display_vnote_div(struct vnote *v) {
195 /* begin outer div */
197 wprintf("<div id=\"note-%s\" ", v->uid);
198 wprintf("class=\"stickynote_outer\" ");
200 wprintf("left: %dpx; ", v->pos_left);
201 wprintf("top: %dpx; ", v->pos_top);
202 wprintf("width: %dpx; ", v->pos_width);
203 wprintf("height: %dpx; ", v->pos_height);
204 wprintf("background-color: #%02X%02X%02X ", v->color_red, v->color_green, v->color_blue);
207 /* begin title bar */
209 wprintf("<div id=\"titlebar-%s\" ", v->uid);
210 wprintf("class=\"stickynote_titlebar\" ");
211 wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
213 wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2);
216 wprintf("<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>");
217 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
219 wprintf("<td align=right valign=middle "
220 // "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
221 "><img src=\"static/closewindow.gif\">");
222 wprintf("</td></tr></table>");
235 * display sticky notes
237 * msgnum = Message number on the local server of the note to be displayed
239 void display_note(long msgnum, int unread) {
241 char mime_partnum[256];
242 char mime_filename[256];
243 char mime_content_type[256];
244 char mime_disposition[256];
246 char relevant_partnum[256];
247 char *relevant_source = NULL;
249 relevant_partnum[0] = '\0';
250 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
252 serv_getln(buf, sizeof buf);
253 if (buf[0] != '1') return;
255 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
256 if (!strncasecmp(buf, "part=", 5)) {
257 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
258 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
259 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
260 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
261 mime_length = extract_int(&buf[5], 5);
263 if (!strcasecmp(mime_content_type, "text/vnote")) {
264 strcpy(relevant_partnum, mime_partnum);
269 if (!IsEmptyStr(relevant_partnum)) {
270 relevant_source = load_mimepart(msgnum, relevant_partnum);
271 if (relevant_source != NULL) {
272 struct vnote *v = vnote_new_from_str(relevant_source);
273 free(relevant_source);
274 display_vnote_div(v);
276 /* uncomment these lines to see ugly debugging info
277 wprintf("<script type=\"text/javascript\">");
278 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
279 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
280 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
281 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
282 wprintf("</script>");