appointment drag and drop, RT#34237
[freeside.git] / rt / share / html / Search / Calendar.html
index e6282b5..2c19296 100644 (file)
@@ -1,21 +1,23 @@
-<%args>
-$Month => (localtime)[4]
-$Year => (localtime)[5] + 1900
-$Query => undef
-$Format => undef
-$Order => undef
-$OrderBy => undef
+<%ARGS>
+$Month       => (localtime)[4]
+$Year        => (localtime)[5] + 1900
+$Query       => undef
+$Format      => undef
+$Order       => undef
+$OrderBy     => undef
 $RowsPerPage => undef
-$NewQuery => 0
-$WeekDay => undef
-$WeekMonth => undef
-$WeekYear => undef
-$OrigMonth => undef
-$OrigYear => undef
-$Embed => undef
-$DayDisplay => undef
-@DayDisplayArgs => ()
-</%args>
+$NewQuery    => 0
+$WeekDay     => undef
+$WeekMonth   => undef
+$WeekYear    => undef
+$OrigMonth   => undef
+$OrigYear    => undef
+$Embed       => undef
+$Display     => undef
+@DisplayArgs => ()
+$slots       => $default_slots
+$DimPast     => 0
+</%ARGS>
 
 % my $title;
 % if ( $WeekMonth ) {
@@ -76,61 +78,63 @@ $DayDisplay => undef
     </table>
 % }
 
-<table class="rtxcalendar">
+<table class="<% $WeekDay ? 'rtxweeklycalendar' : 'rtxcalendar' %>">
+
+  <thead>
+
+% unless ( $WeekDay ) {
+
+    <tr>
+      <td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td>
+%     for ( @{$week{$weekstart}} ) {
+        <th colspan=<% $WeekDay ? $slots : 1 %>><%$rtdate->GetWeekday($_)%></th>
+%     }
+    </tr>
+  </thead>
+  <tbody>
 
-<thead>
-<tr>
-<td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td>
-% for ( @{$week{$weekstart}} ) {
-<th width="14%" colspan=<% $WeekDay ? $slots : 1 %>><%$rtdate->GetWeekday($_)%></th>
 % }
-</tr>
-</thead>
 
-<tbody>
 <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 {
+% unless ( $WeekDay ) {
   <& td_week_expand, date=>$start, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
 % }
 
 % if ( $WeekDay ) {
 
-    <td class="labels"></td>
+    <td class="labels" colspan=2></td>
 
 %   my $date = $start;
+%   my $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="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>
+      <th colspan=<%$slots%>
+          class="labels"
+%#                 <%   $is_today     ? 'today'
+%#                    : $is_yesterday ? 'yesterday'
+%#                    : $is_aweekago  ? 'aweekago'
+%#                    : ''
+%#                 %>"
+%#        <div class="<%   $is_today ? 'todays'
+%#                       : ''
+%#                    %>calendardate"
+      ><% $rtdate->GetWeekday( $week{$weekstart}->[$sday++] ). ' '.
+          $rtdate->GetMonth($date->month-1). ' '.
+          $date->day
+       %>
+      </th>
 
 %     $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">
+              <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
                 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
               </td>
 %       }
@@ -138,115 +142,93 @@ $DayDisplay => undef
 
 %   } #while ($date <= $end)
 
-%   my $sday = 0;
-%   my @slots = ( [], [], [], [], [], [], [] );
+    </tr>
+
+        </thead>
+        <tbody>
+
+    <tr>
+
+  <td class="controls" rowspan=<% $rowspan+1 %> valign="middle">
+    <& week_collapse, date=>$start, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
+  </td>
+
+%     #slot header callback
+%     if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
+%
+%       my $el = "/Elements/CalendarSlotHeader$1";
+        <td class="labels"></td>
+%       for (0..6) {
+          <& $el, Date      => $date,
+                  DateTypes => \%DateTypes,
+                  slots     => $slots,
+                  @DisplayArgs,
+          &>
+%       }
+%     }
+    </tr>
+
 %   foreach my $row ( @week_rows ) {
 
       <tr>
       <& td_time, $row &>
 
 %     $date = $start;
-%     $sday = 0;
+%     my $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 ];
-%         }
+%     #slot callback
+%     if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
+%       my $el = "/Elements/CalendarSlot$1";
+        <& $el, Date      => $date,
+                DateTypes => \%DateTypes,
+                Tickets   => $Tickets{$date->strftime("%F")} || [],
+                slots     => $slots,
+                sday      => $sday,
+                tod_row   => $row,
+                timestep  => $timestep,
+                @DisplayArgs,
+        &>
+%     } else {
+
+%       #just display the normal events for this day?
+        <td class="weekly" colspan="<%$slots%>">
+%         for my $Ticket ( @{ $Tickets{$date->strftime("%F")} } ) {
+%           my %dt =
+%             map { $_=>1 }
+%             grep {
+%               my $meth = $_.'Obj';
 %
-%         #XXX also off by 1h on daylight savings boundaries
-%         my $due = $t->DueObj->Unix - $t->DueObj->SetToMidnight;
+%               my($m, $h) = ($Ticket->$meth->Localtime('user'))[1,2];
+%               my $tod = $h*60 + $m;
 %
-%         if ( $due <= $row && $due > ($row + $timestep ) ) {
-%           #then find our slot and remove us
-%           @{ $slots[$sday] } =
-%             map { (!ref($_) || $_->[0] != $t->Id) ? $_ : '' }
-%               @{ $slots[$sday] };
+%               LocalDate($Ticket->$meth->Unix) eq $date->strftime('%F') #today
+%                 && $tod >= $row && $tod < ($row+$timestep); #and in timeslot
+%             } keys %DateTypes;
+%           next unless keys %dt;
+            <& /Elements/CalendarEvent,
+                 Object    => $Ticket,
+                 Date      => $date,
+                 DateTypes => \%dt
+            &>
+%           unless ( $Ticket eq ${ $Tickets{$date->strftime("%F")} }[-1] ) { #hmm, no.. not with "next unless $dt" :/
+              <BR>
+%           }
 %         }
-%
-%       }
-%
-%       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>
+        </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">
+              <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
                   <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
                 </td>
 %         }
