10 char *pastel_palette[] = {
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=\"$('palette-%s').style.display = 'block';\" ", 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("style=\"display:none;\" >");
60 wprintf("<table border=0 cellpadding=0 cellspacing=0>");
62 if ((i%3)==0) wprintf("<tr>");
63 wprintf("<td bgcolor=\"%s\"> </td>", pastel_palette[i]);
64 if (((i+1)%3)==0) wprintf("</tr>");
71 wprintf("<td></td>"); // nothing in the title bar, it's just for resizing
73 wprintf("<td align=right valign=middle>");
74 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
75 wprintf("src=\"static/closewindow.gif\">");
76 wprintf("</td></tr></table>");
82 wprintf("<div id=\"notebody-%s\" ", v->uid);
83 wprintf("class=\"stickynote_body\"");
88 wprintf("<script type=\"text/javascript\">");
89 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
90 "{rows:%d,cols:%d,highlightcolor:'#%02X%02X%02X',highlightendcolor:'#%02X%02X%02X',"
91 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
94 (v->pos_height / 16) - 5,
95 (v->pos_width / 9) - 1,
96 v->color_red, v->color_green, v->color_blue,
97 v->color_red, v->color_green, v->color_blue,
100 _("Click on any note to edit it.")
102 wprintf("</script>\n");
104 /* begin resize handle */
106 wprintf("<div id=\"resize-%s\" ", v->uid);
107 wprintf("class=\"stickynote_resize\" ");
108 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
111 wprintf("<img src=\"static/resizecorner.png\">");
123 * Fetch a message from the server and extract a vNote from it
125 struct vnote *vnote_new_from_msg(long msgnum) {
127 char mime_partnum[256];
128 char mime_filename[256];
129 char mime_content_type[256];
130 char mime_disposition[256];
132 char relevant_partnum[256];
133 char *relevant_source = NULL;
134 char uid_from_headers[256];
136 int body_line_len = 0;
138 struct vnote *vnote_from_body = NULL;
140 relevant_partnum[0] = 0;
141 uid_from_headers[0] = 0;
142 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
144 serv_getln(buf, sizeof buf);
145 if (buf[0] != '1') return NULL;
147 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
148 if (!strncasecmp(buf, "exti=", 5)) {
149 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
151 else if (!strncasecmp(buf, "part=", 5)) {
152 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
153 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
154 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
155 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
156 mime_length = extract_int(&buf[5], 5);
158 if (!strcasecmp(mime_content_type, "text/vnote")) {
159 strcpy(relevant_partnum, mime_partnum);
162 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
163 // Convert an old-style note to a vNote
164 if (!vnote_from_body) {
165 vnote_from_body = vnote_new();
166 vnote_from_body->uid = strdup(uid_from_headers);
167 vnote_from_body->body = malloc(32768);
168 vnote_from_body->body[0] = 0;
171 body_line_len = strlen(buf);
172 if ((body_len + body_line_len + 10) < 32768) {
173 strcpy(&vnote_from_body->body[body_len++], " ");
174 strcpy(&vnote_from_body->body[body_len], buf);
175 body_len += body_line_len;
178 else if (IsEmptyStr(buf)) {
183 if (!IsEmptyStr(relevant_partnum)) {
184 relevant_source = load_mimepart(msgnum, relevant_partnum);
185 if (relevant_source != NULL) {
186 struct vnote *v = vnote_new_from_str(relevant_source);
187 free(relevant_source);
192 if (vnote_from_body) {
193 return(vnote_from_body);
200 * Serialize a vnote and write it to the server
202 void write_vnote_to_server(struct vnote *v)
206 serv_puts("ENT0 1|||4");
207 serv_getln(buf, sizeof buf);
209 serv_puts("Content-type: text/vnote");
211 serv_puts(vnote_serialize(v));
220 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
222 void ajax_update_note(void) {
226 struct vnote *v = NULL;
228 if (!havebstr("note_uid")) {
229 begin_ajax_response();
230 wprintf("Received ajax_update_note() request without a note UID.");
235 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
236 serv_printf("EUID %s", bstr("note_uid"));
237 serv_getln(buf, sizeof buf);
239 begin_ajax_response();
240 wprintf("Cannot find message containing vNote with the requested uid!");
244 msgnum = atol(&buf[4]);
245 lprintf(9, "Note msg = %ld\n", msgnum);
247 // Was this request a delete operation? If so, nuke it...
248 if (havebstr("deletenote")) {
249 if (!strcasecmp(bstr("deletenote"), "yes")) {
250 serv_printf("DELE %ld", msgnum);
251 serv_getln(buf, sizeof buf);
252 begin_ajax_response();
259 // If we get to this point it's an update, not a delete
260 v = vnote_new_from_msg(msgnum);
262 begin_ajax_response();
263 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
268 /* Make any requested changes */
269 if (havebstr("top")) {
270 v->pos_top = atoi(bstr("top"));
272 if (havebstr("left")) {
273 v->pos_left = atoi(bstr("left"));
275 if (havebstr("height")) {
276 v->pos_height = atoi(bstr("height"));
278 if (havebstr("width")) {
279 v->pos_width = atoi(bstr("width"));
281 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
282 if (v->body) free(v->body);
283 v->body = strdup(bstr("value"));
286 /* Serialize it and save it to the message base. Server will delete the old one. */
287 write_vnote_to_server(v);
289 begin_ajax_response();
302 * display sticky notes
304 * msgnum = Message number on the local server of the note to be displayed
306 void display_note(long msgnum, int unread) {
309 v = vnote_new_from_msg(msgnum);
311 display_vnote_div(v);
313 /* uncomment these lines to see ugly debugging info
314 wprintf("<script type=\"text/javascript\">");
315 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
316 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
317 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
318 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
319 wprintf("</script>");
331 void add_new_note(void) {
336 v->uid = malloc(128);
337 generate_uuid(v->uid);
338 v->body = strdup(_("Click on any note to edit it."));
339 write_vnote_to_server(v);