Index: openacs-4/packages/calendar/www/view-one-day-display.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/www/view-one-day-display.tcl,v diff -u -r1.34 -r1.35 --- openacs-4/packages/calendar/www/view-one-day-display.tcl 16 Aug 2006 17:52:14 -0000 1.34 +++ openacs-4/packages/calendar/www/view-one-day-display.tcl 15 May 2007 20:14:21 -0000 1.35 @@ -1,3 +1,24 @@ +# FIXME from sloanspace calendar, they have added a system_type attribute to +# cal_items table, which can be null, class, community, or personal +# this is used to figure out which CSS class to use, for now we set to +# empty string to use generic cal-Item css class DAVEB 20070121 +set system_type "" + +#Expects: +# date (required but empty string okay): YYYY-MM-DD +# show_calendar_name_p (optional): 0 or 1 +# start_display_hour (optional): 0-23 +# end_display_hour (optional): 0-23 +# url_stub_callback (optional): + +#Display constants, should match up with default styles in calendar.css. +set hour_height_inside 43 +set hour_height_sep 3 +set hour_height_units px +set bump_right_base 0 +set bump_right_delta 35 +set bump_right_units px + if {[info exists url_stub_callback]} { # This parameter is only set if this file is called from .LRN. # This way I make sure that for the time being this adp/tcl @@ -8,18 +29,15 @@ } set current_date $date -if {![info exists return_url]} { - set return_url [ad_urlencode "../"] -} if {[info exists portlet_mode_p] && $portlet_mode_p} { - set item_template "\${url_stub}cal-item-view?show_cal_nav=0&return_url=${return_url}&action=edit&cal_item_id=\$item_id" + set event_url_template "\${url_stub}cal-item-view?show_cal_nav=0&return_url=[ad_urlencode "../"]&action=edit&cal_item_id=\$item_id" set url_stub_callback "calendar_portlet_display::get_url_stub" - set hour_template "calendar/cal-item-new?date=$current_date&start_time=\$day_current_hour&return_url=$return_url" + set hour_template "calendar/cal-item-new?date=$current_date&start_time=\$grid_hour" } else { - set item_template "cal-item-view?cal_item_id=\$item_id" + set event_url_template "cal-item-view?cal_item_id=\$item_id" set url_stub_callback "" - set hour_template {cal-item-new?date=$current_date&start_time=$day_current_hour&return_url=$return_url} + set hour_template {cal-item-new?date=$current_date&start_time=$grid_hour} } if { ![info exists show_calendar_name_p] } { @@ -47,190 +65,174 @@ set date [lc_time_fmt $user_now_time "%F"] } - set package_id [ad_conn package_id] set user_id [ad_conn user_id] -# Loop through the items without time -multirow create items_without_time \ + +multirow create items \ + all_day_p \ + style_class \ event_name \ event_url \ + description \ calendar_name \ - status_summary + weekday \ + start_date \ + end_date \ + start_time \ + end_time \ + top \ + height \ + style +set previous_intervals [list] + +# Loop through the items without time + set additional_limitations_clause " and to_char(start_date, 'HH24:MI') = '00:00' and to_char(end_date, 'HH24:MI') = '00:00'" +if { [exists_and_not_null cal_system_type] } { + append additional_limitations_clause " and system_type = :cal_system_type " +} set additional_select_clause "" set order_by_clause " order by name" set interval_limitation_clause [db_map dbqd.calendar.www.views.day_interval_limitation] #AG: the "select_all_day_items" query is identical to "select_items" #just without the Oracle +ORDERED hint, which speeds every other #query but slows this one. -db_foreach dbqd.calendar.www.views.select_items {} { - # reset url stub - set url_stub "" +db_foreach dbqd.calendar.www.views.select_all_day_items {} { + + # Localize + set pretty_weekday [lc_time_fmt $ansi_start_date "%A"] + set pretty_start_date [lc_time_fmt $ansi_start_date "%x"] + set pretty_end_date [lc_time_fmt $ansi_end_date "%x"] + set pretty_start_time [lc_time_fmt $ansi_start_date "%X"] + set pretty_end_time [lc_time_fmt $ansi_end_date "%X"] - # In case we need to dispatch to a different URL (ben) + # In case we need to dispatch to a different URL (ben). + # The calculated url_stub is fed back into the event_url_template. + set url_stub "" if {![empty_string_p $url_stub_callback]} { - # Cache the stuff + # Cache the url stub lookup. if {![info exists url_stubs($calendar_id)]} { set url_stubs($calendar_id) [$url_stub_callback $calendar_id] } - set url_stub $url_stubs($calendar_id) + set url_stub $url_stubs($calendar_id) } - - set event_url [subst $item_template] - multirow append items_without_time $name $event_url $calendar_name $status_summary -} + #height will be overwritten once we know how the vertical hour span. + multirow append items 1 "calendar-${system_type}Item" \ + $name \ + [subst $event_url_template] \ + $description \ + $calendar_name \ + $pretty_weekday \ + $pretty_start_date \ + $pretty_end_date \ + $pretty_start_time \ + $pretty_end_time \ + 0 \ + 0 \ + "left: ${bump_right_base}${bump_right_units};" - -set day_current_hour 0 -set localized_day_current_hour "" -set item_add_without_time [subst $hour_template] - -# Now items with time -multirow create items \ - event_name \ - event_url \ - calendar_name \ - status_summary \ - add_url \ - localized_current_hour \ - current_hour \ - start_time \ - end_time \ - colspan \ - rowspan - -for {set i 0 } { $i < 24 } { incr i } { - set items_per_hour($i) 0 + incr bump_right_base $bump_right_delta } - set additional_limitations_clause " and (to_char(start_date, 'HH24:MI') <> '00:00' or to_char(end_date, 'HH24:MI') <> '00:00')" +if { [exists_and_not_null cal_system_type] } { + append additional_limitations_clause " and system_type = :cal_system_type " +} set order_by_clause " order by to_char(start_date,'HH24')" set day_items_per_hour {} +set adjusted_start_display_hour $start_display_hour +set adjusted_end_display_hour $end_display_hour + db_foreach dbqd.calendar.www.views.select_items {} { set ansi_start_date [lc_time_system_to_conn $ansi_start_date] set ansi_end_date [lc_time_system_to_conn $ansi_end_date] + # Localize + set pretty_weekday [lc_time_fmt $ansi_start_date "%A"] + set pretty_start_date [lc_time_fmt $ansi_start_date "%x"] + set pretty_end_date [lc_time_fmt $ansi_end_date "%x"] + set pretty_start_time [lc_time_fmt $ansi_start_date "%X"] + set pretty_end_time [lc_time_fmt $ansi_end_date "%X"] + set start_time [lc_time_fmt $ansi_start_date "%X"] set end_time [lc_time_fmt $ansi_end_date "%X"] - if {($start_hour == $end_hour) || ($end_minutes > 0)} { - incr end_hour + if { $start_hour < $adjusted_start_display_hour && \ + [string equal \ + [string range $ansi_start_date 0 9] \ + [string range $ansi_end_date 0 9]] } { + set adjusted_start_display_hour $start_hour } - for { set item_current_hour $start_hour } { $item_current_hour < $end_hour } { incr item_current_hour } { - set item_current_hour [expr [string trimleft $item_current_hour 0]+0] - - if { $start_hour == $item_current_hour } { - - lappend day_items_per_hour \ - [list $item_current_hour $name $item_id $calendar_name $status_summary $start_hour $end_hour $start_time $end_time $calendar_id] - } else { - lappend day_items_per_hour \ - [list $item_current_hour {} $item_id $calendar_name $status_summary $start_hour $end_hour $start_time $end_time $calendar_id] - } - incr items_per_hour($item_current_hour) + if { $end_hour > $adjusted_end_display_hour && \ + [string equal \ + [string range $ansi_start_date 0 9] \ + [string range $ansi_end_date 0 9]] } { + set adjusted_end_display_hour $end_hour } -} -set day_items_per_hour [lsort -command calendar::compare_day_items_by_current_hour $day_items_per_hour] -set day_current_hour $start_display_hour + set top [expr ($start_hour * ($hour_height_inside+$hour_height_sep)) \ + + ($start_minutes*$hour_height_inside/60)] + set bottom [expr ($end_hour * ($hour_height_inside+$hour_height_sep)) \ + + ($end_minutes*$hour_height_inside/60)] + set height [expr $bottom - $top - 2] -# Get the maximum items per hour -set max_items_per_hour 0 -for {set i $start_display_hour } { $i < $end_display_hour } { incr i } { - if {$items_per_hour($i) > $max_items_per_hour} { - set max_items_per_hour $items_per_hour($i) - } -} - -foreach this_item $day_items_per_hour { - set item_start_hour [expr [string trimleft [lindex $this_item 5] 0]+0] - set item_end_hour [expr [string trimleft [lindex $this_item 6] 0]+0] - set rowspan [expr $item_end_hour - $item_start_hour] - if {$item_start_hour > $day_current_hour && \ - $item_start_hour >= $start_display_hour} { - # need to add dummy entries to show all hours - - for { } { $day_current_hour < $item_start_hour } { incr day_current_hour } { - set localized_day_current_hour [lc_time_fmt "$current_date $day_current_hour:00:00" "%X"] - multirow append items \ - "" \ - "" \ - "" \ - "" \ - [subst $hour_template] \ - $localized_day_current_hour \ - $day_current_hour \ - 0 \ - 0 \ - "" \ - "" + set bump_right $bump_right_base + foreach {previous_start previous_end} $previous_intervals { + if { ($start_seconds >= $previous_start && $start_seconds < $previous_end) || ($previous_start >= $start_seconds && $previous_start < $end_seconds) } { + incr bump_right $bump_right_delta } } - set day_current_hour [lindex $this_item 0] - set localized_day_current_hour [lc_time_fmt "$current_date $day_current_hour:00:00" "%X"] - - # reset url stub + # In case we need to dispatch to a different URL (ben). + # The calculated url_stub is fed back into the event_url_template. set url_stub "" - - # In case we need to dispatch to a different URL (ben) if {![empty_string_p $url_stub_callback]} { - # Cache the stuff - - if {![info exists url_stubs([lindex $this_item 9])]} { - set url_stubs([lindex $this_item 9]) [$url_stub_callback [lindex $this_item 9]] + # Cache the url stub lookup. + if {![info exists url_stubs($calendar_id)]} { + set url_stubs($calendar_id) [$url_stub_callback $calendar_id] } - set url_stub $url_stubs([lindex $this_item 9]) + set url_stub $url_stubs($calendar_id) } - - set item [lindex $this_item 1] - set item_id [lindex $this_item 2] - - set current_hour_link [subst $hour_template] - - multirow append items \ - $item \ - [subst $item_template] \ - [lindex $this_item 3] \ - [lindex $this_item 4] \ - $current_hour_link \ - $localized_day_current_hour \ - $day_current_hour \ - [lindex $this_item 7] \ - [lindex $this_item 8] \ - 0 \ - $rowspan - - set day_current_hour [expr [lindex $this_item 0] +1 ] + multirow append items 0 "calendar-${system_type}Item" \ + "$name ($start_time - $end_time)" \ + [subst $event_url_template] \ + $description \ + $calendar_name \ + $pretty_weekday \ + $pretty_start_date \ + $pretty_end_date \ + $pretty_start_time \ + $pretty_end_time \ + $top \ + $height \ + "left: ${bump_right}${bump_right_units};" + + lappend previous_intervals $start_seconds $end_seconds } -if {$day_current_hour < $end_display_hour } { - # need to add dummy entries to show all hours - for { } { $day_current_hour < $end_display_hour } { incr day_current_hour } { - set localized_day_current_hour [lc_time_fmt "$current_date $day_current_hour:00:00" "%X" [ad_conn locale]] - multirow append items \ - "" \ - "" \ - "" \ - "" \ - "[subst $hour_template]" \ - $localized_day_current_hour \ - $day_current_hour \ - "" \ - 0 \ - 0 +#Now correct the top attribute for the adjusted start. +if { $adjusted_start_display_hour != 0 } { + set num_items [multirow size items] + for {set i 1} {$i <= $num_items } {incr i} { + if { [multirow get items $i all_day_p] } { + multirow set items $i height \ + [expr ($adjusted_end_display_hour-$adjusted_start_display_hour+1)*($hour_height_inside+$hour_height_sep)] + } else { + set currval [multirow get items $i top] + multirow set items $i top \ + [expr $currval - ($adjusted_start_display_hour*($hour_height_inside+$hour_height_sep))] + } } } @@ -244,3 +246,26 @@ set next_week_url "view?view=day&date=[ns_urlencode $tomorrow]" } set dates [lc_time_fmt $date "%q"] +set curr_day_name [lc_time_fmt $date "%A"] +set curr_month [lc_time_fmt $date "%B"] +set curr_day [lc_time_fmt $date "%d"] +set curr_year [lc_time_fmt $date "%Y"] + +#Calendar grid. +set grid_start $adjusted_start_display_hour +set grid_first_hour [lc_time_fmt "$current_date $grid_start:00:00" "%X"] +set grid_hour $grid_start +set grid_first_add_url [subst $hour_template] +incr grid_start + +multirow create grid hour add_url +for { set grid_hour $grid_start } { $grid_hour <= $adjusted_end_display_hour } { incr grid_hour } { + set localized_grid_hour [lc_time_fmt "$current_date $grid_hour:00:00" "%X"] + multirow append grid $localized_grid_hour [subst $hour_template] +} + +if { [info exists export] && [string equal $export print] } { + set print_html [template::adp_parse [acs_root_dir]/packages/calendar/www/view-print-display [list &items items show_calendar_name_p $show_calendar_name_p]] + ns_return 200 text/html $print_html + ad_script_abort +}