4 $slots => $default_slots
7 $timestep => $default_timestep
9 $LengthMin => $default_timestep
12 $RedirectToBasics => 0
14 % my $scheduling = ($custnum && $LengthMin) ? 1 : 0;
15 % foreach my $username ( @username ) {
17 % my %schedule = UserDaySchedule( username => $username,
18 % 'date' => $Date->strftime('%F'),
19 % Tickets => \@Tickets,
22 % my $bgcolor = '#666666';
23 % my $border = '1px solid #555555';
24 % my $label_time = '';
25 % my $label_title = '';
26 % my $selectable = 0; # can we schedule a new appointment
28 % my $draggable_length = 0;
29 % my $droppable = 0; # can we reschedule an appointment here
30 % my $cells = 0; # total cell count for appointment
31 % my $offset = 0; # position of cell in appointment
33 % #white out available times
34 % foreach my $avail ( @{ $schedule{'avail'} } ) {
35 % my( $start, $end ) = @$avail;
36 % next if $start >= ($tod_row+$timestep) || $end <= $tod_row;
37 % $bgcolor = '#FFFFFF';
38 % $border = '1px solid #D7D7D7';
40 % if $LengthMin <= $end - $tod_row #the slot is long enough
41 % && ! grep { $_ > $tod_row && $LengthMin > $_ - $tod_row }
42 % map $_->[0], values %{ $schedule{'scheduled'} };
45 % #block out / show / color code existing appointments
47 % foreach my $id ( keys %{ $schedule{'scheduled'} } ) {
49 % my( $starts, $due, $col, $t ) = @{ $schedule{'scheduled'}->{$id} };
51 % # misleading loop--at most one id should pass this test
52 % next if $starts >= ($tod_row+$timestep) || $due <= $tod_row;
54 % # but, if for any reason a scheduling conflict occurs,
55 % # use the later starting one to minimize UI conflicts--
56 % # not to imply that this scenario has been tested or should ever happen!!!
57 % next if $starts < $maxstarts;
58 % $maxstarts = $starts;
61 % $bgcolor = '#'.$col;
62 % $border = '1px solid #D7D7D7';
63 % # can't schedule a new appointment
65 % # but can reschedule a ticket overlapping its old slot (filtered by can_drop)
66 % $droppable = 1 unless $scheduling;
67 % $draggable_length = $due - $starts;
68 % $cells = int( ($due-$starts) / $timestep );
69 % $cells++ if ($due-$starts) % $timestep;
71 % #false laziness w/misc/xmlhttp-ticket-update.html & CalendarDaySchedule
72 % my %hash = $m->comp('/Ticket/Elements/Customers', Ticket => $t);
73 % my @cust_main = values( %{$hash{cust_main}} );
75 % #false laziness w/xmlhttp-ticket-update.html
76 % $label_time = FS::sched_avail::pretty_time($starts). '-'.
77 % FS::sched_avail::pretty_time($due);
78 % $label_title = $cust_main[0]->_FreesideURILabel;
79 % #'install for custname XX miles away'; #XXX placeholder/more
81 % $offset = int( ($tod_row - $starts) / $timestep );
82 % $offset++ if ($tod_row - $starts) % $timestep;
85 % my $td_id = 'td_'. $Date->epoch. '_'. $tod_row. '_'. $username;
87 <td style = "background-color: <% $bgcolor %>; border: <% $border %>"
89 class = "<% ($selectable && $scheduling) ? 'weeklyselectable' : 'weekly' %>"
90 %# <% $is_today ? 'today'
91 %# : $is_yesterday ? 'yesterday'
92 %# : $is_aweekago ? 'aweekago'
95 % if ( $selectable ) {
97 % # Scheduling a new appointment
98 % if ( $scheduling ) {
100 % #XXX for now, construct a ticket creation URL
101 % # eventually, do much the same, but say "appointment made", show time
102 % # and date, have # options to do things with it? etc.
103 % # then redir back to customer/appointment view i guess
105 % #abstraction is leaking like a sieve... linking back to freeside cust
106 % # (XXX and eventually, package)
107 % my $cust_main = qsearchs('cust_main', { custnum=>$custnum } )
108 % or die "unknown custnum $custnum";
110 % my $conf = new FS::Conf;
111 % my $Queue = $conf->config('ticket_system-appointment-queueid')
112 % or die "ticket_system-appointment-queueid configuration not set";
114 % my $member = "freeside://freeside/cust_main/$custnum";
116 % my $Starts = int($tod_row/60). ':'. sprintf('%02d',$tod_row%60). ':00';
117 % my $Due = int(($tod_row+$LengthMin)/60). ':'.
118 % sprintf('%02d',($tod_row+$LengthMin)%60). ':00';
120 % my $url = $RT::WebPath. '/Ticket/Display.html?id=new'.
122 % "&Owner=$username".
123 % '&Starts='. $Date->strftime('%F').'%20'. $Starts.
124 % '&Due='. $Date->strftime('%F').'%20'. $Due.
125 % '&new-MemberOf='. $member. #XXX uri_escape?
127 % '&RedirectToBasics='.$RedirectToBasics;
128 % #'&Requestors='. #XXX Freeside customer requestor(s) (package?
130 onmouseover = "boxon(this);"
131 onmouseout = "boxoff(this);"
132 title = "<% 'Make appointment for '.
133 FS::sched_avail::pretty_time($tod_row). '-'.
134 FS::sched_avail::pretty_time($tod_row+$LengthMin)
136 onclick = "window.location.href = '<% $url %>'"
138 % # If not scheduling, allow drag-and-drop rescheduling
145 <SCRIPT TYPE="text/javascript">
147 var $cell_<% $td_id %> = $('#<% $td_id %>');
148 $cell_<% $td_id %>.data('username', "<% $username %>");
149 $cell_<% $td_id %>.data('starts', <% $Date->epoch + $tod_row*60 %>);
150 $cell_<% $td_id %>.data('epoch', <% $Date->epoch %>);
151 $cell_<% $td_id %>.data('tod_row', <% $tod_row %>);
154 set_schedulable_cell($cell_<% $td_id %>);
158 set_appointment_cell(
160 <% $ticketid |js_string %>,
161 <% $bgcolor |n,js_string %>,
162 <% $label_time |n,js_string %>,
163 <% $label_title |n,js_string %>,
164 <% $draggable_length * 60 %>,
169 % if ( $droppable ) {
170 % if ( $draggable_length ) {
171 set_draggable_cell($cell_<% $td_id %>);
173 set_droppable_cell($cell_<% $td_id %>);
179 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
180 my $default_timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
184 use RTx::Schedule qw( UserDaySchedule );
185 use FS::sched_avail; #just for pretty_time
187 #what happened? alas. for constructing the ticket creation links
188 use FS::Record qw( qsearchs );