11 * Display a <div> containing a rendered sticky note.
13 void display_vnote_div(struct vnote *v) {
17 wprintf("<div id=\"note-%s\" ", v->uid);
18 wprintf("class=\"stickynote_outer\" ");
20 wprintf("left: %dpx; ", v->pos_left);
21 wprintf("top: %dpx; ", v->pos_top);
22 wprintf("width: %dpx; ", v->pos_width);
23 wprintf("height: %dpx; ", v->pos_height);
24 wprintf("background-color: #%02X%02X%02X ", v->color_red, v->color_green, v->color_blue);
29 wprintf("<div id=\"titlebar-%s\" ", v->uid);
30 wprintf("class=\"stickynote_titlebar\" ");
31 wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
33 wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2);
36 wprintf("<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>");
38 wprintf("<td align=left valign=middle>");
39 wprintf("<img onclick=\"alert('FIXME');\" ");
40 wprintf("src=\"static/8paint16.gif\">");
43 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
45 wprintf("<td align=right valign=middle>");
46 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
47 wprintf("src=\"static/closewindow.gif\">");
48 wprintf("</td></tr></table>");
54 wprintf("<div id=\"notebody-%s\" ", v->uid);
55 wprintf("class=\"stickynote_body\"");
60 wprintf("<script type=\"text/javascript\">");
61 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
62 "{rows:%d,cols:%d,highlightcolor:'#%02X%02X%02X',highlightendcolor:'#%02X%02X%02X',"
63 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
66 (v->pos_height / 16) - 5,
67 (v->pos_width / 9) - 1,
68 v->color_red, v->color_green, v->color_blue,
69 v->color_red, v->color_green, v->color_blue,
72 _("Click on any note to edit it.")
74 wprintf("</script>\n");
76 /* begin resize handle */
78 wprintf("<div id=\"resize-%s\" ", v->uid);
79 wprintf("class=\"stickynote_resize\" ");
80 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
83 wprintf("<img src=\"static/resizecorner.png\">");
95 * Fetch a message from the server and extract a vNote from it
97 struct vnote *vnote_new_from_msg(long msgnum) {
99 char mime_partnum[256];
100 char mime_filename[256];
101 char mime_content_type[256];
102 char mime_disposition[256];
104 char relevant_partnum[256];
105 char *relevant_source = NULL;
106 char uid_from_headers[256];
108 int body_line_len = 0;
110 struct vnote *vnote_from_body = NULL;
112 relevant_partnum[0] = 0;
113 uid_from_headers[0] = 0;
114 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
116 serv_getln(buf, sizeof buf);
117 if (buf[0] != '1') return NULL;
119 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
120 if (!strncasecmp(buf, "exti=", 5)) {
121 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
123 else if (!strncasecmp(buf, "part=", 5)) {
124 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
125 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
126 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
127 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
128 mime_length = extract_int(&buf[5], 5);
130 if (!strcasecmp(mime_content_type, "text/vnote")) {
131 strcpy(relevant_partnum, mime_partnum);
134 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
135 // Convert an old-style note to a vNote
136 if (!vnote_from_body) {
137 vnote_from_body = vnote_new();
138 vnote_from_body->uid = strdup(uid_from_headers);
139 vnote_from_body->body = malloc(32768);
140 vnote_from_body->body[0] = 0;
143 body_line_len = strlen(buf);
144 if ((body_len + body_line_len + 10) < 32768) {
145 strcpy(&vnote_from_body->body[body_len++], " ");
146 strcpy(&vnote_from_body->body[body_len], buf);
147 body_len += body_line_len;
150 else if (IsEmptyStr(buf)) {
155 if (!IsEmptyStr(relevant_partnum)) {
156 relevant_source = load_mimepart(msgnum, relevant_partnum);
157 if (relevant_source != NULL) {
158 struct vnote *v = vnote_new_from_str(relevant_source);
159 free(relevant_source);
164 if (vnote_from_body) {
165 return(vnote_from_body);
172 * Serialize a vnote and write it to the server
174 void write_vnote_to_server(struct vnote *v)
178 serv_puts("ENT0 1|||4");
179 serv_getln(buf, sizeof buf);
181 serv_puts("Content-type: text/vnote");
183 serv_puts(vnote_serialize(v));
192 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
194 void ajax_update_note(void) {
198 struct vnote *v = NULL;
200 if (!havebstr("note_uid")) {
201 begin_ajax_response();
202 wprintf("Received ajax_update_note() request without a note UID.");
207 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
208 serv_printf("EUID %s", bstr("note_uid"));
209 serv_getln(buf, sizeof buf);
211 begin_ajax_response();
212 wprintf("Cannot find message containing vNote with the requested uid!");
216 msgnum = atol(&buf[4]);
217 lprintf(9, "Note msg = %ld\n", msgnum);
219 // Was this request a delete operation? If so, nuke it...
220 if (havebstr("deletenote")) {
221 if (!strcasecmp(bstr("deletenote"), "yes")) {
222 serv_printf("DELE %ld", msgnum);
223 serv_getln(buf, sizeof buf);
224 begin_ajax_response();
231 // If we get to this point it's an update, not a delete
232 v = vnote_new_from_msg(msgnum);
234 begin_ajax_response();
235 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
240 /* Make any requested changes */
241 if (havebstr("top")) {
242 v->pos_top = atoi(bstr("top"));
244 if (havebstr("left")) {
245 v->pos_left = atoi(bstr("left"));
247 if (havebstr("height")) {
248 v->pos_height = atoi(bstr("height"));
250 if (havebstr("width")) {
251 v->pos_width = atoi(bstr("width"));
253 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
254 if (v->body) free(v->body);
255 v->body = strdup(bstr("value"));
258 /* Serialize it and save it to the message base. Server will delete the old one. */
259 write_vnote_to_server(v);
261 begin_ajax_response();
274 * display sticky notes
276 * msgnum = Message number on the local server of the note to be displayed
278 void display_note(long msgnum, int unread) {
281 v = vnote_new_from_msg(msgnum);
283 display_vnote_div(v);
285 /* uncomment these lines to see ugly debugging info
286 wprintf("<script type=\"text/javascript\">");
287 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
288 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
289 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
290 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
291 wprintf("</script>");
303 void add_new_note(void) {
308 v->uid = malloc(128);
309 generate_uuid(v->uid);
310 v->body = strdup(_("Click on any note to edit it."));
311 write_vnote_to_server(v);