10 int pastel_palette[9][3] = {
24 * Display a <div> containing a rendered sticky note.
26 void display_vnote_div(struct vnote *v) {
30 wprintf("<div id=\"note-%s\" ", v->uid); // begin outer div
31 wprintf("class=\"stickynote_outer\" ");
33 wprintf("left: %dpx; ", v->pos_left);
34 wprintf("top: %dpx; ", v->pos_top);
35 wprintf("width: %dpx; ", v->pos_width);
36 wprintf("height: %dpx; ", v->pos_height);
37 wprintf("background-color: #%02X%02X%02X ", v->color_red, v->color_green, v->color_blue);
44 wprintf("<div id=\"titlebar-%s\" ", v->uid); // begin title bar div
45 wprintf("class=\"stickynote_titlebar\" ");
46 wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
48 wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2);
51 wprintf("<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>");
53 wprintf("<td align=left valign=middle>");
54 wprintf("<img onclick=\"NotesClickPalette(event,'%s')\" ", v->uid);
55 wprintf("src=\"static/8paint16.gif\">");
57 /* embed color selector */
58 wprintf("<div id=\"palette-%s\" ", v->uid); // begin stickynote_palette div
59 wprintf("class=\"stickynote_palette\">");
61 wprintf("<table border=0 cellpadding=0 cellspacing=0>");
63 if ((i%3)==0) wprintf("<tr>");
65 wprintf("onClick=\"NotesClickColor(event,'%s',%d,%d,%d,'#%02x%02x%02x','#%02x%02x%02x')\" ",
67 pastel_palette[i][0], // color values to pass to ajax call
70 pastel_palette[i][0], // new color of note
73 pastel_palette[i][0] / 2, // new color of title bar
74 pastel_palette[i][1] / 2,
75 pastel_palette[i][2] / 2
77 wprintf("bgcolor=\"#%02x%02x%02x\"> </td>",
82 if (((i+1)%3)==0) wprintf("</tr>");
86 wprintf("</div>"); // end stickynote_palette div
90 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
92 wprintf("<td align=right valign=middle>");
93 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
94 wprintf("src=\"static/closewindow.gif\">");
95 wprintf("</td></tr></table>");
97 wprintf("</div>\n"); // end title bar div
103 wprintf("<div id=\"notebody-%s\" ", v->uid); // begin body div
104 wprintf("class=\"stickynote_body\"");
107 wprintf("</div>\n"); // end body div
109 wprintf("<script type=\"text/javascript\">");
110 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
111 "{rows:%d,cols:%d,onEnterHover:false,onLeaveHover:false,"
112 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
115 (v->pos_height / 16) - 5,
116 (v->pos_width / 9) - 1,
119 _("Click on any note to edit it.")
121 wprintf("</script>\n");
125 wprintf("<div id=\"resize-%s\" ", v->uid); // begin resize handle div
126 wprintf("class=\"stickynote_resize\" ");
127 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
128 wprintf("> </div>"); // end resize handle div
132 wprintf("</div>\n"); // end outer div
138 * Fetch a message from the server and extract a vNote from it
140 struct vnote *vnote_new_from_msg(long msgnum) {
142 char mime_partnum[256];
143 char mime_filename[256];
144 char mime_content_type[256];
145 char mime_disposition[256];
147 char relevant_partnum[256];
148 char *relevant_source = NULL;
149 char uid_from_headers[256];
151 int body_line_len = 0;
153 struct vnote *vnote_from_body = NULL;
155 relevant_partnum[0] = 0;
156 uid_from_headers[0] = 0;
157 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
159 serv_getln(buf, sizeof buf);
160 if (buf[0] != '1') return NULL;
162 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
163 if (!strncasecmp(buf, "exti=", 5)) {
164 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
166 else if (!strncasecmp(buf, "part=", 5)) {
167 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
168 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
169 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
170 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
171 mime_length = extract_int(&buf[5], 5);
173 if (!strcasecmp(mime_content_type, "text/vnote")) {
174 strcpy(relevant_partnum, mime_partnum);
177 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
178 // Convert an old-style note to a vNote
179 if (!vnote_from_body) {
180 vnote_from_body = vnote_new();
181 vnote_from_body->uid = strdup(uid_from_headers);
182 vnote_from_body->color_red = pastel_palette[3][0];
183 vnote_from_body->color_green = pastel_palette[3][1];
184 vnote_from_body->color_blue = pastel_palette[3][2];
185 vnote_from_body->body = malloc(32768);
186 vnote_from_body->body[0] = 0;
189 body_line_len = strlen(buf);
190 if ((body_len + body_line_len + 10) < 32768) {
191 strcpy(&vnote_from_body->body[body_len++], " ");
192 strcpy(&vnote_from_body->body[body_len], buf);
193 body_len += body_line_len;
196 else if (IsEmptyStr(buf)) {
201 if (!IsEmptyStr(relevant_partnum)) {
202 relevant_source = load_mimepart(msgnum, relevant_partnum);
203 if (relevant_source != NULL) {
204 struct vnote *v = vnote_new_from_str(relevant_source);
205 free(relevant_source);
210 if (vnote_from_body) {
211 return(vnote_from_body);
218 * Serialize a vnote and write it to the server
220 void write_vnote_to_server(struct vnote *v)
224 serv_puts("ENT0 1|||4");
225 serv_getln(buf, sizeof buf);
227 serv_puts("Content-type: text/vnote");
229 serv_puts(vnote_serialize(v));
238 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
240 void ajax_update_note(void) {
244 struct vnote *v = NULL;
246 if (!havebstr("note_uid")) {
247 begin_ajax_response();
248 wprintf("Received ajax_update_note() request without a note UID.");
253 // lprintf(9, "Note UID = %s\n", bstr("note_uid"));
254 serv_printf("EUID %s", bstr("note_uid"));
255 serv_getln(buf, sizeof buf);
257 begin_ajax_response();
258 wprintf("Cannot find message containing vNote with the requested uid!");
262 msgnum = atol(&buf[4]);
263 // lprintf(9, "Note msg = %ld\n", msgnum);
265 // Was this request a delete operation? If so, nuke it...
266 if (havebstr("deletenote")) {
267 if (!strcasecmp(bstr("deletenote"), "yes")) {
268 serv_printf("DELE %ld", msgnum);
269 serv_getln(buf, sizeof buf);
270 begin_ajax_response();
277 // If we get to this point it's an update, not a delete
278 v = vnote_new_from_msg(msgnum);
280 begin_ajax_response();
281 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
286 /* Make any requested changes */
287 if (havebstr("top")) {
288 v->pos_top = atoi(bstr("top"));
290 if (havebstr("left")) {
291 v->pos_left = atoi(bstr("left"));
293 if (havebstr("height")) {
294 v->pos_height = atoi(bstr("height"));
296 if (havebstr("width")) {
297 v->pos_width = atoi(bstr("width"));
299 if (havebstr("red")) {
300 v->color_red = atoi(bstr("red"));
302 if (havebstr("green")) {
303 v->color_green = atoi(bstr("green"));
305 if (havebstr("blue")) {
306 v->color_blue = atoi(bstr("blue"));
308 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
309 if (v->body) free(v->body);
310 v->body = strdup(bstr("value"));
313 /* Serialize it and save it to the message base. Server will delete the old one. */
314 write_vnote_to_server(v);
316 begin_ajax_response();
329 * display sticky notes
331 * msgnum = Message number on the local server of the note to be displayed
333 void display_note(long msgnum, int unread) {
336 v = vnote_new_from_msg(msgnum);
338 display_vnote_div(v);
340 /* uncomment these lines to see ugly debugging info
341 wprintf("<script type=\"text/javascript\">");
342 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
343 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
344 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
345 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
346 wprintf("</script>");
358 void add_new_note(void) {
363 v->uid = malloc(128);
364 generate_uuid(v->uid);
365 v->color_red = pastel_palette[3][0];
366 v->color_green = pastel_palette[3][1];
367 v->color_blue = pastel_palette[3][2];
368 v->body = strdup(_("Click on any note to edit it."));
369 write_vnote_to_server(v);