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->color_red = 0xFF;
168 vnote_from_body->color_green = 0xFF; // pastel yellow
169 vnote_from_body->color_blue = 0xBF;
170 vnote_from_body->body = malloc(32768);
171 vnote_from_body->body[0] = 0;
174 body_line_len = strlen(buf);
175 if ((body_len + body_line_len + 10) < 32768) {
176 strcpy(&vnote_from_body->body[body_len++], " ");
177 strcpy(&vnote_from_body->body[body_len], buf);
178 body_len += body_line_len;
181 else if (IsEmptyStr(buf)) {
186 if (!IsEmptyStr(relevant_partnum)) {
187 relevant_source = load_mimepart(msgnum, relevant_partnum);
188 if (relevant_source != NULL) {
189 struct vnote *v = vnote_new_from_str(relevant_source);
190 free(relevant_source);
195 if (vnote_from_body) {
196 return(vnote_from_body);
203 * Serialize a vnote and write it to the server
205 void write_vnote_to_server(struct vnote *v)
209 serv_puts("ENT0 1|||4");
210 serv_getln(buf, sizeof buf);
212 serv_puts("Content-type: text/vnote");
214 serv_puts(vnote_serialize(v));
223 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
225 void ajax_update_note(void) {
229 struct vnote *v = NULL;
231 if (!havebstr("note_uid")) {
232 begin_ajax_response();
233 wprintf("Received ajax_update_note() request without a note UID.");
238 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
239 serv_printf("EUID %s", bstr("note_uid"));
240 serv_getln(buf, sizeof buf);
242 begin_ajax_response();
243 wprintf("Cannot find message containing vNote with the requested uid!");
247 msgnum = atol(&buf[4]);
248 lprintf(9, "Note msg = %ld\n", msgnum);
250 // Was this request a delete operation? If so, nuke it...
251 if (havebstr("deletenote")) {
252 if (!strcasecmp(bstr("deletenote"), "yes")) {
253 serv_printf("DELE %ld", msgnum);
254 serv_getln(buf, sizeof buf);
255 begin_ajax_response();
262 // If we get to this point it's an update, not a delete
263 v = vnote_new_from_msg(msgnum);
265 begin_ajax_response();
266 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
271 /* Make any requested changes */
272 if (havebstr("top")) {
273 v->pos_top = atoi(bstr("top"));
275 if (havebstr("left")) {
276 v->pos_left = atoi(bstr("left"));
278 if (havebstr("height")) {
279 v->pos_height = atoi(bstr("height"));
281 if (havebstr("width")) {
282 v->pos_width = atoi(bstr("width"));
284 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
285 if (v->body) free(v->body);
286 v->body = strdup(bstr("value"));
289 /* Serialize it and save it to the message base. Server will delete the old one. */
290 write_vnote_to_server(v);
292 begin_ajax_response();
305 * display sticky notes
307 * msgnum = Message number on the local server of the note to be displayed
309 void display_note(long msgnum, int unread) {
312 v = vnote_new_from_msg(msgnum);
314 display_vnote_div(v);
316 /* uncomment these lines to see ugly debugging info
317 wprintf("<script type=\"text/javascript\">");
318 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
319 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
320 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
321 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
322 wprintf("</script>");
334 void add_new_note(void) {
339 v->uid = malloc(128);
340 generate_uuid(v->uid);
342 v->color_green = 0xFF; // pastel yellow
343 v->color_blue = 0xBF;
344 v->body = strdup(_("Click on any note to edit it."));
345 write_vnote_to_server(v);