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)\" ",
69 wprintf("bgcolor=\"#%02x%02x%02x\"> </td>",
74 if (((i+1)%3)==0) wprintf("</tr>");
81 wprintf("<td></td>"); // nothing in the title bar, it's just for resizing
83 wprintf("<td align=right valign=middle>");
84 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
85 wprintf("src=\"static/closewindow.gif\">");
86 wprintf("</td></tr></table>");
92 wprintf("<div id=\"notebody-%s\" ", v->uid);
93 wprintf("class=\"stickynote_body\"");
98 wprintf("<script type=\"text/javascript\">");
99 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
100 "{rows:%d,cols:%d,highlightcolor:'#%02X%02X%02X',highlightendcolor:'#%02X%02X%02X',"
101 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
104 (v->pos_height / 16) - 5,
105 (v->pos_width / 9) - 1,
106 v->color_red, v->color_green, v->color_blue,
107 v->color_red, v->color_green, v->color_blue,
110 _("Click on any note to edit it.")
112 wprintf("</script>\n");
114 /* begin resize handle */
116 wprintf("<div id=\"resize-%s\" ", v->uid);
117 wprintf("class=\"stickynote_resize\" ");
118 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
121 wprintf("<img src=\"static/resizecorner.png\">");
133 * Fetch a message from the server and extract a vNote from it
135 struct vnote *vnote_new_from_msg(long msgnum) {
137 char mime_partnum[256];
138 char mime_filename[256];
139 char mime_content_type[256];
140 char mime_disposition[256];
142 char relevant_partnum[256];
143 char *relevant_source = NULL;
144 char uid_from_headers[256];
146 int body_line_len = 0;
148 struct vnote *vnote_from_body = NULL;
150 relevant_partnum[0] = 0;
151 uid_from_headers[0] = 0;
152 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
154 serv_getln(buf, sizeof buf);
155 if (buf[0] != '1') return NULL;
157 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
158 if (!strncasecmp(buf, "exti=", 5)) {
159 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
161 else if (!strncasecmp(buf, "part=", 5)) {
162 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
163 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
164 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
165 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
166 mime_length = extract_int(&buf[5], 5);
168 if (!strcasecmp(mime_content_type, "text/vnote")) {
169 strcpy(relevant_partnum, mime_partnum);
172 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
173 // Convert an old-style note to a vNote
174 if (!vnote_from_body) {
175 vnote_from_body = vnote_new();
176 vnote_from_body->uid = strdup(uid_from_headers);
177 vnote_from_body->color_red = pastel_palette[3][0];
178 vnote_from_body->color_green = pastel_palette[3][1];
179 vnote_from_body->color_blue = pastel_palette[3][2];
180 vnote_from_body->body = malloc(32768);
181 vnote_from_body->body[0] = 0;
184 body_line_len = strlen(buf);
185 if ((body_len + body_line_len + 10) < 32768) {
186 strcpy(&vnote_from_body->body[body_len++], " ");
187 strcpy(&vnote_from_body->body[body_len], buf);
188 body_len += body_line_len;
191 else if (IsEmptyStr(buf)) {
196 if (!IsEmptyStr(relevant_partnum)) {
197 relevant_source = load_mimepart(msgnum, relevant_partnum);
198 if (relevant_source != NULL) {
199 struct vnote *v = vnote_new_from_str(relevant_source);
200 free(relevant_source);
205 if (vnote_from_body) {
206 return(vnote_from_body);
213 * Serialize a vnote and write it to the server
215 void write_vnote_to_server(struct vnote *v)
219 serv_puts("ENT0 1|||4");
220 serv_getln(buf, sizeof buf);
222 serv_puts("Content-type: text/vnote");
224 serv_puts(vnote_serialize(v));
233 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
235 void ajax_update_note(void) {
239 struct vnote *v = NULL;
241 if (!havebstr("note_uid")) {
242 begin_ajax_response();
243 wprintf("Received ajax_update_note() request without a note UID.");
248 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
249 serv_printf("EUID %s", bstr("note_uid"));
250 serv_getln(buf, sizeof buf);
252 begin_ajax_response();
253 wprintf("Cannot find message containing vNote with the requested uid!");
257 msgnum = atol(&buf[4]);
258 lprintf(9, "Note msg = %ld\n", msgnum);
260 // Was this request a delete operation? If so, nuke it...
261 if (havebstr("deletenote")) {
262 if (!strcasecmp(bstr("deletenote"), "yes")) {
263 serv_printf("DELE %ld", msgnum);
264 serv_getln(buf, sizeof buf);
265 begin_ajax_response();
272 // If we get to this point it's an update, not a delete
273 v = vnote_new_from_msg(msgnum);
275 begin_ajax_response();
276 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
281 /* Make any requested changes */
282 if (havebstr("top")) {
283 v->pos_top = atoi(bstr("top"));
285 if (havebstr("left")) {
286 v->pos_left = atoi(bstr("left"));
288 if (havebstr("height")) {
289 v->pos_height = atoi(bstr("height"));
291 if (havebstr("width")) {
292 v->pos_width = atoi(bstr("width"));
294 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
295 if (v->body) free(v->body);
296 v->body = strdup(bstr("value"));
299 /* Serialize it and save it to the message base. Server will delete the old one. */
300 write_vnote_to_server(v);
302 begin_ajax_response();
315 * display sticky notes
317 * msgnum = Message number on the local server of the note to be displayed
319 void display_note(long msgnum, int unread) {
322 v = vnote_new_from_msg(msgnum);
324 display_vnote_div(v);
326 /* uncomment these lines to see ugly debugging info
327 wprintf("<script type=\"text/javascript\">");
328 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
329 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
330 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
331 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
332 wprintf("</script>");
344 void add_new_note(void) {
349 v->uid = malloc(128);
350 generate_uuid(v->uid);
351 v->color_red = pastel_palette[3][0];
352 v->color_green = pastel_palette[3][1];
353 v->color_blue = pastel_palette[3][2];
354 v->body = strdup(_("Click on any note to edit it."));
355 write_vnote_to_server(v);