installers (calendaring), RT#16584
[freeside.git] / rt / share / html / Elements / CalendarSlotSchedule
index 3af90ff..5b40040 100644 (file)
@@ -1,46 +1,68 @@
 <%ARGS>
-  $Date     => undef
-  @Tickets  => ()
-  $slots    => $default_slots
-  $sday     => undef
-  $tod_row  => undef
-  $timestep => $default_timestep
-  @username => ()
+  $Date      => undef
+  @Tickets   => ()
+  $slots     => $default_slots
+  $sday      => undef
+  $tod_row   => undef
+  $timestep  => $default_timestep
+  @username  => ()
+  $LengthMin => $default_timestep
 </%ARGS>
 % foreach my $username ( @username ) {
+%
+%   my %schedule = UserDaySchedule( username => $username,
+%                                   'date'   => $Date->strftime('%F'),
+%                                   Tickets  => \@Tickets,
+%                                 );
+%
+%   my $bgcolor = '666666;border-color:#555555';
+%   my $content = '';
+%   my $onmouse = 0;
+%
+%   #white out available times
+%   foreach my $avail ( @{ $schedule{'avail'} } ) {
+%     my( $start, $end ) = @$avail;
+%     next if $start >= ($tod_row+$timestep) || $end <= $tod_row;
+%     $bgcolor = 'FFFFFF';
+%     $onmouse = 1
+%       if $LengthMin <= $end - $tod_row  #the slot is long enough
+%       && ! grep { $_ > $tod_row && $LengthMin > $_ - $tod_row }
+%              map $_->[0], values %{ $schedule{'scheduled'} };
+%   }
+%
+%   #block out / show / color code existing appointments
+%   foreach my $id ( keys %{ $schedule{'scheduled'} } ) {
+%
+%     my( $starts, $due, $col, $t ) = @{ $schedule{'scheduled'}->{$id} };
+%
+%     next if $starts >= ($tod_row+$timestep) || $due < $tod_row;
+%
+%     $bgcolor = $col;
+%     $onmouse = 0;
+%
+%     if ( $starts >= $tod_row ) { #first row
+%       $content .= ($content?', ':''). $id; #XXX more
+%     }
+%   }
 
-    <td class="weekly
+    <td style="background:#<%$bgcolor%>" class="weekly"
 %#               <%   $is_today     ? 'today'
 %#                  : $is_yesterday ? 'yesterday'
 %#                  : $is_aweekago  ? 'aweekago'
 %#                  : ''
-%#               %>
-                   "
-    >
-%       for my $t (@Tickets) {
-%         next unless $t->OwnerObj->Name eq $username;
-%
-%         next unless RTx::Calendar::LocalDate($t->StartsObj->Unix)
-%                     eq $Date->strftime('%F'); #today
-%
-%         my($sm, $sh) = ($t->StartsObj->Localtime('user'))[1,2];
-%         my $starts = $sh*60 + $sm;
-%
-%         my($dm, $dh) = ($t->DueObj->Localtime('user'))[1,2];
-%         my $due = $dh*60 + $dm;
-%
-%         next if $starts >= ($tod_row+$timestep) || $due < $tod_row;
-%
-%         warn $starts. ' = '. ($tod_row+$timestep);
-%         if ( $starts >= $tod_row ) {
-            <% $t->Id %>
-%         } else {
-            cont<% $t->Id %>...
-%         }
-%       }
-    </td>
+%#               %>"
+%     if ( $onmouse ) {
+        onmouseover="boxon(this);"
+        onmouseout ="boxoff(this);"
+%     }
+    ><% $content %></td>
 % }
 <%ONCE>
 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
 my $default_timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
 </%ONCE>
+<%INIT>
+
+use RTx::Schedule qw( UserDaySchedule );
+
+</%INIT>