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,'#%02x%02x%02x','#%02x%02x%02x')\" ",
65 pastel_palette[i][0], // color values to pass to ajax call
68 pastel_palette[i][0], // new color of note
71 pastel_palette[i][0] / 2, // new color of title bar
72 pastel_palette[i][1] / 2,
73 pastel_palette[i][2] / 2
75 wprintf("bgcolor=\"#%02x%02x%02x\"> </td>",
80 if (((i+1)%3)==0) wprintf("</tr>");
87 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
89 wprintf("<td align=right valign=middle>");
90 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
91 wprintf("src=\"static/closewindow.gif\">");
92 wprintf("</td></tr></table>");
98 wprintf("<div id=\"notebody-%s\" ", v->uid);
99 wprintf("class=\"stickynote_body\"");
104 wprintf("<script type=\"text/javascript\">");
105 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
106 "{rows:%d,cols:%d,onEnterHover:false,onLeaveHover:false,"
107 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
110 (v->pos_height / 16) - 5,
111 (v->pos_width / 9) - 1,
114 _("Click on any note to edit it.")
116 wprintf("</script>\n");
118 /* begin resize handle */
120 wprintf("<div id=\"resize-%s\" ", v->uid);
121 wprintf("class=\"stickynote_resize\" ");
122 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
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("red")) {
295 v->color_red = atoi(bstr("red"));
297 if (havebstr("green")) {
298 v->color_green = atoi(bstr("green"));
300 if (havebstr("blue")) {
301 v->color_blue = atoi(bstr("blue"));
303 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
304 if (v->body) free(v->body);
305 v->body = strdup(bstr("value"));
308 /* Serialize it and save it to the message base. Server will delete the old one. */
309 write_vnote_to_server(v);
311 begin_ajax_response();
324 * display sticky notes
326 * msgnum = Message number on the local server of the note to be displayed
328 void display_note(long msgnum, int unread) {
331 v = vnote_new_from_msg(msgnum);
333 display_vnote_div(v);
335 /* uncomment these lines to see ugly debugging info
336 wprintf("<script type=\"text/javascript\">");
337 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
338 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
339 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
340 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
341 wprintf("</script>");
353 void add_new_note(void) {
358 v->uid = malloc(128);
359 generate_uuid(v->uid);
360 v->color_red = pastel_palette[3][0];
361 v->color_green = pastel_palette[3][1];
362 v->color_blue = pastel_palette[3][2];
363 v->body = strdup(_("Click on any note to edit it."));
364 write_vnote_to_server(v);