Sticky notes can now be moved and resized by dragging
authorArt Cancro <ajc@citadel.org>
Tue, 29 Apr 2008 21:56:11 +0000 (21:56 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 29 Apr 2008 21:56:11 +0000 (21:56 +0000)
and their size/position are now updated on the server.

webcit/notes.c
webcit/static/resizecorner.png [new file with mode: 0644]
webcit/static/wclib.js
webcit/static/webcit.css

index 24f3c5de056366f66dd04b3d633c6d03027290a8..81cc8b9fa7e05cdfd1ceaa541af20ba4c6d4bfbb 100644 (file)
@@ -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 <div> containing a rendered sticky note.
  */
@@ -223,20 +195,33 @@ void display_vnote_div(struct vnote *v) {
 
        wprintf("</div>\n");
 
+       /* begin note body */
+
        escputs(v->body);
 
+       /* begin resize handle */
+
+       wprintf("<div id=\"resize-%s\" ", v->uid);
+       wprintf("class=\"stickynote_resize\" ");
+       wprintf("onMouseDown=\"NotesResizeMouseDown(event,'%s')\" ", v->uid);
+       wprintf("style=\"");
+       wprintf("\">");
+
+       wprintf("<img src=\"static/resizecorner.png\">");
+
        wprintf("</div>\n");
-}
 
+       /* end of note */
+
+       wprintf("</div>\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("<script type=\"text/javascript\">");
-                       wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
-                       wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
-                       wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
-                       wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
-                       wprintf("</script>");
-                       */
-
-                       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("<script type=\"text/javascript\">");
+               wprintf("document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
+               wprintf("document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
+               wprintf("document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
+               wprintf("document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
+               wprintf("</script>");
+               */
+
+               vnote_free(v);
+       }
 }
 
 #endif
diff --git a/webcit/static/resizecorner.png b/webcit/static/resizecorner.png
new file mode 100644 (file)
index 0000000..fa3e382
Binary files /dev/null and b/webcit/static/resizecorner.png differ
index f1e7eaf9f501c2273ce0b3b4e808e9491716f956..581903e09e0eae62ea912189dfbc044d66334c16 100644 (file)
@@ -498,6 +498,90 @@ function NotesDragMouseDown(evt, uid) {
 
 
 
+// These functions handle resizing sticky notes by dragging the resize handle
+
+var uid_of_note_being_resized = 0;
+var saved_cursor_style = 'default';
+var note_was_resized = 0;
+
+function NotesResizeMouseUp(evt) {
+       document.onmouseup = null;
+       document.onmousemove = null;
+       if (document.layers) {
+               document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
+       }
+
+       d = $('note-' + uid_of_note_being_resized);
+       d.style.cursor = saved_cursor_style;
+
+       // If any motion actually occurred, submit an ajax http call to record it to the server
+       if (note_was_resized > 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
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 
 
index 2ec1cab2ce6f104d73b83171fa483b8208081107..72e237b1f47f7afb189264107fd85c79bd8f284c 100644 (file)
@@ -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;
+}