Index: openacs-4/packages/calendar/www/mini-calendar.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/www/mini-calendar.tcl,v diff -u -r1.23 -r1.24 --- openacs-4/packages/calendar/www/mini-calendar.tcl 22 May 2018 16:44:55 -0000 1.23 +++ openacs-4/packages/calendar/www/mini-calendar.tcl 3 Sep 2024 15:37:36 -0000 1.24 @@ -1,13 +1,24 @@ -if {![info exists base_url] || $base_url eq ""} { - set base_url [ad_conn url] +ad_include_contract { + + Mini calendar + +} { + {base_url:localurl "[ad_conn url]"} + {date:clock(%Y-%m-%d|%Y%m%d) "[dt_sysdate]"} } -if {![info exists date] || $date eq ""} { - set date [dt_sysdate] +if {$base_url eq ""} { + set base_url [ad_conn url] } -ad_form -name go-to-date -method get -has_submit 1 -action $base_url \ - -export [lappend list_of_vars page_num] \ +# +# Do not conflict with other portlet instances being rendered on the +# same page. +# +set form_name go-to-date-[clock microseconds] + +ad_form -name $form_name -method get -has_submit 1 -action $base_url \ + -export {page_num} \ -html {class inline-form} \ -form { {date:text,nospell,optional @@ -16,7 +27,7 @@ } {btn_ok:text(submit) {label "[_ calendar.Go_to_date]"} - } + } {view:text(hidden) {value "day"} } @@ -33,12 +44,12 @@ # Determine whether we need to pass on the period_days variable from the list view if {$view eq "list"} { - if {(![info exists period_days] || $period_days eq "") - || $period_days eq [parameter::get -parameter ListView_DefaultPeriodDays -default 31] + if {(![info exists period_days] || $period_days eq "") + || $period_days eq [parameter::get -parameter ListView_DefaultPeriodDays -default 31] } { - set url_stub_period_days "" + set url_stub_period_days "" } else { - set url_stub_period_days "&period_days=${period_days}" + set url_stub_period_days "&period_days=${period_days}" } } else { set url_stub_period_days "" @@ -60,37 +71,34 @@ set active_p f } if {$viewname eq "list"} { - multirow append views [lang::util::localize $message_key_array($viewname)] $viewname $active_p \ - "[export_vars -base $base_url {date {view $viewname}}]${page_num}${url_stub_period_days}" + multirow append views [lang::util::localize $message_key_array($viewname)] $viewname $active_p \ + "[export_vars -base $base_url {date {view $viewname}}]${page_num}${url_stub_period_days}" } else { - multirow append views [lang::util::localize $message_key_array($viewname)] $viewname $active_p \ - "[export_vars -base $base_url {date {view $viewname}}]${page_num}" + multirow append views [lang::util::localize $message_key_array($viewname)] $viewname $active_p \ + "[export_vars -base $base_url {date {view $viewname}}]${page_num}" } } -set list_of_vars [list] - -# Get the current month, day, and the first day of the month -if {[catch { - dt_get_info $date -} errmsg]} { - set date [dt_sysdate] - dt_get_info $date -} - +# +# Parse the date and extract the information needed to render the +# calendar. +# set now [clock scan $date] -set date_list [dt_ansi_to_list $date] -set year [util::trim_leading_zeros [lindex $date_list 0]] -set month [util::trim_leading_zeros [lindex $date_list 1]] -set day [util::trim_leading_zeros [lindex $date_list 2]] - +lassign [dt_ansi_to_list $date] year month day set months_list [dt_month_names] set curr_month_idx [expr {[util::trim_leading_zeros [clock format $now -format "%m"]]-1}] set curr_day [clock format $now -format "%d"] set curr_month [clock format $now -format "%B"] set curr_year [clock format $now -format "%Y"] set curr_date_pretty [lc_time_fmt $date "%q"] +set dt_info [dt_get_info -dict $date] +set first_julian_date_of_month [dict get $dt_info first_julian_date_of_month] +set days_in_last_month [dict get $dt_info days_in_last_month] +set last_julian_date [dict get $dt_info last_julian_date] +set last_julian_date_in_month [dict get $dt_info last_julian_date_in_month] +set julian_date_today [dict get $dt_info julian_date_today] + set today [lc_time_fmt [dt_sysdate] "%q"] if {$view eq "month"} { @@ -110,22 +118,22 @@ set new_row_p [expr {$i / 3}] if {$i == $curr_month_idx} { - set current_month_p t + set current_month_p t } else { set current_month_p f } set target_date [clock format \ [clock scan "[expr {$i-$curr_month_idx}] month" -base $now] -format "%Y-%m-%d"] multirow append months $month $current_month_p $new_row_p \ "[export_vars -base $base_url {{date $target_date} view}]${page_num}${url_stub_period_days}" - + } } else { set prev_month [clock format [clock scan "1 month ago" -base $now] -format "%Y-%m-%d"] set next_month [clock format [clock scan "1 month" -base $now] -format "%Y-%m-%d"] set prev_month_url "$base_url?view=$view&date=[ad_urlencode $prev_month]${page_num}${url_stub_period_days}" set next_month_url "$base_url?view=$view&date=[ad_urlencode $next_month]${page_num}${url_stub_period_days}" - + set first_day_of_week [lc_get firstdayofweek] set week_days [lc_get abday] set long_weekdays [lc_get day] @@ -158,10 +166,10 @@ set active_p f } elseif {$julian_date > $last_julian_date_in_month} { set active_p f - } + } set ansi_date [dt_julian_to_ansi $julian_date] set pretty_date [lc_time_fmt $ansi_date %Q] - + if {$julian_date == $first_julian_date_of_month} { set day_number 1 } elseif {$julian_date == $last_julian_date_in_month + 1} { @@ -206,7 +214,7 @@ acs_KeypressGoto('$url#calendar',event); }); }] - + incr day_number incr day_of_week } @@ -220,18 +228,6 @@ set today_p f } - -set form_vars "" -foreach var $list_of_vars { - append form_vars "" -} - -ad_form -name choose_new_date -show_required_p f -has_edit 0 -has_submit 0 -form { - {new_date:date - {label ""} - {format {MM DD YYYY}}} -} - # Local variables: # mode: tcl # tcl-indent-level: 4