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 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
168 void ajax_update_note(void) {
172 struct vnote *v = NULL;
174 if (!havebstr("note_uid")) {
175 begin_ajax_response();
176 wprintf("Received ajax_update_note() request without a note UID.");
181 lprintf(9, "Note UID = %s\n", bstr("note_uid"));
182 serv_printf("EUID %s", bstr("note_uid"));
183 serv_getln(buf, sizeof buf);
185 begin_ajax_response();
186 wprintf("Cannot find message containing vNote with the requested uid!");
190 msgnum = atol(&buf[4]);
192 // Was this request a delete operation? If so, nuke it...
193 if (havebstr("deletenote")) {
194 if (!strcasecmp(bstr("deletenote"), "yes")) {
195 serv_printf("DELE %ld", msgnum);
196 serv_getln(buf, sizeof buf);
197 begin_ajax_response();
204 // If we get to this point it's an update, not a delete
205 v = vnote_new_from_msg(msgnum);
207 begin_ajax_response();
208 wprintf("Cannot locate a vNote within message %ld\n", msgnum);
213 /* Make any requested changes */
214 if (havebstr("top")) {
215 v->pos_top = atoi(bstr("top"));
217 if (havebstr("left")) {
218 v->pos_left = atoi(bstr("left"));
220 if (havebstr("height")) {
221 v->pos_height = atoi(bstr("height"));
223 if (havebstr("width")) {
224 v->pos_width = atoi(bstr("width"));
226 if (havebstr("value")) { // I would have preferred 'body' but InPlaceEditor hardcodes 'value'
227 if (v->body) free(v->body);
228 v->body = strdup(bstr("value"));
231 /* Serialize it and save it to the message base. Server will delete the old one. */
232 serv_puts("ENT0 1|||4");
233 serv_getln(buf, sizeof buf);
235 serv_puts("Content-type: text/vnote");
237 serv_puts(vnote_serialize(v));
241 begin_ajax_response();
254 * display sticky notes
256 * msgnum = Message number on the local server of the note to be displayed
258 void display_note(long msgnum, int unread) {
261 v = vnote_new_from_msg(msgnum);
263 display_vnote_div(v);
265 /* uncomment these lines to see ugly debugging info
266 wprintf("<script type=\"text/javascript\">");
267 wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
268 wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
269 wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
270 wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
271 wprintf("</script>");