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=\"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>");
62 wprintf("<td bgcolor=\"%s\"> </td>", pastel_palette[i]);
63 if (((i+1)%3)==0) wprintf("</tr>");
70 wprintf("<td></td>"); // nothing in the title bar, it's just for resizing
72 wprintf("<td align=right valign=middle>");
73 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
74 wprintf("src=\"static/closewindow.gif\">");
75 wprintf("</td></tr></table>");
81 wprintf("<div id=\"notebody-%s\" ", v->uid);
82 wprintf("class=\"stickynote_body\"");
87 wprintf("<script type=\"text/javascript\">");
88 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
89 "{rows:%d,cols:%d,highlightcolor:'#%02X%02X%02X',highlightendcolor:'#%02X%02X%02X',"
90 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
93 (v->pos_height / 16) - 5,
94 (v->pos_width / 9) - 1,
95 v->color_red, v->color_green, v->color_blue,
96 v->color_red, v->color_green, v->color_blue,
99 _("Click on any note to edit it.")
101 wprintf("</script>\n");
103 /* begin resize handle */
105 wprintf("<div id=\"resize-%s\" ", v->uid);
106 wprintf("class=\"stickynote_resize\" ");
107 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
110 wprintf("<img src=\"static/resizecorner.png\">");
122 * Fetch a message from the server and extract a vNote from it
124 struct vnote *vnote_new_from_msg(long msgnum) {
126 char mime_partnum[256];
127 char mime_filename[256];
128 char mime_content_type[256];
129 char mime_disposition[256];
131 char relevant_partnum[256];
132 char *relevant_source = NULL;
133 char uid_from_headers[256];
135 int body_line_len = 0;
137 struct vnote *vnote_from_body = NULL;
139 relevant_partnum[0] = 0;
140 uid_from_headers[0] = 0;
141 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
143 serv_getln(buf, sizeof buf);
144 if (buf[0] != '1') return NULL;
146 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
147 if (!strncasecmp(buf, "exti=", 5)) {
148 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
150 else if (!strncasecmp(buf, "part=", 5)) {
151 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
152 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
153 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
154 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
155 mime_length = extract_int(&buf[5], 5);
157 if (!strcasecmp(mime_content_type, "text/vnote")) {
158 strcpy(relevant_partnum, mime_partnum);
161 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
162 // Convert an old-style note to a vNote
163 if (!vnote_from_body) {
164 vnote_from_body = vnote_new();
165 vnote_from_body->uid = strdup(uid_from_headers);
166 vnote_from_body->color_red = 0xFF;
167 vnote_from_body->color_green = 0xff; // pastel yellow
168 vnote_from_body->color_blue = 0x80;
169 vnote_from_body->body = malloc(32768);
170 vnote_from_body->body[0] = 0;
173 body_line_len = strlen(buf);
174 if ((body_len + body_line_len + 10) < 32768) {
175 strcpy(&vnote_from_body->body[body_len++], " ");
176 strcpy(&vnote_from_body->body[body_len], buf);
177 body_len += body_line_len;
180 else if (IsEmptyStr(buf)) {
185 if (!IsEmptyStr(relevant_partnum)) {
186 relevant_source = load_mimepart(msgnum, relevant_partnum);
187 if (relevant_source != NULL) {
188 struct vnote *v = vnote_new_from_str(relevant_source);
189 free(relevant_source);
194 if (vnote_from_body) {
195 return(vnote_from_body);
202 * Serialize a vnote and write it to the server
204 void write_vnote_to_server(struct vnote *v)
208 serv_puts("ENT0 1|||4");
209 serv_getln(buf, sizeof buf);
211 serv_puts("Content-type: text/vnote");
213 serv_puts(vnote_serialize(v));
222 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
224 void ajax_update_note(void) {
228 struct vnote *v = NULL;
230 if (!havebstr("note_uid")) {
231 begin_ajax_response();
232 wprintf("Received ajax_update_note() request without a note UID.");
237 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
238 serv_printf("EUID %s", bstr("note_uid"));
239 serv_getln(buf, sizeof buf);
241 begin_ajax_response();
242 wprintf("Cannot find message containing vNote with the requested uid!");
246 msgnum = atol(&buf[4]);
247 lprintf(9, "Note msg = %ld\n", msgnum);
249 // Was this request a delete operation? If so, nuke it...
250 if (havebstr("deletenote")) {
251 if (!strcasecmp(bstr("deletenote"), "yes")) {
252 serv_printf("DELE %ld", msgnum);
253 serv_getln(buf, sizeof buf);
254 begin_ajax_response();
261 // If we get to this point it's an update, not a delete
262 v = vnote_new_from_msg(msgnum);
264 begin_ajax_response();
265 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
270 /* Make any requested changes */
271 if (havebstr("top")) {
272 v->pos_top = atoi(bstr("top"));
274 if (havebstr("left")) {
275 v->pos_left = atoi(bstr("left"));
277 if (havebstr("height")) {
278 v->pos_height = atoi(bstr("height"));
280 if (havebstr("width")) {
281 v->pos_width = atoi(bstr("width"));
283 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
284 if (v->body) free(v->body);
285 v->body = strdup(bstr("value"));
288 /* Serialize it and save it to the message base. Server will delete the old one. */
289 write_vnote_to_server(v);
291 begin_ajax_response();
304 * display sticky notes
306 * msgnum = Message number on the local server of the note to be displayed
308 void display_note(long msgnum, int unread) {
311 v = vnote_new_from_msg(msgnum);
313 display_vnote_div(v);
315 /* uncomment these lines to see ugly debugging info
316 wprintf("<script type=\"text/javascript\">");
317 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
318 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
319 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
320 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
321 wprintf("</script>");
333 void add_new_note(void) {
338 v->uid = malloc(128);
339 generate_uuid(v->uid);
341 v->color_green = 0xff; // pastel yellow
342 v->color_blue = 0x80;
343 v->body = strdup(_("Click on any note to edit it."));
344 write_vnote_to_server(v);