no need for FS calendar buttons in RT 4.2
[freeside.git] / rt / share / html / Elements / CalendarSlotSchedule
1 <%ARGS>
2   $Date      => undef
3   @Tickets   => ()
4   $slots     => $default_slots
5   $sday      => undef
6   $tod_row   => undef
7   $timestep  => $default_timestep
8   @username  => ()
9   $LengthMin => $default_timestep
10   $custnum   => undef
11   $pkgnum    => undef
12   $RedirectToBasics => 0
13 </%ARGS>
14 % my $scheduling = ($custnum && $LengthMin) ? 1 : 0;
15 % foreach my $username ( @username ) {
16 %
17 %   my %schedule = UserDaySchedule( username => $username,
18 %                                   'date'   => $Date->strftime('%F'),
19 %                                   Tickets  => \@Tickets,
20 %                                 );
21 %
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
27 %   my $ticketid = 0;
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
32 %
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';
39 %     $selectable = 1
40 %       if $LengthMin <= $end - $tod_row  #the slot is long enough
41 %       && ! grep { $_ > $tod_row && $LengthMin > $_ - $tod_row }
42 %              map $_->[0], values %{ $schedule{'scheduled'} };
43 %   }
44 %
45 %   #block out / show / color code existing appointments
46 %   my $maxstarts = 0;
47 %   foreach my $id ( keys %{ $schedule{'scheduled'} } ) {
48 %
49 %     my( $starts, $due, $col, $t ) = @{ $schedule{'scheduled'}->{$id} };
50 %
51 %     # misleading loop--at most one id should pass this test
52 %     next if $starts >= ($tod_row+$timestep) || $due <= $tod_row;
53 %
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;
59 %
60 %     $ticketid = $id;
61 %     $bgcolor = '#'.$col;
62 %     $border = '1px solid #D7D7D7';
63 %     # can't schedule a new appointment
64 %     $selectable = 0;
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;
70 %
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}} );
74 %
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
80 %
81 %     $offset = int( ($tod_row - $starts) / $timestep );
82 %     $offset++ if ($tod_row - $starts) % $timestep;
83 %   }
84 %
85 %   my $td_id = 'td_'. $Date->epoch. '_'. $tod_row. '_'. $username;
86
87     <td style = "background-color: <% $bgcolor %>; border: <% $border %>"
88           ID="<% $td_id %>"
89         class = "<% ($selectable && $scheduling) ? 'weeklyselectable' : 'weekly' %>"
90 %#                 <%   $is_today     ? 'today'
91 %#                    : $is_yesterday ? 'yesterday'
92 %#                    : $is_aweekago  ? 'aweekago'
93 %#                    : ''
94 %#                 %>"
95 %     if ( $selectable ) {
96 %
97 %       # Scheduling a new appointment
98 %       if ( $scheduling ) {
99 %
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
104 %
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";
109 %
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";
113 %
114 %         my $member = "freeside://freeside/cust_main/$custnum";
115 %
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';
119 %
120 %         my $url = $RT::WebPath. '/Ticket/Display.html?id=new'.
121 %                   "&Queue=$Queue".
122 %                   "&Owner=$username".
123 %                   '&Starts='. $Date->strftime('%F').'%20'. $Starts.
124 %                   '&Due='.    $Date->strftime('%F').'%20'. $Due.
125 %                   '&new-MemberOf='. $member. #XXX uri_escape?
126 %                   '&Status=new'.
127 %                   '&RedirectToBasics='.$RedirectToBasics;
128 %                   #'&Requestors='. #XXX Freeside customer requestor(s) (package?
129
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)
135                         %>"
136           onclick     = "window.location.href = '<% $url %>'"
137 %
138 %       # If not scheduling, allow drag-and-drop rescheduling
139 %       } else {
140 %         $droppable = 1;
141 %       }
142 %
143 %     }
144     ></td>
145     <SCRIPT TYPE="text/javascript">
146
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 %>);
152
153 %     if ($selectable) {
154       set_schedulable_cell($cell_<% $td_id %>);
155 %     }
156
157 %     if ($ticketid) {
158       set_appointment_cell(
159         $cell_<% $td_id %>,
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 %>,
165         <% $cells %>,
166         <% $offset %>
167       );
168 %     }
169 %     if ( $droppable ) {
170 %       if ( $draggable_length ) {
171       set_draggable_cell($cell_<% $td_id %>);
172 %       }
173       set_droppable_cell($cell_<% $td_id %>);
174 %     }
175
176     </SCRIPT>
177 % }
178 <%ONCE>
179 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
180 my $default_timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
181 </%ONCE>
182 <%INIT>
183
184 use RTx::Schedule qw( UserDaySchedule );
185 use FS::sched_avail; #just for pretty_time
186
187 #what happened?  alas.  for constructing the ticket creation links
188 use FS::Record qw( qsearchs );
189 use FS::cust_main;
190
191 </%INIT>