Mini month calendar is complete. The 'previous month'
authorArt Cancro <ajc@citadel.org>
Mon, 15 Oct 2007 17:42:49 +0000 (17:42 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 15 Oct 2007 17:42:49 +0000 (17:42 +0000)
and 'next month' buttons are using AJAX updater in order to
eliminate the need to re-render the entire screen.

webcit/calendar_view.c
webcit/webcit.c
webcit/webcit.h

index 17a0cbf9c95e228912aa6f5c972fe1aec73be6a4..c26241c017fefef1de07b67f1e4c221bc0078954 100644 (file)
 /****************************************************************************/
 
 
-/**
- */
 void embeddable_mini_calendar(int year, int month, char *urlformat)
 {
        struct tm starting_tm;
        struct tm tm;
        time_t thetime;
-       int i;
+       int i, len;
        time_t previous_month;
        time_t next_month;
        time_t colheader_time;
@@ -31,6 +29,7 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
        char weekstart_buf[16];
        char url[256];
        char div_id[256];
+       char escaped_urlformat[256];
 
        snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
 
@@ -68,15 +67,10 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
 
        wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
 
+       /* Previous month link */
        localtime_r(&previous_month, &tm);
-
-       wprintf("<a href=\"javascript:minical_previous_month();\">&laquo;</a>");
-       wprintf("&nbsp;");
-/* previous month
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">&laquo;</a>", 
                (int)(tm.tm_year)+1900, tm.tm_mon + 1);
-       wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
-*/
 
        wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
        wprintf("&nbsp;&nbsp;"
@@ -85,14 +79,10 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
                "</span>"
                "&nbsp;&nbsp;", colheader_label, year);
 
-       wprintf("&nbsp;");
-       wprintf("<a href=\"javascript:minical_next_month();\">&raquo;</a>");
-/*
+       /* Next month link */
        localtime_r(&next_month, &tm);
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">&raquo;</a>",
                (int)(tm.tm_year)+1900, tm.tm_mon + 1);
-       wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
-*/
 
        wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
                "<tr>");
@@ -139,6 +129,41 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
 
        wprintf("</table>"                      /** end of inner table */
                "</div>\n");
+
+       /* javascript for previous and next month */
+       len = strlen(urlformat);
+       for (i=0; i<len; ++i) {
+               sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
+       }
+
+       wprintf("<script type=\"text/javascript\">                                                      "
+               "       function minical_change_month(year, month) {                                    "
+               "               p = 'year=' + year + '&month=' + month                                  "
+               "                       + '&urlformat=%s&r=' + CtdlRandomString();                      "
+               "               new Ajax.Updater('%s', 'mini_calendar',                                 "
+               "                       { method: 'get', parameters: p, evalScripts: true } );          "
+               "       }                                                                               "
+               "</script>\n"
+               ,
+               escaped_urlformat, div_id
+       );
+
+}
+
+/* ajax embedder for the above mini calendar */
+void ajax_mini_calendar(void) {
+       char urlformat[256];
+       int i, len;
+       char *escaped_urlformat;
+
+       escaped_urlformat = bstr("urlformat");
+        len = strlen(escaped_urlformat) * 2 ;
+       for (i=0; i<len; ++i) {
+               urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
+               urlformat[i+1] = 0;
+       }
+
+       embeddable_mini_calendar( atoi(bstr("year")), atoi(bstr("month")), urlformat );
 }
 
 
@@ -1334,6 +1359,9 @@ void do_tasks_view(void) {
        wprintf("</i></center><br />\n");
 }
 
+/**\brief stub for non-libical builds */
+void ajax_mini_calendar(void) {
+}
 
 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
 
index 428003ee92e73b5ae8db277e704c6155a276bb5a..e3cef8ff782e95c43ab1e57efe2b791c73bbe2f8 100644 (file)
@@ -1533,6 +1533,10 @@ void session_loop(struct httprequest *req)
                begin_ajax_response();
                calendar_section();
                end_ajax_response();
+       } else if (!strcasecmp(action, "mini_calendar")) {
+               begin_ajax_response();
+               ajax_mini_calendar();
+               end_ajax_response();
        } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
                begin_ajax_response();
                do_iconbar();
index 75376fef99dd38c9af2b2aa07cbb581dcffab197..42c39812972c0c9a693320fa588fb0969f837bb0 100644 (file)
@@ -464,6 +464,7 @@ void who_inner_div(void);
 void wholist_section(void);
 void tasks_section(void);
 void calendar_section(void);
+void ajax_mini_calendar(void);
 void new_messages_section(void);
 void fmout(char *align);
 void pullquote_fmout(void);
@@ -724,6 +725,7 @@ void str_wiki_index(char *s);
 void display_wiki_page(void);
 char *bmstrcasestr(char *text, char *pattern);
 int get_time_format_cached (void);
+int xtoi(char *in, size_t len);
 
 #ifdef HAVE_ICONV
 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode);