<%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
+ $custnum => undef
+ $pkgnum => undef
+ $RedirectToBasics => 0
</%ARGS>
-<%SHARED>
-my @slots = ( [], [], [], [], [], [], [] );
-</%SHARED>
-% #for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
-% for my $t (@Tickets) {
-%
-% my($sm, $sh) = ($t->StartsObj->Localtime('user'))[1,2];
-% my $starts = $sh*60 + $sm;
-%
-% if ( RTx::Calendar::LocalDate($t->StartsObj->Unix) eq $Date->strftime('%F') #today
-% && $starts >= $tod_row && $starts < ($tod_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 ];
-% }
-%
-% my($dm, $dh) = ($t->DueObj->Localtime('user'))[1,2];
-% my $due = $dh*60 + $dm;
-%
-% if ( RTx::Calendar::LocalDate($t->DueObj->Unix) eq $Date->strftime('%F') #today
-% && $due <= $tod_row && $due > ($tod_row + $timestep ) ) {
-% #then find our slot and remove us
-% @{ $slots[$sday] } =
-% map { (!ref($_) || $_->[0] != $t->Id) ? $_ : '' }
-% @{ $slots[$sday] };
-% }
+% foreach my $username ( @username ) {
%
-% }
+% my %schedule = UserDaySchedule( username => $username,
+% 'date' => $Date->strftime('%F'),
+% Tickets => \@Tickets,
+% );
+%
+% my $bgcolor = '666666;border-color:#555555';
+% my $content = '';
+% my $link = '';
+% my $selectable = 0;
+% my $draggable_ticketid = 0;
+% my $draggable_length = 0;
+% my $droppable = 0;
+% my $cells = 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';
+% $selectable = 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
+% #my %line = ();
+% 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;
+% $selectable = 0;
%
-% pop @{ $slots[$sday] } while @{ $slots[$sday] } && !ref($slots[$sday]->[-1]);
+% if ( $starts >= $tod_row ) { #first row
%
-% #now display:
+% #false laziness w/misc/xmlhttp-ticket-update.html & CalendarDaySchedule
+% my %hash = $m->comp('/Ticket/Elements/Customers', Ticket => $t);
+% my @cust_main = values( %{$hash{cust_main}} );
%
-% if ( scalar(@{$slots[$sday]}) > $slots ) {
-% #overflow situation, eek... could be handled better, how?
+% $content .= ($content?', ':''). #$id. ': '.
+% #false laziness w/xmlhttp-ticket-update.html
+% FS::sched_avail::pretty_time($starts). '-'.
+% FS::sched_avail::pretty_time($due).
+% ': '. $cust_main[0]->_FreesideURILabel;
+% #'install for custname XX miles away'; #XXX placeholder/more
+% $link = qq( <A HREF="$RT::WebPath/Ticket/Display.html?id=$id" target="_blank">view</A> ).
+% include('/elements/popup_link.html',
+% action=>$RT::WebPath.'/Ticket/ModifyCustomFieldsPopup.html?id='.$id,
+% label =>'edit',
+% actionlabel => 'Edit appointment',
+% height => 436, # better: A + B * (num_custom_fields)
+% );
+% $draggable_ticketid = $id;
+% $draggable_length = $due - $starts;
+%
+% $cells = int( ($due-$starts) / $timestep );
+% $cells++ if ($due-$starts) % $timestep;
+%
+% #} else {
+% # $content .= ($content?', ':''). $id;
+% }
+% }
+%
+% my $td_id = 'td_'. $Date->epoch. '_'. $tod_row. '_'. $username;
- <td colspan=<%$slots%>
- class="weekly
-%# <% $is_today ? 'today'
-%# : $is_yesterday ? 'yesterday'
-%# : $is_aweekago ? 'aweekago'
-%# : ''
-%# %>
- "
- >MULTIPLE
- </td>
+ <td style = "background-color:#<%$bgcolor%>"
+ ID="<% $td_id %>"
+ class = "<% ($selectable && $custnum && $LengthMin) ? 'weeklyselectable' : 'weekly' %>"
+%# <% $is_today ? 'today'
+%# : $is_yesterday ? 'yesterday'
+%# : $is_aweekago ? 'aweekago'
+%# : ''
+%# %>"
+% if ( $selectable ) {
+%
+% if ( $custnum && $LengthMin ) {
+%
+% #XXX for now, construct a ticket creation URL
+% # eventually, do much the same, but say "appointment made", show time
+% # and date, have # options to do things with it? etc.
+% # then redir back to customer/appointment view i guess
+%
+% #abstraction is leaking like a sieve... linking back to freeside cust
+% # (XXX and eventually, package)
+% my $cust_main = qsearchs('cust_main', { custnum=>$custnum } )
+% or die "unknown custnum $custnum";
+%
+% my $conf = new FS::Conf;
+% my $Queue = $conf->config('ticket_system-appointment-queueid')
+% or die "ticket_system-appointment-queueid configuration not set";
+%
+% my $member = "freeside://freeside/cust_main/$custnum";
+%
+% my $Starts = int($tod_row/60). ':'. sprintf('%02d',$tod_row%60). ':00';
+% my $Due = int(($tod_row+$LengthMin)/60). ':'.
+% sprintf('%02d',($tod_row+$LengthMin)%60). ':00';
+%
+% my $url = $RT::WebPath. '/Ticket/Display.html?id=new'.
+% "&Queue=$Queue".
+% "&Owner=$username".
+% '&Starts='. $Date->strftime('%F').'%20'. $Starts.
+% '&Due='. $Date->strftime('%F').'%20'. $Due.
+% '&new-MemberOf='. $member. #XXX uri_escape?
+% '&Status=new'.
+% '&RedirectToBasics='.$RedirectToBasics;
+% #'&Requestors='. #XXX Freeside customer requestor(s) (package?
+ onmouseover = "boxon(this);"
+ onmouseout = "boxoff(this);"
+ title = "<% 'Make appointment for '.
+ FS::sched_avail::pretty_time($tod_row). '-'.
+ FS::sched_avail::pretty_time($tod_row+$LengthMin)
+ %>"
+ onclick = "window.location.href = '<% $url %>'"
+%
% } else {
+% $droppable = 1;
+% }
%
-% foreach my $slot ( @{ $slots[$sday] } ) {
-% my( $id, $ticket ) = @$slot;
+% }
+ ><% $content |h %><% $link |n %></td>
+ <SCRIPT TYPE="text/javascript">
- <td class="weekly
-%# <% $is_today ? 'today'
-%# : $is_yesterday ? 'yesterday'
-%# : $is_aweekago ? 'aweekago'
-%# : ''
-%# %>
- "
- ><% $id %>
- </td>
+ $('#<% $td_id %>').data('username', "<% $username %>");
+ $('#<% $td_id %>').data('starts', <% $Date->epoch + $tod_row*60 %>);
+ $('#<% $td_id %>').data('epoch', <% $Date->epoch %>);
+ $('#<% $td_id %>').data('tod_row', <% $tod_row %>);
-% }
-%
-% if ( scalar(@{$slots[$sday]}) < $slots ) {
+% if ( $droppable ) {
+ $('#<% $td_id %>').droppable({
+ over: boxon_drop,
+ drop: reschedule_appointment,
+ tolerance: 'pointer'
+ });
+% }
- <td colspan=<% $slots - scalar(@{$slots[$sday]}) %>
- class="weekly
-%# <% $is_today ? 'today'
-%# : $is_yesterday ? 'yesterday'
-%# : $is_aweekago ? 'aweekago'
-%# : ''
-%# %>
- "
- >
- </td>
-% }
-%
-% }
+% if ( $draggable_ticketid ) {
+ $('#<% $td_id %>').draggable({
+ containment: '.titlebox-content',
+%# revert: 'invalid',
+ revert: true,
+ revertDuration: 0,
+ });
+ $('#<% $td_id %>').data('ticketid', <% $draggable_ticketid %>);
+ $('#<% $td_id %>').data('length', <% $draggable_length * 60 %>);
+ $('#<% $td_id %>').data('cells', <% $cells %>);
+ $('#<% $td_id %>').data('bgcolor', "#<% $bgcolor %>");
+% }
+
+ </SCRIPT>
+% }
<%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 );
+use FS::sched_avail; #just for pretty_time
+
+#what happened? alas. for constructing the ticket creation links
+use FS::Record qw( qsearchs );
+use FS::cust_main;
+
+</%INIT>