Complete overhaul of "Notes" view. Now features AJAX create and edit operations.
authorArt Cancro <ajc@citadel.org>
Thu, 26 Jan 2006 20:45:41 +0000 (20:45 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 26 Jan 2006 20:45:41 +0000 (20:45 +0000)
webcit/ChangeLog
webcit/groupdav_put.c
webcit/messages.c
webcit/notes.c
webcit/roomops.c
webcit/static/wclib.js
webcit/webcit.c
webcit/webcit.h

index 57c3f42f47cb3e9e0da4e1a618c431c72b5329e9..0d41d0d0b8881980a5892235e2c56c3073a89ffd 100644 (file)
@@ -1,5 +1,8 @@
 $Id$
 
+Thu Jan 26 15:44:56 EST 2006 ajc
+* Complete overhaul of "Notes" view.  Now features AJAX create and edit operations.
+
 Wed Jan 25 22:25:46 EST 2006 ajc
 * Fixed some spelling errors
 * Added en_GB.po translation provided by David Given
index e2c91fe727bc8ba2b25cfac32dd753edc7e6822f..73f9e349f269344c2360e7bbcba193d974e3d75b 100644 (file)
@@ -12,9 +12,9 @@
 
 
 /**
- * \brief put an item to the server
+ * \brief GroupDAV PUT an item to the server
  * \param dav_pathname The pathname is always going to be /groupdav/room_name/euid
- * \param dav_ifmatch should we match?
+ * \param dav_ifmatch ETag of the item we think we're replacing
  * \param dav_content_type the mime type
  * \param dav_content the actual data
  */
index 9af483f6a7df928bf57cde866846d625ba1c59fb..3c3770e508deeb128392a0dcb1e0263072563afc 100644 (file)
@@ -2187,6 +2187,11 @@ void readloop(char *oper)
                );
        }
 
+       if (is_notes) {
+               wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
+               wprintf("<div id=\"new_notes_here\"></div>\n");
+       }
+
        for (a = 0; a < nummsgs; ++a) {
                if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
 
index 89f2c84ca31a342c04f0d09211e8d840b6a0c4d1..667745c7fcbce75ac66e55d94e125ff9b4bfeed0 100644 (file)
@@ -7,16 +7,19 @@
  */
 /*@{*/
 #include "webcit.h"
+#include "groupdav.h"
 #include "webserver.h"
 
 /**
  * \brief display sticky notes
  * \param msgnum the citadel mesage number
  */
-void display_note(long msgnum) {
+void display_note(long msgnum)
+{
        char buf[SIZ];
        char notetext[SIZ];
        char display_notetext[SIZ];
+       char eid[128];
        int in_text = 0;
        int i;
 
@@ -30,28 +33,102 @@ void display_note(long msgnum) {
        }
 
        strcpy(notetext, "");
+       strcpy(eid, "");
        while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
 
-               /** Fill the buffer to at least 256 characters */
-               if ( (in_text) && (strlen(notetext) < 256) ) {
+               /** Fill the buffer */
+               if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
                        strcat(notetext, buf);
                }
 
+               if ( (!in_text) && (!strncasecmp(buf, "exti=", 5)) ) {
+                       safestrncpy(eid, &buf[5], sizeof eid);
+               }
+
                if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
                        in_text = 1;
                }
        }
 
-       /** Now sanitize the buffer, and shorten it to just a small snippet */
+       /** Now sanitize the buffer */
        for (i=0; i<strlen(notetext); ++i) {
                if (isspace(notetext[i])) notetext[i] = ' ';
        }
-       strcpy(&notetext[72], "...");
 
        /** Make it HTML-happy and print it. */
-       stresc(display_notetext, notetext, 1, 1);
-       wprintf("%s<br />\n", display_notetext);
+       stresc(display_notetext, notetext, 0, 0);
+       if (strlen(eid) > 0) {
+               wprintf("<span id=\"note%s\">%s</span><br />\n", eid, display_notetext);
+       }
+       else {
+               wprintf("<span id=\"note%ld\">%s</span><br />\n", msgnum, display_notetext);
+       }
+
+       /** Offer in-place editing. */
+       if (strlen(eid) > 0) {
+               wprintf("<script type=\"text/javascript\">"
+                       " new Ajax.InPlaceEditor('note%s', 'updatenote?eid=%s', {rows:5,cols:72}); "
+                       "</script>\n",
+                       eid,
+                       eid
+               );
+       }
 }
 
 
