X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FSearch%2FCalendar.html;h=e6282b58ad8b30704f148a72f60fe77b0a6574c6;hb=90dc916d0dbd7eb7be3fe767d12faddc723e3506;hp=e5a1c28a5d26e976c549856076b9ca0ede6f03c2;hpb=d5933aea7be7beddc995fb35cdd034231d2c515f;p=freeside.git diff --git a/rt/share/html/Search/Calendar.html b/rt/share/html/Search/Calendar.html index e5a1c28a5..e6282b58a 100644 --- a/rt/share/html/Search/Calendar.html +++ b/rt/share/html/Search/Calendar.html @@ -7,125 +7,417 @@ $Order => undef $OrderBy => undef $RowsPerPage => undef $NewQuery => 0 +$WeekDay => undef +$WeekMonth => undef +$WeekYear => undef +$OrigMonth => undef +$OrigYear => undef +$Embed => undef +$DayDisplay => undef +@DayDisplayArgs => () </%args> +% my $title; +% if ( $WeekMonth ) { +% if ( $start->month == $end->month ) { +% $title = $rtdate->GetMonth( $start->month -1 ). ' '. +% $start->day. '-'. $end->day. ', '. $start->year; +% } elsif ( $start->year == $end->year ) { +% $title = +% $rtdate->GetMonth( $start->month -1 ). ' '. $start->day. ' - '. +% $rtdate->GetMonth( $end->month -1 ). ' '. $end->day. ', '. $end->year; +% } else { +% $title = +% $rtdate->GetMonth( $start->month -1 ).' '.$start->day.', '.$start->year. +% ' - '. +% $rtdate->GetMonth( $end->month -1 ). ' '.$end->day. ', '. $end->year; +% } +% } else { +% $title = $rtdate->GetMonth($Month) . " $Year" +% } + +% unless ( $Embed ) { + <& /Elements/Header, Title => $title &> -<& /Ticket/Elements/Tabs, - current_tab => "Search/Calendar.html?$QueryString", - Title => $title &> +<& /Elements/Tabs &> + +% } + <&| /Widgets/TitleBox, - title => loc('Calendar for ') . $rtdate->GetMonth($Month) . " $Year" , + title => loc('Calendar for '). $title, title_class=> 'inverse', color => "#993333" &> -<table width="100%"> -<tr> -<td align="left"> -% my ($PMonth, $PYear) = ($Month - 1, $Year); +% my($PMonth, $PYear, $NMonth, $NYear); +% unless ( $WeekDay ) { + + <table width="100%"> + <tr> + <td align="left"> +% ($PMonth, $PYear) = ($Month - 1, $Year); % if ($PMonth < 0) { % $PYear--; % $PMonth = 11; % } -<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a> -</td> -<td align="center"> -<a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a> -</td> -<td align="right"> -% my ($NMonth, $NYear) = ($Month + 1, $Year); + <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a> + </td> + <th align="center"> + <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font> + </th> + <td align="right"> +% ($NMonth, $NYear) = ($Month + 1, $Year); % if ($NMonth > 11) { % $NYear++; % $NMonth = 0; % } -<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a> -</td> -</tr> -</table> + <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a> + </td> + </tr> + </table> +% } <table class="rtxcalendar"> + <thead> <tr> -<th></th> +<td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td> % for ( @{$week{$weekstart}} ) { -<th width="14%"><%$rtdate->GetWeekday($_)%></th> +<th width="14%" colspan=<% $WeekDay ? $slots : 1 %>><%$rtdate->GetWeekday($_)%></th> % } </tr> </thead> + <tbody> <tr> -% while ($date <= $end) { -% if ( $date->day_of_week == $startday_of_week ) { -<th><% $date->week_number %></th> -% } -<td class="<% $date->month != ($Month + 1) ? 'oddline' : '' %>" - style="width:14%;<% DateTime->compare($today, $date) == 0 ? 'background:#f6f7f8;' : '' %>" -> -<p class="date"><%$date->day%></p> -% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { -<& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &> -% } -</td> -% $date = $set->next($date); -% if ( $date->day_of_week == $startday_of_week ) { -</tr><tr> + +% if ( $WeekDay ) { + <td class="controls" rowspan=<% $rowspan+1 %> valign="middle"> + <& week_collapse, date=>$start, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &> + </td> + </td> +% } else { + <& td_week_expand, date=>$start, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &> % } + +% if ( $WeekDay ) { + + <td class="labels"></td> + +% my $date = $start; +% while ($date <= $end) { +% +% my $is_today = (DateTime->compare($today, $date) == 0); +% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0); +% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0); + + <td colspan=<%$slots%> + class="weekly + <% $is_today ? 'today' + : $is_yesterday ? 'yesterday' + : $is_aweekago ? 'aweekago' + : '' + %>" + > + <div class="<% $is_today ? 'todays' + : '' + %>calendardate" + ><% $rtdate->GetMonth($date->month-1). ' '. $date->day %></div> + + </td> + +% $date = $set->next($date); +% if ( $date->day_of_week == $startday_of_week ) { + </tr> +% if ( $date <= $end ) { #a second week? not going to work for week view yet + <tr> + <td class="controls" rowspan=<% $rowspan + 1 %> valign="middle"> + <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &> + </td> +% } +% } + +% } #while ($date <= $end) + +% my $sday = 0; +% my @slots = ( [], [], [], [], [], [], [] ); +% foreach my $row ( @week_rows ) { + + <tr> + <& td_time, $row &> + +% $date = $start; +% $sday = 0; +% while ($date <= $end) { +% +% my $is_today = (DateTime->compare($today, $date) == 0); +% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0); +% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0); + +%# <td colspan=<%$slots%> +%# class="<% $is_today ? 'today' +%# : $is_yesterday ? 'yesterday' +%# : $is_aweekago ? 'aweekago' +%# : '' +%# %>" +%# > + +% #XXX display these in a time aware fashion +%#% my $sp = 3; +%#% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { +%#% $sp--; +%# <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &> +%#% } +%# <% ($sp>0) ? '<BR>'x$sp : '' |n %> + +% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { +% +% #XXX off by 1h on daylight savings boundaries... two sundays a year +% my $starts = ($t->StartsObj->Unix - $t->StartsObj->SetToMidnight(Timezone=>'user'))/60; +% +% if ( $starts >= $row && $starts < ($row + $timestep) ) { +% #then we're a new entry, find a slot for us +% my $s = 0; +% while ( ref($slots[$sday]->[$s]) ) { $s++ } +% $slots[$sday]->[$s] = [ $t->Id, $t ]; +% } +% +% #XXX also off by 1h on daylight savings boundaries +% my $due = $t->DueObj->Unix - $t->DueObj->SetToMidnight; +% +% if ( $due <= $row && $due > ($row + $timestep ) ) { +% #then find our slot and remove us +% @{ $slots[$sday] } = +% map { (!ref($_) || $_->[0] != $t->Id) ? $_ : '' } +% @{ $slots[$sday] }; +% } +% +% } +% +% pop @{ $slots[$sday] } while @{ $slots[$sday] } && !ref($slots[$sday]->[-1]); +% +% #now display: +% +% if ( scalar(@{$slots[$sday]}) > $slots ) { +% #overflow situation, eek... could be handled better, how? + + <td colspan=<%$slots%> + class="weekly + <% $is_today ? 'today' + : $is_yesterday ? 'yesterday' + : $is_aweekago ? 'aweekago' + : '' + %>" + >MULTIPLE + </td> + +% } else { +% +% foreach my $slot ( @{ $slots[$sday] } ) { +% my( $id, $ticket ) = @$slot; + + <td class="weekly + <% $is_today ? 'today' + : $is_yesterday ? 'yesterday' + : $is_aweekago ? 'aweekago' + : '' + %>" + ><% $id %> + </td> + +% } +% +% if ( scalar(@{$slots[$sday]}) < $slots ) { + + <td colspan=<% $slots - scalar(@{$slots[$sday]}) %> + class="weekly + <% $is_today ? 'today' + : $is_yesterday ? 'yesterday' + : $is_aweekago ? 'aweekago' + : '' + %>" + > + </td> +% } +% +% } + +% $date = $set->next($date); +% if ( $date->day_of_week == $startday_of_week ) { + </tr> +% if ( $date <= $end ) { #a second week? not going to work for week view yet + <tr> + <td class="controls" rowspan=<% $rowspan + 1 %> valign="middle"> + <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &> + </td> +% } +% } +% +% $sday++; +% } #while ($date <= $end) +% } #foreach my $row ( @week_rows ) +% +% } else { +% +% my $date = $start; +% while ($date <= $end) { +% +% my $offmonth = !$WeekDay && $date->month != ($Month + 1); +% my $is_today = (DateTime->compare($today, $date) == 0); +% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0); +% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0); + + <td + class="<% $offmonth ? 'offmonth' + : $is_today ? 'today' + : $is_yesterday ? 'yesterday' + : $is_aweekago ? 'aweekago' + : '' + %>" + > + <div class="<% $is_today ? 'todays' + : $offmonth ? 'offmonth' + : '' + %>calendardate" + ><% $date->day %></div> + +% if ( defined($DayDisplay) && $DayDisplay =~ /^(\w+)$/ ) { +% +% my $el = "/Elements/CalendarDay$1"; + <& $el, Tickets => $Tickets{$date->strftime("%F")}, + Date => $date, + DateTypes => \%DateTypes, + @DayDisplayArgs, + &> +% +% } else { +% +% my $sp = 3; +% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { +% $sp--; + <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &> +% } + <% ($sp>0) ? '<BR>'x$sp : '' |n %> +% +% } + + </td> + +% $date = $set->next($date); +% if ( $date->day_of_week == $startday_of_week ) { + </tr> +% if ( $date <= $end ) { + <tr> + <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &> +% } +% } + +% } #while ($date <= $end) + % } -</tr> </tbody> </table> -<table width="100%"> -<tr> -<td align="left"> -<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a> -</td> -<td align="right"> -<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a> -</td> -</tr> -</table> +% unless ( $WeekDay ) { + <table width="100%"> + <tr> + <td align="left"> + <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a> + </td> -<table width="100%"> -<tr> -<td valign="top" align="center" width="80%"> -<form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post"> + <td valign="top" align="center"> + <form action="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?<%$QueryString%>" method="post"> + + <select name="Month"> +% for (0..11) { + <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option> +% } + </select> + +% my $year = (localtime)[5] + 1900; + <select name="Year"> +% for ( ($year-5) .. ($year+5)) { + <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option> +% } + </select> + +%# <& /Elements/Submit&> + <input type="submit" value="<% loc('Submit') %>" class="button" /> + + </form> + </td> + + <td align="right"> + <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a> + </td> + </tr> + </table> -<select name="Month"> -% for (0..11) { -<option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option> -% } -</select> -% my $year = (localtime)[5] + 1900; -<select name="Year"> -% for ( ($year-5) .. ($year+5)) { -<option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option> % } -</select> -<& /Elements/Submit&> -</form> -</td> -<td valign="top" width="50%" align="right"> -<img src="<%$RT::WebImagesURL%>/created.png" /> : <&|/l&>Created</&><br /> -<img src="<%$RT::WebImagesURL%>/due.png" /> : <&|/l&>Due</&><br /> -<img src="<%$RT::WebImagesURL%>/resolved.png" /> : <&|/l&>Resolved</&><br /> -<img src="<%$RT::WebImagesURL%>/updated.png" /> : <&|/l&>Last Updated</&><br /> -<img src="<%$RT::WebImagesURL%>/created_due.png" /> : <&|/l&>Created</&>, <&|/l&>Due</&><br /> -<img src="<%$RT::WebImagesURL%>/reminder.png" /> : <&|/l&>Reminders</&><br /> -<img src="<%$RT::WebImagesURL%>/starts.png" /> : <&|/l&>Starts</&><br /> -<img src="<%$RT::WebImagesURL%>/started.png" /> : <&|/l&>Started</&><br /> -<img src="<%$RT::WebImagesURL%>/starts_due.png" /> : <&|/l&>Starts</&>, <&|/l&>Due</&><br /> +% unless ( $Embed ) { +<table width="100%"> +<tr> +<td valign="top" rowspan=9> + <BR> + <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a> </td> + +% foreach my $legend (keys %legend) { + <tr> + <td align="right"> + <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" /> + </td> + <td align="left"> +% my $more = 0; +% foreach ( @{$legend{$legend}} ) { + <% $more++ ? ', ' : '' %> + <&|/l&><% $_ %></&> +% } + </td> + </tr> +% } + </table> +% } + </&> -</html> +<%ONCE> + +my %legend = ( + 'created' => ['Created'], + 'due' => ['Due'], + 'resolved' => ['Resolved'], + 'updated' => ['Last Updated'], + 'created_due' => ['Created','Due'], + 'reminder' => ['Reminders'], + 'started' => ['Started'], + 'starts_due' => ['Starts','Due'], +); + +my $stime = RT->Config->Get('CalendarWeeklyStartMin'); +$stime = 480 unless $stime =~ /^\d+$/; #8am +my $etime = RT->Config->Get('CalendarWeeklyEndMin'); +$etime = 1080 unless $etime =~ /^\d+$/; #6pm + +my $timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h +my $rowspan = ($etime-$stime) / $timestep; + +my $slots = RT->Config->Get('CalendarWeeklySlots') || 5; + +my $wt = $stime; +my @week_rows = (); +while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep } + +</%ONCE> <%INIT> -use RTx::Calendar qw(FirstDay LastDay); +use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek); + +$Embed =~ /^[\w\.]+$/ or die 'xss'; my $title = loc("Calendar"); @@ -133,6 +425,9 @@ my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/; my $rtdate = RT::Date->new($session{'CurrentUser'}); +my $time_zone = $session{'CurrentUser'}->UserObj->Timezone + || RT->Config->Get('Timezone'); + my $weekstart = 'Sunday'; #RT::SiteConfig? user pref? my %week = ( 'Saturday' => [6,0..5], @@ -142,33 +437,54 @@ my %week = ( my $startday_of_week = ${$week{$weekstart}}[0] || 7; my $endday_of_week = ${$week{$weekstart}}[-1] || 7; -my $today = DateTime->today; -my $date = FirstDay($Year, $Month + 1, $startday_of_week ); -my $end = LastDay ($Year, $Month + 1, $endday_of_week ); +my $today = DateTime->today( time_zone=>$time_zone ); +my $yesterday = $today->clone->subtract( days=>1 ); +my $aweekago = $today->clone->subtract( days=>7 ); + +my( $start, $end ); +if ( $WeekDay ) { + $start = DateTime->new( year => $WeekYear, + month => $WeekMonth+1, + day => $WeekDay, + time_zone => $time_zone, + ); + $end = LastDayOfWeek( $WeekYear, $WeekMonth+1, $WeekDay, $endday_of_week ); +} else { + $start = FirstDay($Year, $Month + 1, $startday_of_week ); + $end = LastDay ($Year, $Month + 1, $endday_of_week ); +} # use this to loop over days until $end my $set = DateTime::Set->from_recurrence( next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } ); -my $QueryString = +my $QueryString; +if ($Query) { + $QueryString = $m->comp( '/Elements/QueryString', Query => $Query, Format => $Format, Order => $Order, OrderBy => $OrderBy, - Rows => $RowsPerPage - ) - if ($Query); - -$QueryString ||= 'NewQuery=1'; + Rows => $RowsPerPage, + @DayDisplayArgs, + ); +} else { + $QueryString = + $m->comp( + '/Elements/QueryString', + NewQuery => 1, + @DayDisplayArgs, + ); +} # Default Query and Format my $TempFormat = "__Starts__ __Due__"; my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled') AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' ) - AND ( Type = 'reminder' OR 'Type' = 'ticket' )"; + AND ( Type = 'reminder' OR 'Type' = 'ticket' )"; if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) { $TempFormat = $Search->SubValue('Format'); @@ -185,10 +501,57 @@ my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes; # used to display or not a date in Element/CalendarEvent my %DateTypes = map { $_ => 1 } @Dates; -$TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F")); +$TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F")); # print STDERR ("-" x 30), "\n", $TempQuery, "\n"; -my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F")); +my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F")); </%INIT> +<%def td_week_expand> +<%args> + $date => undef + $Month => undef + $Year => undef + $QueryString => undef + $Embed => undef +</%args> + <td class="controls"> + <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?WeekDay=<% $date->day %>&WeekMonth=<% $date->month -1 %>&WeekYear=<% $date->year %>&OrigMonth=<% $Month %>&OrigYear=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-expand.gif"></a> + </td> +</%def> + +<%def week_collapse> +<%args> + $date => undef + $Month => undef + $Year => undef + $QueryString => undef + $Embed => undef +</%args> + <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<% $Month %>&Year=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-collapse.gif" STYLE="height:384px;width:11px"></a> +</%def> + +<%def td_time> +% my( $min ) = shift; + <td class="labels"><% pretty_time($min) |n %></td> +<%init> +sub pretty_time { + my $t = shift; + + return 'Midnight' if $t == 0 || $t == 1440; + return 'Noon' if $t == 720; + + my $h = int( $t / 60 ); + my $m = $t % 60; + + my $ap = 'AM'; + if ( $h == 0 || $h == 24 ) { $h = 12; } + elsif ( $h == 12 ) { $ap = 'PM'; } + elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; } + + sprintf('%02d:%02d '.$ap, $h, $m); + +} +</%init> +</%def>