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>");
37 wprintf("<td></td>"); // nothing in the title bar, it's just for dragging
39 wprintf("<td align=right valign=middle>");
40 wprintf("<img onclick=\"DeleteStickyNote(event,'%s','%s')\" ", v->uid, _("Delete this note?") );
41 wprintf("src=\"static/closewindow.gif\">");
42 wprintf("</td></tr></table>");
48 wprintf("<div id=\"notebody-%s\" ", v->uid);
49 wprintf("class=\"stickynote_body\"");
54 wprintf("<script type=\"text/javascript\">");
55 wprintf(" new Ajax.InPlaceEditor('notebody-%s', 'ajax_update_note?note_uid=%s', "
56 "{rows:%d,cols:%d,highlightcolor:'#%02X%02X%02X',highlightendcolor:'#%02X%02X%02X',"
57 "okText:'%s',cancelText:'%s',clickToEditText:'%s'});",
60 (v->pos_height / 16) - 5,
61 (v->pos_width / 9) - 1,
62 v->color_red, v->color_green, v->color_blue,
63 v->color_red, v->color_green, v->color_blue,
66 _("Click on any note to edit it.")
68 wprintf("</script>\n");
70 /* begin resize handle */
72 wprintf("<div id=\"resize-%s\" ", v->uid);
73 wprintf("class=\"stickynote_resize\" ");
74 wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\"", v->uid);
77 wprintf("<img src=\"static/resizecorner.png\">");
89 * Fetch a message from the server and extract a vNote from it
91 struct vnote *vnote_new_from_msg(long msgnum) {
93 char mime_partnum[256];
94 char mime_filename[256];
95 char mime_content_type[256];
96 char mime_disposition[256];
98 char relevant_partnum[256];
99 char *relevant_source = NULL;
100 char uid_from_headers[256];
102 int body_line_len = 0;
104 struct vnote *vnote_from_body = NULL;
106 relevant_partnum[0] = 0;
107 uid_from_headers[0] = 0;
108 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
110 serv_getln(buf, sizeof buf);
111 if (buf[0] != '1') return NULL;
113 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
114 if (!strncasecmp(buf, "exti=", 5)) {
115 safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
117 else if (!strncasecmp(buf, "part=", 5)) {
118 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
119 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
120 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
121 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
122 mime_length = extract_int(&buf[5], 5);
124 if (!strcasecmp(mime_content_type, "text/vnote")) {
125 strcpy(relevant_partnum, mime_partnum);
128 else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
129 // Convert an old-style note to a vNote
130 if (!vnote_from_body) {
131 vnote_from_body = vnote_new();
132 vnote_from_body->uid = strdup(uid_from_headers);
133 vnote_from_body->body = malloc(32768);
134 vnote_from_body->body[0] = 0;
137 body_line_len = strlen(buf);
138 if ((body_len + body_line_len + 10) < 32768) {
139 strcpy(&vnote_from_body->body[body_len++], " ");
140 strcpy(&vnote_from_body->body[body_len], buf);
141 body_len += body_line_len;
144 else if (IsEmptyStr(buf)) {
149 if (!IsEmptyStr(relevant_partnum)) {
150 relevant_source = load_mimepart(msgnum, relevant_partnum);
151 if (relevant_source != NULL) {
152 struct vnote *v = vnote_new_from_str(relevant_source);
153 free(relevant_source);
158 if (vnote_from_body) {
159 return(vnote_from_body);
166 * Serialize a vnote and write it to the server
168 void write_vnote_to_server(struct vnote *v)
172 serv_puts("ENT0 1|||4");
173 serv_getln(buf, sizeof buf);
175 serv_puts("Content-type: text/vnote");
177 serv_puts(vnote_serialize(v));
186 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
188 void ajax_update_note(void) {
192 struct vnote *v = NULL;
194 if (!havebstr("note_uid")) {
195 begin_ajax_response();
196 wprintf("Received ajax_update_note() request without a note UID.");
201 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
202 serv_printf("EUID %s", bstr("note_uid"));
203 serv_getln(buf, sizeof buf);
205 begin_ajax_response();
206 wprintf("Cannot find message containing vNote with the requested uid!");
210 msgnum = atol(&buf[4]);
212 // Was this request a delete operation? If so, nuke it...
213 if (havebstr("deletenote")) {
214 if (!strcasecmp(bstr("deletenote"), "yes")) {
215 serv_printf("DELE %ld", msgnum);
216 serv_getln(buf, sizeof buf);
217 begin_ajax_response();
224 // If we get to this point it's an update, not a delete
225 v = vnote_new_from_msg(msgnum);
227 begin_ajax_response();
228 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
233 /* Make any requested changes */
234 if (havebstr("top")) {
235 v->pos_top = atoi(bstr("top"));
237 if (havebstr("left")) {
238 v->pos_left = atoi(bstr("left"));
240 if (havebstr("height")) {
241 v->pos_height = atoi(bstr("height"));
243 if (havebstr("width")) {
244 v->pos_width = atoi(bstr("width"));
246 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
247 if (v->body) free(v->body);
248 v->body = strdup(bstr("value"));
251 /* Serialize it and save it to the message base. Server will delete the old one. */
252 write_vnote_to_server(v);
254 begin_ajax_response();
267 * display sticky notes
269 * msgnum = Message number on the local server of the note to be displayed
271 void display_note(long msgnum, int unread) {
274 v = vnote_new_from_msg(msgnum);
276 display_vnote_div(v);
278 /* uncomment these lines to see ugly debugging info
279 wprintf("<script type=\"text/javascript\">");
280 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
281 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
282 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
283 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
284 wprintf("</script>");
296 void add_new_note(void) {
301 v->uid = malloc(128);
302 generate_uuid(v->uid);
303 v->body = strdup(_("Click on any note to edit it."));
304 write_vnote_to_server(v);