From 9cb08bddc827e0edb9550faa57643c560136399b Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 29 Apr 2008 21:56:11 +0000 Subject: [PATCH] Sticky notes can now be moved and resized by dragging and their size/position are now updated on the server. --- webcit/notes.c | 163 +++++++++++++++++++++++---------- webcit/static/resizecorner.png | Bin 0 -> 530 bytes webcit/static/wclib.js | 84 +++++++++++++++++ webcit/static/webcit.css | 6 ++ 4 files changed, 207 insertions(+), 46 deletions(-) create mode 100644 webcit/static/resizecorner.png diff --git a/webcit/notes.c b/webcit/notes.c index 24f3c5de0..81cc8b9fa 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -159,34 +159,6 @@ void updatenote(void) } -/* - * Background ajax call to receive updates from the browser when a note is moved, resized, or updated. - */ -void ajax_update_note(void) { - - begin_ajax_response(); - wprintf("Updating."); // Browser ignores the response, so nothing is necessary. - end_ajax_response(); - - if (!havebstr("note_uid")) { - lprintf(5, "Received ajax_update_note() request without a note UID.\n"); - return; - } - - lprintf(9, "Note UID = %s\n", bstr("note_uid")); - if (havebstr("top")) lprintf(9, "Top = %s\n", bstr("top")); - if (havebstr("left")) lprintf(9, "Left = %s\n", bstr("left")); - if (havebstr("height")) lprintf(9, "Height = %s\n", bstr("height")); - if (havebstr("width")) lprintf(9, "Width = %s\n", bstr("width")); - - /* FIXME finish this */ -} - - - - -#ifdef NEW_NOTES_VIEW - /* * Display a
containing a rendered sticky note. */ @@ -223,20 +195,33 @@ void display_vnote_div(struct vnote *v) { wprintf("
\n"); + /* begin note body */ + escputs(v->body); + /* begin resize handle */ + + wprintf("
uid); + wprintf("class=\"stickynote_resize\" "); + wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\" ", v->uid); + wprintf("style=\""); + wprintf("\">"); + + wprintf(""); + wprintf("
\n"); -} + /* end of note */ + + wprintf("\n"); +} /* - * display sticky notes - * - * msgnum = Message number on the local server of the note to be displayed + * Fetch a message from the server and extract a vNote from it */ -void display_note(long msgnum, int unread) { +struct vnote *vnote_new_from_msg(long msgnum) { char buf[1024]; char mime_partnum[256]; char mime_filename[256]; @@ -250,7 +235,7 @@ void display_note(long msgnum, int unread) { sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */ serv_puts(buf); serv_getln(buf, sizeof buf); - if (buf[0] != '1') return; + if (buf[0] != '1') return NULL; while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { if (!strncasecmp(buf, "part=", 5)) { @@ -271,20 +256,106 @@ void display_note(long msgnum, int unread) { if (relevant_source != NULL) { struct vnote *v = vnote_new_from_str(relevant_source); free(relevant_source); - display_vnote_div(v); - - /* uncomment these lines to see ugly debugging info - wprintf(""); - */ - - vnote_free(v); + return(v); } } + + return NULL; +} + + +/* + * Background ajax call to receive updates from the browser when a note is moved, resized, or updated. + */ +void ajax_update_note(void) { + + char buf[1024]; + int msgnum; + struct vnote *v = NULL; + + begin_ajax_response(); + wprintf("Updating."); // Browser ignores the response, so nothing is necessary. + end_ajax_response(); + + if (!havebstr("note_uid")) { + lprintf(5, "Received ajax_update_note() request without a note UID.\n"); + return; + } + + lprintf(9, "Note UID = %s\n", bstr("note_uid")); + serv_printf("EUID %s", bstr("note_uid")); + serv_getln(buf, sizeof buf); + if (buf[0] != '2') { + lprintf(5, "Cannot find message containing vNote with the requested uid!\n"); + return; + } + msgnum = atol(&buf[4]); + v = vnote_new_from_msg(msgnum); + if (!v) { + lprintf(5, "Cannot locate a vNote within message %ld\n", msgnum); + return; + } + + /* Make any requested changes */ + if (havebstr("top")) { + lprintf(9, "Top = %s\n", bstr("top")); + v->pos_top = atoi(bstr("top")); + } + if (havebstr("left")) { + lprintf(9, "Left = %s\n", bstr("left")); + v->pos_left = atoi(bstr("left")); + } + if (havebstr("height")) { + lprintf(9, "Height = %s\n", bstr("height")); + v->pos_height = atoi(bstr("height")); + } + if (havebstr("width")) { + lprintf(9, "Width = %s\n", bstr("width")); + v->pos_width = atoi(bstr("width")); + } + + /* Serialize it and save it to the message base. Server will delete the old one. */ + serv_puts("ENT0 1|||4"); + serv_getln(buf, sizeof buf); + if (buf[0] == '4') { + serv_puts("Content-type: text/vnote"); + serv_puts(""); + serv_puts(vnote_serialize(v)); + serv_puts("000"); + } + vnote_free(v); +} + + + + + + +#ifdef NEW_NOTES_VIEW + +/* + * display sticky notes + * + * msgnum = Message number on the local server of the note to be displayed + */ +void display_note(long msgnum, int unread) { + struct vnote *v; + + v = vnote_new_from_msg(msgnum); + if (v) { + display_vnote_div(v); + + /* uncomment these lines to see ugly debugging info + wprintf(""); + */ + + vnote_free(v); + } } #endif diff --git a/webcit/static/resizecorner.png b/webcit/static/resizecorner.png new file mode 100644 index 0000000000000000000000000000000000000000..fa3e382c5cce67229b3b35361bd7c8b55934bc3e GIT binary patch literal 530 zcmV+t0`2{YP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iOE1 z6($_0c%zU200ELoL_t(I%cYXPYLr0~#m||Y1vC*NlGLsk3O7D zW`t^hDv@hePj3!;@g(An&#l{598_Zc`Zoc9<#)3Qz{PlscxCXV>J@ig?u-OLn!E)b zQzFT=7hkJqBrJ?$rj1W6=FF5cQSbS`4M@shr%E9Jq2WlEehC0DAgx~cApmgyeLEd# zFv;w2EM7j0eQ*9J_dog(5yowwOQkqX$JozzDmd8fcSipBV+)!?$~8l-ad;0%%IbEz zZ-q0K;dkdp0zgy)`km2B0Afl!xcXfl-q_tV`)iR%%F^5OT~qvCzqb1%8~0IjeL$`G z;B1B&03ZOl^X9@LfJSV(#^~ON1)+g64Pp;;z~QBkRv1ias)(AYgN30GfZ#vo4+dba Uf9`BZHvj+t07*qoM6N<$f`Am 0) { + p = 'note_uid=' + uid_of_note_being_resized + + '&width=' + d.style.width + + '&height=' + d.style.height + + '&r=' + CtdlRandomString(); + new Ajax.Request( + 'ajax_update_note', + { + method: 'post', + parameters: p + } + ); + } + + uid_of_note_being_resized = ''; + return true; +} + +function NotesResizeMouseMove(evt) { + x = (ns6 ? evt.clientX : event.clientX); + x_increment = x - saved_x; + y = (ns6 ? evt.clientY : event.clientY); + y_increment = y - saved_y; + + // Move the div + d = $('note-' + uid_of_note_being_resized); + + divTop = parseInt(d.style.height); + divLeft = parseInt(d.style.width); + + d.style.height = (divTop + y_increment) + 'px'; + d.style.width = (divLeft + x_increment) + 'px'; + + saved_x = x; + saved_y = y; + note_was_resized = 1; + return true; +} + + +function NotesResizeMouseDown(evt, uid) { + saved_x = (ns6 ? evt.clientX : event.clientX); + saved_y = (ns6 ? evt.clientY : event.clientY); + document.onmouseup = NotesResizeMouseUp; + document.onmousemove = NotesResizeMouseMove; + if (document.layers) { + document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE); + } + uid_of_note_being_resized = uid; + d = $('note-' + uid_of_note_being_resized); + saved_cursor_style = d.style.cursor; + d.style.cursor = 'move'; + return false; // disable the default action +} + + + + + + + + + + + + + diff --git a/webcit/static/webcit.css b/webcit/static/webcit.css index 2ec1cab2c..72e237b1f 100644 --- a/webcit/static/webcit.css +++ b/webcit/static/webcit.css @@ -1340,3 +1340,9 @@ li.event_unread span, a.event_read_title { background-color: #888800; font-size: 6px; } + +.stickynote_resize { + position: absolute; + right: 0px; + bottom: 0px; +} -- 2.30.2