From 9a85a9f3c8905d5676603ed7d50c237e2545e2d9 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 15 Oct 2007 17:42:49 +0000 Subject: [PATCH] Mini month calendar is complete. The 'previous month' and 'next month' buttons are using AJAX updater in order to eliminate the need to re-render the entire screen. --- webcit/calendar_view.c | 60 +++++++++++++++++++++++++++++++----------- webcit/webcit.c | 4 +++ webcit/webcit.h | 2 ++ 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 17a0cbf9c..c26241c01 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -14,14 +14,12 @@ /****************************************************************************/ -/** - */ 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("
\n", div_id); + /* Previous month link */ localtime_r(&previous_month, &tm); - - wprintf("«"); - wprintf(" "); -/* previous month - wprintf("", + wprintf("«", (int)(tm.tm_year)+1900, tm.tm_mon + 1); - wprintf("\n"); -*/ wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm); wprintf("  " @@ -85,14 +79,10 @@ void embeddable_mini_calendar(int year, int month, char *urlformat) "" "  ", colheader_label, year); - wprintf(" "); - wprintf("»"); -/* + /* Next month link */ localtime_r(&next_month, &tm); - wprintf("", + wprintf("»", (int)(tm.tm_year)+1900, tm.tm_mon + 1); - wprintf("\n"); -*/ wprintf("" ""); @@ -139,6 +129,41 @@ void embeddable_mini_calendar(int year, int month, char *urlformat) wprintf("
" /** end of inner table */ "
\n"); + + /* javascript for previous and next month */ + len = strlen(urlformat); + for (i=0; i " + " 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 } ); " + " } " + "\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
\n"); } +/**\brief stub for non-libical builds */ +void ajax_mini_calendar(void) { +} #endif /* WEBCIT_WITH_CALENDAR_SERVICE */ diff --git a/webcit/webcit.c b/webcit/webcit.c index 428003ee9..e3cef8ff7 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -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(); diff --git a/webcit/webcit.h b/webcit/webcit.h index 75376fef9..42c398129 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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); -- 2.30.2