10 int pastel_palette[9][3] = {
24 * Display a <div> containing a rendered sticky note.
26 void display_vnote_div(struct vnote *v) {
31 wprintf("<div id=\"note-%s\" ", v->uid);
32 wprintf("class=\"stickynote_outer\" ");
34 wprintf("left: %dpx; ", v->pos_left);
35 wprintf("top: %dpx; ", v->pos_top);
36 wprintf("width: %dpx; ", v->pos_width);
37 wprintf("height: %dpx; ", v->pos_height);
38 wprintf("background-color: #%02X%02X%02X ", v->color_red, v->color_green, v->color_blue);
43 wprintf("<div id=\"titlebar-%s\" ", v->uid);
44 wprintf("class=\"stickynote_titlebar\" ");
45 wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
47 wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2);
50 wprintf("<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>");
52 wprintf("<td align=left valign=middle>");
53 wprintf("<img onclick=\"NotesClickPalette(event,'%s')\" ", v->uid);
54 wprintf("src=\"static/8paint16.gif\">");
56 /* embed color selector */
57 wprintf("<div id=\"palette-%s\" ", v->uid);
58 wprintf("class=\"stickynote_palette\" ");
59 wprintf("<table border=0 cellpadding=0 cellspacing=0>");
61 if ((i%3)==0) wprintf("<tr>");
63 wprintf("onClick=\"NotesClickColor(event,'%s',%d,%d,%d,'#%02x%02x%02x','#%02x%02x%02x')\" ",
65 pastel_palette[i][0], // color values to pass to ajax call
68 pastel_palette[i][0], // new color of note
71 pastel_palette[i][0] / 2, // new color of title bar
72 pastel_palette[i][1] / 2,
73 pastel_palette[i][2] / 2
75 wprintf("bgcolor=\"#%02x%02x%02x\"> </td>",
80 if (((i+1)%3)==0) wprintf("</tr>");
87 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
89 wprintf("<td align=right valign=middle>");
90 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
91 wprintf("src=\"static/closewindow.gif\">");
92 wprintf("</td></tr></table>");
98 wprintf("<div id=\"notebody-%s\" ", v->uid);
99 wprintf("class=\"stickynote_body\"");
104 wprintf("<script type=\"text/javascript\">");
105 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
107 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
110 (v->pos_height / 16) - 5,
111 (v->pos_width / 9) - 1,
114 _("Click on any note to edit it.")
116 wprintf("</script>\n");
118 /* begin resize handle */
120 wprintf("<div id=\"resize-%s\" ", v->uid);
121 wprintf("class=\"stickynote_resize\" ");
122 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
125 wprintf("<img src=\"static/resizecorner.png\">");
137 * Fetch a message from the server and extract a vNote from it
139 struct vnote *vnote_new_from_msg(long msgnum) {
141 char mime_partnum[256];
142 char mime_filename[256];
143 char mime_content_type[256];
144 char mime_disposition[256];
146 char relevant_partnum[256];
147 char *relevant_source = NULL;
148 char uid_from_headers[256];
150 int body_line_len = 0;
152 struct vnote *vnote_from_body = NULL;
154 relevant_partnum[0] = 0;
155 uid_from_headers[0] = 0;
156 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
158 serv_getln(buf, sizeof buf);
159 if (buf[0] != '1') return NULL;
161 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
162 if (!strncasecmp(buf, "exti=", 5)) {
163 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
165 else if (!strncasecmp(buf, "part=", 5)) {
166 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
167 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
168 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
169 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
170 mime_length = extract_int(&buf[5], 5);
172 if (!strcasecmp(mime_content_type, "text/vnote")) {
173 strcpy(relevant_partnum, mime_partnum);
176 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
177 // Convert an old-style note to a vNote
178 if (!vnote_from_body) {
179 vnote_from_body = vnote_new();
180 vnote_from_body->uid = strdup(uid_from_headers);
181 vnote_from_body->color_red = pastel_palette[3][0];
182 vnote_from_body->color_green = pastel_palette[3][1];
183 vnote_from_body->color_blue = pastel_palette[3][2];
184 vnote_from_body->body = malloc(32768);
185 vnote_from_body->body[0] = 0;
188 body_line_len = strlen(buf);
189 if ((body_len + body_line_len + 10) < 32768) {
190 strcpy(&vnote_from_body->body[body_len++], " ");
191 strcpy(&vnote_from_body->body[body_len], buf);
192 body_len += body_line_len;
195 else if (IsEmptyStr(buf)) {
200 if (!IsEmptyStr(relevant_partnum)) {
201 relevant_source = load_mimepart(msgnum, relevant_partnum);
202 if (relevant_source != NULL) {
203 struct vnote *v = vnote_new_from_str(relevant_source);
204 free(relevant_source);
209 if (vnote_from_body) {
210 return(vnote_from_body);
217 * Serialize a vnote and write it to the server
219 void write_vnote_to_server(struct vnote *v)
223 serv_puts("ENT0 1|||4");
224 serv_getln(buf, sizeof buf);
226 serv_puts("Content-type: text/vnote");
228 serv_puts(vnote_serialize(v));
237 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
239 void ajax_update_note(void) {
243 struct vnote *v = NULL;
245 if (!havebstr("note_uid")) {
246 begin_ajax_response();
247 wprintf("Received ajax_update_note() request without a note UID.");
252 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
253 serv_printf("EUID %s", bstr("note_uid"));
254 serv_getln(buf, sizeof buf);
256 begin_ajax_response();
257 wprintf("Cannot find message containing vNote with the requested uid!");
261 msgnum = atol(&buf[4]);
262 lprintf(9, "Note msg = %ld\n", msgnum);
264 // Was this request a delete operation? If so, nuke it...
265 if (havebstr("deletenote")) {
266 if (!strcasecmp(bstr("deletenote"), "yes")) {
267 serv_printf("DELE %ld", msgnum);
268 serv_getln(buf, sizeof buf);
269 begin_ajax_response();
276 // If we get to this point it's an update, not a delete
277 v = vnote_new_from_msg(msgnum);
279 begin_ajax_response();
280 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
285 /* Make any requested changes */
286 if (havebstr("top")) {
287 v->pos_top = atoi(bstr("top"));
289 if (havebstr("left")) {
290 v->pos_left = atoi(bstr("left"));
292 if (havebstr("height")) {
293 v->pos_height = atoi(bstr("height"));
295 if (havebstr("width")) {
296 v->pos_width = atoi(bstr("width"));
298 if (havebstr("red")) {
299 v->color_red = atoi(bstr("red"));
301 if (havebstr("green")) {
302 v->color_green = atoi(bstr("green"));
304 if (havebstr("blue")) {
305 v->color_blue = atoi(bstr("blue"));
307 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
308 if (v->body) free(v->body);
309 v->body = strdup(bstr("value"));
312 /* Serialize it and save it to the message base. Server will delete the old one. */
313 write_vnote_to_server(v);
315 begin_ajax_response();
328 * display sticky notes
330 * msgnum = Message number on the local server of the note to be displayed
332 void display_note(long msgnum, int unread) {
335 v = vnote_new_from_msg(msgnum);
337 display_vnote_div(v);
339 /* uncomment these lines to see ugly debugging info
340 wprintf("<script type=\"text/javascript\">");
341 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
342 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
343 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
344 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
345 wprintf("</script>");
357 void add_new_note(void) {
362 v->uid = malloc(128);
363 generate_uuid(v->uid);
364 v->color_red = pastel_palette[3][0];
365 v->color_green = pastel_palette[3][1];
366 v->color_blue = pastel_palette[3][2];
367 v->body = strdup(_("Click on any note to edit it."));
368 write_vnote_to_server(v);