@@ -254,6 +236,7 @@ $DayDisplay => undef
 %
 %       $sday++;
 %     } #while ($date <= $end)
+      </tr>
 %   } #foreach my $row ( @week_rows )
 %
 % } else {
@@ -265,28 +248,31 @@ $DayDisplay => undef
 %     my $is_today     = (DateTime->compare($today,     $date) == 0);
 %     my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
 %     my $is_aweekago  = (DateTime->compare($aweekago,  $date) == 0);
+%
+%     my $past = $DimPast && DateTime->compare($today,  $date) == 1;
 
       <td
-          class="<%   $offmonth     ? 'offmonth'
-                    : $is_today     ? 'today'
-                    : $is_yesterday ? 'yesterday'
-                    : $is_aweekago  ? 'aweekago'
+          class="<% $past ? 'past' : '' %><% $offmonth ? 'offmonth' : '' %><%
+                      $is_today     ? ' today'
+                    : $is_yesterday ? ' yesterday'
+                    : $is_aweekago  ? ' aweekago'
                     : ''
                  %>"
       >
         <div class="<%   $is_today ? 'todays'
-                       : $offmonth ? 'offmonth'
-                       : ''
+                       : ( $past ? 'past' : ''). ($offmonth ? 'offmonth' : '' )
                     %>calendardate"
         ><% $date->day %></div>
 
-%       if ( defined($DayDisplay) && $DayDisplay =~ /^(\w+)$/ ) {
+%       if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
 %
 %         my $el = "/Elements/CalendarDay$1";
-          <& $el, Tickets   => $Tickets{$date->strftime("%F")},
-                  Date      => $date,
-                  DateTypes => \%DateTypes,
-                  @DayDisplayArgs,
+          <& $el, CurrentUser => $session{CurrentUser},
+                  Tickets     => $Tickets{$date->strftime("%F")},
+                  Date        => $date,
+                  today       => $today,
+                  DateTypes   => \%DateTypes,
+                  @DisplayArgs,
           &>
 %
 %       } else {
@@ -407,7 +393,7 @@ $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 $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
 
 my $wt = $stime;
 my @week_rows = ();
@@ -415,9 +401,10 @@ while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
 
 </%ONCE>
 <%INIT>
-use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
+use RTx::Calendar qw( FirstDay LastDay LastDayOfWeek DatesClauses LocalDate
+                      SearchDefaultCalendar FindTickets );
 
-$Embed =~ /^[\w\.]+$/ or die 'xss';
+$Embed =~ /^[\w\.]*$/ or die 'xss';
 
 my $title = loc("Calendar");
 
@@ -469,14 +456,14 @@ if ($Query) {
         Order   => $Order,
         OrderBy => $OrderBy,
         Rows    => $RowsPerPage,
-        @DayDisplayArgs,
+        @DisplayArgs,
       );
 } else {
   $QueryString =
       $m->comp(
         '/Elements/QueryString',
         NewQuery => 1,
-        @DayDisplayArgs,
+        @DisplayArgs,
       );
 }
 
@@ -486,7 +473,7 @@ my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
  AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody'  )
  AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
 
-if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
+if ( my $Search = SearchDefaultCalendar($session{CurrentUser}) ) {
   $TempFormat = $Search->SubValue('Format');
   $TempQuery = $Search->SubValue('Query');
 }
@@ -501,11 +488,11 @@ 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, $start->strftime("%F"), $end->strftime("%F"));
+$TempQuery .= DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F"));
 
 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
 
-my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
+my %Tickets = FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
 
 </%INIT>
 <%def td_week_expand>
@@ -529,7 +516,7 @@ my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@
   $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>
+    <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;border:none"></a>
 </%def>
 
 <%def td_time>