* add Michael Meskes patch: make time in task due dates optional
authorWilfried Göesgens <willi@citadel.org>
Sat, 7 Mar 2009 17:24:58 +0000 (17:24 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 7 Mar 2009 17:24:58 +0000 (17:24 +0000)
* make time format a define: FULL/BRIEF/RAWDATE

webcit/calendar.c
webcit/calendar_tools.c
webcit/calendar_view.c
webcit/fmt_date.c
webcit/msg_renderers.c
webcit/static/wclib.js
webcit/webcit.h

index 43d7a710da0a7509500d1ded9ca0006bfc2dfebf..7208760215c994c03f9072542f0dd88c4b6a5ff3 100644 (file)
@@ -125,7 +125,7 @@ void cal_process_object(StrBuf *Target,
                        }
                        else {
                                tt = icaltime_as_timet(t);
-                               webcit_fmt_date(buf, tt, 0);
+                               webcit_fmt_date(buf, tt, DATEFMT_FULL);
                                StrBufAppendPrintf(Target, "<dt>");
                                StrBufAppendPrintf(Target, _("Starting date/time:"));
                                StrBufAppendPrintf(Target, "</dt><dd>%s</dd>", buf);
@@ -136,7 +136,7 @@ void cal_process_object(StrBuf *Target,
                if (p != NULL) {
                        t = icalproperty_get_dtend(p);
                        tt = icaltime_as_timet(t);
-                       webcit_fmt_date(buf, tt, 0);
+                       webcit_fmt_date(buf, tt, DATEFMT_FULL);
                        StrBufAppendPrintf(Target, "<dt>");
                        StrBufAppendPrintf(Target, _("Ending date/time:"));
                        StrBufAppendPrintf(Target, "</dt><dd>%s</dd>", buf);
@@ -683,6 +683,13 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch
        else
                IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
        display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
+
+       wprintf("<INPUT TYPE=\"CHECKBOX\" NAME=\"dtstart_time\" ID=\"dtstart_time\" VALUE=\"yes\"");
+       if (!IcalTime.is_date) {
+               wprintf("CHECKED=\"CHECKED\"");
+       }
+       wprintf(">");
+       wprintf(_("Time associated"));
        wprintf("</TD></TR>\n");
 
        wprintf("<TR><TD>");
@@ -704,7 +711,13 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch
        else
                IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
        display_icaltimetype_as_webform(&IcalTime, "due", 0);
-               
+
+       wprintf("<INPUT TYPE=\"CHECKBOX\" NAME=\"due_time\" ID=\"due_time\" VALUE=\"yes\"");
+       if (!IcalTime.is_date) {
+               wprintf("CHECKED=\"CHECKED\"");
+       }
+       wprintf(">");
+       wprintf(_("Time associated"));
        wprintf("</TD></TR>\n");
        todoStatus = icalcomponent_get_status(vtodo);
        wprintf("<TR><TD>\n");
@@ -837,7 +850,12 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from
                        icalproperty_free(prop);
                }
                if (IsEmptyStr(bstr("nodtstart"))) {
-                       icaltime_from_webform(&t, "dtstart");
+                       if (yesbstr("dtstart_time")) {
+                               icaltime_from_webform(&t, "dtstart");
+                       }
+                       else {
+                               icaltime_from_webform_dateonly(&t, "dtstart");
+                       }
                        icalcomponent_add_property(vtodo,
                                                   icalproperty_new_dtstart(t)
                                );
@@ -880,7 +898,12 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from
                        icalproperty_free(prop);
                }
                if (IsEmptyStr(bstr("nodue"))) {
-                       icaltime_from_webform(&t, "due");
+                       if (yesbstr("due_time")) {
+                               icaltime_from_webform(&t, "due");
+                       }
+                       else {
+                               icaltime_from_webform_dateonly(&t, "due");
+                       }
                        icalcomponent_add_property(vtodo,
                                                   icalproperty_new_due(t)
                                );
index b595d74a50fbdc8d6e961937fd8b22cc0feb138f..6cad617fffa5c4df16e4786b5f7179e5bbab3e0a 100644 (file)
@@ -81,7 +81,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix, int d
        }
 
        wprintf(_("Hour: "));
-       wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
+       wprintf("<SELECT NAME=\"%s_hour\" ID=\"%s_hour\" SIZE=\"1\">\n", prefix, prefix);
        for (i=0; i<=23; ++i) {
 
                if (time_format == WC_TIMEFORMAT_24) {
@@ -101,7 +101,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix, int d
        wprintf("</SELECT>\n");
 
        wprintf(_("Minute: "));
-       wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
+       wprintf("<SELECT NAME=\"%s_minute\" ID=\"%s_minute\" SIZE=\"1\">\n", prefix, prefix);
        for (i=0; i<=59; ++i) {
                if ( (i % 5 == 0) || (tm.tm_min == i) ) {
                        wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
index 4d0d0c8310028c99322981a41981f2266a13d486..8ff0a4dbcea5d630629ed035493bdbe2f6b09bca 100644 (file)
@@ -290,7 +290,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                }
                                                else {
                                                        tt = icaltime_as_timet(t);
-                                                       webcit_fmt_date(buf, tt, 1);
+                                                       webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
                                                        wprintf("<i>%s</i> %s<br>",
                                                                _("Starting date/time:"), buf);
                                                        
@@ -302,7 +302,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                        if (q != NULL) {
                                                                t = icalproperty_get_dtend(q);
                                                                tt = icaltime_as_timet(t);
-                                                               webcit_fmt_date(buf, tt, 1);
+                                                               webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
                                                                wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                                        }
                                                        
@@ -913,9 +913,9 @@ void calendar_day_view_display_events(time_t thetime,
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
                                                                }
-                                webcit_fmt_date(buf, event_tt, 1);
+                                webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                webcit_fmt_date(buf, event_tte, 1);
+                                webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
@@ -992,9 +992,9 @@ void calendar_day_view_display_events(time_t thetime,
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
                                                                }
-                                webcit_fmt_date(buf, event_tt, 1);
+                                webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                webcit_fmt_date(buf, event_tte, 1);
+                                webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
@@ -1435,7 +1435,7 @@ void render_calendar_view(struct calview *c)
 /*
  * Helper function for do_tasks_view().  Returns the due date/time of a vtodo.
  */
-time_t get_task_due_date(icalcomponent *vtodo) {
+time_t get_task_due_date(icalcomponent *vtodo, int *is_date) {
        icalproperty *p;
 
        if (vtodo == NULL) {
@@ -1451,13 +1451,17 @@ time_t get_task_due_date(icalcomponent *vtodo) {
                return get_task_due_date(
                        icalcomponent_get_first_component(
                                vtodo, ICAL_VTODO_COMPONENT
-                               )
+                               ), is_date
                        );
        }
 
        p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
        if (p != NULL) {
-               return(icaltime_as_timet(icalproperty_get_due(p)));
+               struct icaltimetype t = icalproperty_get_due(p);
+
+               if (is_date)
+                       *is_date = t.is_date;
+               return(icaltime_as_timet(t));
        }
        else {
                return(0L);
@@ -1475,8 +1479,8 @@ int task_due_cmp(const void *vtask1, const void *vtask2) {
        time_t t1;
        time_t t2;
 
-       t1 =  get_task_due_date(Task1->cal);
-       t2 =  get_task_due_date(Task2->cal);
+       t1 =  get_task_due_date(Task1->cal, NULL);
+       t2 =  get_task_due_date(Task2->cal, NULL);
        if (t1 < t2) return(-1);
        if (t1 > t2) return(1);
        return(0);
@@ -1545,6 +1549,7 @@ void do_tasks_view(void) {
        Pos = GetNewHashPos(WCC->disp_cal_items, 0);
        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
                icalproperty_status todoStatus;
+               int is_date;
 
                Cal = (disp_cal*)vCal;
                wprintf("<tr><td>");
@@ -1567,10 +1572,10 @@ void do_tasks_view(void) {
                wprintf("</a>\n");
                wprintf("</td>\n");
 
-               due = get_task_due_date(Cal->cal);
+               due = get_task_due_date(Cal->cal, &is_date);
                wprintf("<td><span");
                if (due > 0) {
-                       webcit_fmt_date(buf, due, 0);
+                       webcit_fmt_date(buf, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
                        wprintf(">%s",buf);
                }
                else {
index 2b6ec20360e44a245d8cb43a1b55e156a3672f5a..04cb391f5b8698ee990622a46bc62091be15d7ba 100644 (file)
@@ -47,7 +47,7 @@ size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm)
 /*
  * Format a date/time stamp for output 
  */
-void webcit_fmt_date(char *buf, time_t thetime, int brief)
+void webcit_fmt_date(char *buf, time_t thetime, int Format)
 {
        struct tm tm;
        struct tm today_tm;
@@ -60,34 +60,44 @@ void webcit_fmt_date(char *buf, time_t thetime, int brief)
 
        localtime_r(&thetime, &tm);
 
-       if (brief) {
+       /*
+        * DATEFMT_FULL:      full display 
+        * DATEFMT_BRIEF:     if date == today, show only the time
+        *                    otherwise, for messages up to 6 months old, 
+        *                 show the month and day, and the time
+        *                    older than 6 months, show only the date
+        * DATEFMT_RAWDATE:   show full date, regardless of age 
+        */
 
-               /* If date == today, show only the time */
-               if ((tm.tm_year == today_tm.tm_year)
-                 &&(tm.tm_mon == today_tm.tm_mon)
-                 &&(tm.tm_mday == today_tm.tm_mday)) {
-                       if (time_format == WC_TIMEFORMAT_24) 
-                               wc_strftime(buf, 32, "%k:%M", &tm);
-                       else
-                               wc_strftime(buf, 32, "%l:%M%p", &tm);
-               }
-               /* Otherwise, for messages up to 6 months old, show the month and day, and the time */
-               else if (today_timet - thetime < 15552000) {
-                       if (time_format == WC_TIMEFORMAT_24) 
-                               wc_strftime(buf, 32, "%b %d %k:%M", &tm);
+       switch (Format) {
+               case DATEFMT_BRIEF:
+                       if ((tm.tm_year == today_tm.tm_year)
+                         &&(tm.tm_mon == today_tm.tm_mon)
+                         &&(tm.tm_mday == today_tm.tm_mday)) {
+                               if (time_format == WC_TIMEFORMAT_24) 
+                                       wc_strftime(buf, 32, "%k:%M", &tm);
+                               else
+                                       wc_strftime(buf, 32, "%l:%M%p", &tm);
+                       }
+                       else if (today_timet - thetime < 15552000) {
+                               if (time_format == WC_TIMEFORMAT_24) 
+                                       wc_strftime(buf, 32, "%b %d %k:%M", &tm);
+                               else
+                                       wc_strftime(buf, 32, "%b %d %l:%M%p", &tm);
+                       }
+                       else {
+                               wc_strftime(buf, 32, "%b %d %Y", &tm);
+                       }
+                       break;
+               case DATEFMT_FULL:
+                       if (time_format == WC_TIMEFORMAT_24)
+                               wc_strftime(buf, 32, "%a %b %d %Y %T %Z", &tm);
                        else
-                               wc_strftime(buf, 32, "%b %d %l:%M%p", &tm);
-               }
-               /* older than 6 months, show only the date */
-               else {
-                       wc_strftime(buf, 32, "%b %d %Y", &tm);
-               }
-       }
-       else {
-               if (time_format == WC_TIMEFORMAT_24)
-                       wc_strftime(buf, 32, "%a %b %d %Y %T %Z", &tm);
-               else
-                       wc_strftime(buf, 32, "%a %b %d %Y %r %Z", &tm);
+                               wc_strftime(buf, 32, "%a %b %d %Y %r %Z", &tm);
+                       break;
+               case DATEFMT_RAWDATE:
+                       wc_strftime(buf, 32, "%a %b %d %Y", &tm);
+                       break;
        }
 }
 
index ed20d2eb28f850eb8f96ed9952aa0b110f8127e1..e944548b0fd0db8f919b8aef608c78319685173d 100644 (file)
@@ -441,7 +441,7 @@ void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
 {
        char datebuf[64];
        message_summary *Msg = (message_summary*) CTX;
-       webcit_fmt_date(datebuf, Msg->date, 1);
+       webcit_fmt_date(datebuf, Msg->date, DATEFMT_BRIEF);
        StrBufAppendBufPlain(Target, datebuf, -1, 0);
 }
 
@@ -449,7 +449,7 @@ void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
 {
        char datebuf[64];
        message_summary *Msg = (message_summary*) CTX;
-       webcit_fmt_date(datebuf, Msg->date, 0);
+       webcit_fmt_date(datebuf, Msg->date, DATEFMT_FULL);
        StrBufAppendBufPlain(Target, datebuf, -1, 0);
 }
 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
index be07284322ef7bd4b41bfa3605be31882dabd6d4..622e92005dbc10d25094859a7580022f6e9d060b 100644 (file)
@@ -647,12 +647,24 @@ function HandleRSVP(question_divname, title_divname, msgnum, cal_partnum, sc) {
 // TODO: Collapse into one function
 function toggleTaskDtStart(event) {
        var checkBox = $('nodtstart');
+       var checkBoxTime = $('dtstart_time');
        dtStart = document.getElementById("dtstart");
+       dtStartHour = document.getElementById("dtstart_hour");
+       dtStartMinute = document.getElementById("dtstart_minute");
        if (checkBox.checked) {
                dtStart.disabled = true;
+               dtStartHour.disabled = true;
+               dtStartMinute.disabled = true;
                dtStart.style.textDecoration = "line-through";
        } else {
                dtStart.disabled = false;
+               if (checkBoxTime.checked) {
+                       dtStartHour.disabled = false;
+                       dtStartMinute.disabled = false;
+               } else {
+                       dtStartHour.disabled = true;
+                       dtStartMinute.disabled = true;
+               }
                dtStart.style.textDecoration = "";
                if (dtStart.value.length == 0)
                        dtStart.dpck._initCurrentDate();
@@ -660,12 +672,24 @@ function toggleTaskDtStart(event) {
 }
 function toggleTaskDue(event) {
        var checkBox = $('nodue');
+       var checkBoxTime = $('due_time');
        dueField = document.getElementById("due");
+       dueFieldHour = document.getElementById("due_hour");
+       dueFieldMinute = document.getElementById("due_minute");
        if (checkBox.checked) {
                dueField.disabled = true;
+               dueFieldHour.disabled = true;
+               dueFieldMinute.disabled = true;
                dueField.style.textDecoration = "line-through";
        } else {
                dueField.disabled = false;
+               if (checkBoxTime.checked) {
+                       dueFieldHour.disabled = false;
+                       dueFieldMinute.disabled = false;
+               } else {
+                       dueFieldHour.disabled = true;
+                       dueFieldMinute.disabled = true;
+               }
                dueField.style.textDecoration = "";
                if (dueField.value.length == 0)
                        dueField.dpck._initCurrentDate();
@@ -677,7 +701,9 @@ function ToggleTaskDateOrNoDateActivate(event) {
                toggleTaskDtStart(null);
                toggleTaskDue(null);
                $('nodtstart').observe('click', toggleTaskDtStart);
+               $('dtstart_time').observe('click', toggleTaskDtStart);
                $('nodue').observe('click', toggleTaskDue);
+               $('due_time').observe('click', toggleTaskDue);
        } 
 }
 function TaskViewGatherCategoriesFromTable() {
index 74083d41ce7c9e9538e6f28128d3a7f501c6e643..e2c7aef9e796189e19cb90e9a71d78dcafc22980 100644 (file)
@@ -721,7 +721,11 @@ long guess_calhourformat(void);
 int get_time_format_cached (void);
 int xtoi(const char *in, size_t len);
 const char *get_selected_language(void);
-void webcit_fmt_date(char *buf, time_t thetime, int brief);
+
+#define DATEFMT_FULL 0
+#define DATEFMT_BRIEF 1
+#define DATEFMT_RAWDATE 2
+void webcit_fmt_date(char *buf, time_t thetime, int Format);
 int fetch_http(char *url, char *target_buf, int maxbytes);
 void free_attachments(wcsession *sess);
 void summary(void);