Index: openacs-4/packages/calendar-portlet/www/calendar-portlet.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar-portlet/www/calendar-portlet.tcl,v diff -u -r1.22 -r1.23 --- openacs-4/packages/calendar-portlet/www/calendar-portlet.tcl 17 Aug 2003 01:48:08 -0000 1.22 +++ openacs-4/packages/calendar-portlet/www/calendar-portlet.tcl 22 Sep 2003 10:04:39 -0000 1.23 @@ -1,4 +1,3 @@ - # # Copyright (C) 2001, 2002 MIT # @@ -38,6 +37,7 @@ } } + # get stuff out of the config array array set config $cf set view $config(default_view) @@ -70,19 +70,133 @@ set current_date $date set date_format "YYYY-MM-DD HH24:MI" -set calendar_list [calendar::calendar_list] -set date [calendar::adjust_date -date $date -julian_date $julian_date] +set item_template "\$item" -if {$view == "list"} { - if {[empty_string_p $start_date]} { - set start_date $date +if {$create_p} { + set hour_template "\$hour" + set item_add_template "ADD" +} else { + set hour_template "\$hour" + set item_add_template "" +} + +# big switch on the view var +if { $view == "day" } { + + # Check that the previous and next days are in the tcl boundaries + # so that the calendar widget doesn't bomb when it creates the next/prev links + if {[catch {set yest [clock format [clock scan "1 day ago" -base [clock scan $date]] -format "%Y-%m-%d"]}]} { + set previous_link "" + } else { + if {[catch {clock scan $yest}]} { + set previous_link "" + } else { + set previous_link "\"back" + } } - set ansi_list [split $start_date "- "] - set ansi_year [lindex $ansi_list 0] - set ansi_month [string trimleft [lindex $ansi_list 1] "0"] - set ansi_day [string trimleft [lindex $ansi_list 2] "0"] - set end_date [dt_julian_to_ansi [expr [dt_ansi_to_julian $ansi_year $ansi_month $ansi_day ] + $period_days]] + if {[catch {set tomor [clock format [clock scan "1 day" -base [clock scan $date]] -format "%Y-%m-%d"]}]} { + set next_link "" + } else { + if {[catch {clock scan $tomor}]} { + set next_link "" + } else { + set next_link "\"forward" + } + } + + + set cal_stuff [calendar::one_day_display \ + -prev_nav_template $previous_link \ + -next_nav_template $next_link \ + -item_template $item_template \ + -hour_template $hour_template \ + -date $current_date -start_hour 7 -end_hour 22 \ + -calendar_id_list $list_of_calendar_ids \ + -url_stub_callback "calendar_portlet_display::get_url_stub" \ + -show_calendar_name_p $show_calendar_name_p] + } -ad_return_template +if {$view == "week"} { + + # Check that the previous and next weeks are in the tcl boundaries + # so that the calendar widget doesn't bomb when it creates the next/prev links + if {[catch {set last_w [clock format [clock scan "1 week ago" -base [clock scan $date]] -format "%Y-%m-%d"]}]} { + set previous_link "" + } else { + if {[catch {clock scan $last_w}]} { + set previous_link "" + } else { + set previous_link "\"back" + } + } + + if {[catch {set next_w [clock format [clock scan "1 week" -base [clock scan $date]] -format "%Y-%m-%d"]}]} { + set next_link "" + } else { + if {[catch {clock scan $next_w}]} { + set next_link "" + } else { + set next_link "\"forward" + } + } + + set cal_stuff [calendar::one_week_display \ + -item_template $item_template \ + -date $current_date \ + -calendar_id_list $list_of_calendar_ids \ + -url_stub_callback "calendar_portlet_display::get_url_stub" \ + -prev_week_template $previous_link \ + -next_week_template $next_link \ + -show_calendar_name_p $show_calendar_name_p] +} + +if {$view == "month"} { + + # Check that the previous and next months are in the tcl boundaries + # so that the calendar widget doesn't bomb when it creates the next/prev links + if {[catch {set prev_m [clock format [clock scan "1 month ago" -base [clock scan $date]] -format "%Y-%m-%d"]}]} { + set previous_link "" + } else { + if {[catch {clock scan $prev_m}]} { + set previous_link "" + } else { + set previous_link "\"back" + } + } + + if {[catch {set next_m [clock format [clock scan "1 month" -base [clock scan $date]] -format "%Y-%m-%d"]}]} { + set next_link "" + } else { + if {[catch {clock scan $next_m}]} { + set next_link "" + } else { + set next_link "\"forward" + } + } + + + set cal_stuff [calendar::one_month_display \ + -item_template $item_template \ + -day_template "\$day_number" \ + -date $current_date \ + -item_add_template $item_add_template \ + -calendar_id_list $list_of_calendar_ids \ + -url_stub_callback "calendar_portlet_display::get_url_stub" \ + -show_calendar_name_p $show_calendar_name_p] +} + +if {$view == "list"} { + set cal_stuff [calendar::list_display \ + -item_template $item_template \ + -date $current_date \ + -calendar_id_list $list_of_calendar_ids \ + -url_stub_callback "calendar_portlet_display::get_url_stub" \ + -prev_month_template $previous_link \ + -next_month_template $next_link \ + -show_calendar_name_p $show_calendar_name_p] +} + + +ad_return_template