+/**
+ * \brief  This gets called by the Ajax.InPlaceEditor when we save a note.
+ */
+void updatenote(void)
+{
+       char buf[SIZ];
+       char notetext[SIZ];
+       char display_notetext[SIZ];
+       long msgnum;
+       int in_text = 0;
+       int i;
+
+       serv_printf("ENT0 1||0|0||||||%s", bstr("eid"));
+       serv_getln(buf, sizeof buf);
+       if (buf[0] == '4') {
+               text_to_server(bstr("value"), 0);
+               serv_puts("000");
+       }
+
+       begin_ajax_response();
+       msgnum = locate_message_by_uid(bstr("eid"));
+       if (msgnum >= 0L) {
+               serv_printf("MSG0 %ld", msgnum);
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '1') {
+                       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+               
+                               /** Fill the buffer */
+                               if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
+                                       strcat(notetext, buf);
+                               }
+               
+                               if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
+                                       in_text = 1;
+                               }
+                       }
+                       /** Now sanitize the buffer */
+                       for (i=0; i<strlen(notetext); ++i) {
+                               if (isspace(notetext[i])) notetext[i] = ' ';
+                       }
+               
+                       /** Make it HTML-happy and print it. */
+                       stresc(display_notetext, notetext, 0, 0);
+                       wprintf("%s\n", display_notetext);
+               }
+       }
+       else {
+               wprintf("%s", _("An error has occurred."));
+       }
+
+       end_ajax_response();
+}
+
+
+
 /*@}*/
index f0df5cce2f4d90d3f861e9d08da3758856801dbe..47bb358cf8d04222e500f7e4aed9a58431ed0d41 100644 (file)
@@ -541,7 +541,7 @@ void embed_room_banner(char *got, int navbar_style) {
                                        break;
                                case VIEW_NOTES:
                                        wprintf(
-                                               "<td><a href=\"display_enter\">"
+                                               "<td><a href=\"javascript:add_new_note();\">"
                                                "<img align=\"middle\" src=\"static/enternewnote_24x.gif\" "
                                                "border=\"0\"><span class=\"navbar_link\">"
                                                "%s"
index 78e7cc5c8fc2e8d542d8b5d7adee6e9394733fc7..bf4ae9aa9876ff4e202b32aef0f34b3bf7704e84 100644 (file)
@@ -465,3 +465,19 @@ function ctdl_ts_getInnerText(el) {
 }
 
 
+
+// This function handles the creation of new notes in the "Notes" view.
+//
+function add_new_note() {
+
+       new_eid = Math.random() + '';
+       new_eid = new_eid.substr(3);
+
+       $('new_notes_here').innerHTML = $('new_notes_here').innerHTML
+               + '<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">'
+               + '<span id=\"note' + new_eid + '\">' + Date() + '</span><br />'
+       ;
+
+       new Ajax.InPlaceEditor('note' + new_eid,
+               'updatenote?eid=' + new_eid , {rows:5,cols:72});
+}
index e1852a901f00c322bbe4ba332f4036d19ab85257..e03db53de88f4e6877691b82ebafcf4c3ca36420 100644 (file)
@@ -1621,6 +1621,8 @@ void session_loop(struct httprequest *req)
                dump_vars();
                wprintf("</PRE><hr />\n");
                wDumpContent(1);
+       } else if (!strcasecmp(action, "updatenote")) {
+               updatenote();
        }
 
        /** When all else fais, display the main menu. */
index 22ec3a3cfe626f2604d0a8ddc09ddec96f949312..00c6f1ce28d431462a641af9c7cadb3a10a9630f 100644 (file)
@@ -601,6 +601,7 @@ void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum);
 void display_calendar(long msgnum);
 void display_task(long msgnum);
 void display_note(long msgnum);
+void updatenote(void);
 void do_calendar_view(void);
 void do_tasks_view(void);
 void free_calendar_buffer(void);