show customer name on appointments, RT#34237
[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 </%ARGS>
13 % foreach my $username ( @username ) {
14 %
15 %   my %schedule = UserDaySchedule( username => $username,
16 %                                   'date'   => $Date->strftime('%F'),
17 %                                   Tickets  => \@Tickets,
18 %                                 );
19 %
20 %   my $bgcolor = '666666;border-color:#555555';
21 %   my $content = '';
22 %   my $selectable = 0;
23 %   my $draggable_ticketid = 0;
24 %   my $draggable_length = 0;
25 %   my $droppable = 0;
26 %   my $cells = 0;
27 %
28 %   #white out available times
29 %   foreach my $avail ( @{ $schedule{'avail'} } ) {
30 %     my( $start, $end ) = @$avail;
31 %     next if $start >= ($tod_row+$timestep) || $end <= $tod_row;
32 %     $bgcolor = 'FFFFFF';
33 %     $selectable = 1
34 %       if $LengthMin <= $end - $tod_row  #the slot is long enough
35 %       && ! grep { $_ > $tod_row && $LengthMin > $_ - $tod_row }
36 %              map $_->[0], values %{ $schedule{'scheduled'} };
37 %   }
38 %
39 %   #block out / show / color code existing appointments
40 %   #my %line = ();
41 %   foreach my $id ( keys %{ $schedule{'scheduled'} } ) {
42 %
43 %     my( $starts, $due, $col, $t ) = @{ $schedule{'scheduled'}->{$id} };
44 %
45 %     next if $starts >= ($tod_row+$timestep) || $due <= $tod_row;
46 %
47 %     $bgcolor = $col;
48 %     $selectable = 0;
49 %
50 %     if ( $starts >= $tod_row ) { #first row
51 %
52 %       #false laziness w/misc/xmlhttp-ticket-update.html & CalendarDaySchedule
53 %       my %hash = $m->comp('/Ticket/Elements/Customers', Ticket => $t);
54 %       my @cust_main = values( %{$hash{cust_main}} );
55 %
56 %       $content .= ($content?', ':''). #$id. ': '.
57 %                   #false laziness w/xmlhttp-ticket-update.html
58 %                   FS::sched_avail::pretty_time($starts). '-'.
59 %                   FS::sched_avail::pretty_time($due).
60 %                   ': '. encode_entities($cust_main[0]->_FreesideURILabel);
61 %                   #'install for custname XX miles away'; #XXX placeholder/more
62 %       $draggable_ticketid = $id;
63 %       $draggable_length = $due - $starts;
64 %
65 %       $cells = int( ($due-$starts) / $timestep );
66 %       $cells++ if ($due-$starts) % $timestep;
67 %       
68 %     #} else {
69 %     #  $content .= ($content?', ':''). $id;
70 %     }
71 %   }
72 %
73 %   my $td_id = 'td_'. $Date->epoch. '_'. $tod_row. '_'. $username;
74
75     <td style = "background-color:#<%$bgcolor%>"
76           ID="<% $td_id %>"
77         class = "<% ($selectable && $custnum && $LengthMin) ? 'weeklyselectable' : 'weekly' %>"
78 %#                 <%   $is_today     ? 'today'
79 %#                    : $is_yesterday ? 'yesterday'
80 %#                    : $is_aweekago  ? 'aweekago'
81 %#                    : ''
82 %#                 %>"
83 %     if ( $selectable ) {
84 %
85 %       if ( $custnum && $LengthMin ) {
86 %
87 %         #XXX for now, construct a ticket creation URL
88 %         # eventually, do much the same, but say "appointment made", show time
89 %         # and date, have # options to do things with it? etc.
90 %         # then redir back to customer/appointment view i guess
91 %
92 %         #abstraction is leaking like a sieve... linking back to freeside cust
93 %         # (XXX and eventually, package)
94 %         my $cust_main = qsearchs('cust_main', { custnum=>$custnum } )
95 %           or die "unknown custnum $custnum";
96 %
97 %         my $conf = new FS::Conf;
98 %         my $Queue = $conf->config('ticket_system-appointment-queueid')
99 %           or die "ticket_system-appointment-queueid configuration not set";
100 %
101 %         my $member = "freeside://freeside/cust_main/$custnum";
102 %
103 %warn         my $Starts = int($tod_row/60). ':'. sprintf('%02d',$tod_row%60). ':00';
104 %warn         my $Due    = int(($tod_row+$LengthMin)/60). ':'.
105 %                      sprintf('%02d',($tod_row+$LengthMin)%60). ':00';
106 %
107 %         my $url = $RT::WebPath. '/Ticket/Display.html?id=new'.
108 %                   "&Queue=$Queue".
109 %                   "&Owner=$username".
110 %                   '&Starts='. $Date->strftime('%F').'%20'. $Starts.
111 %                   '&Due='.    $Date->strftime('%F').'%20'. $Due.
112 %                   '&new-MemberOf='. $member. #XXX uri_escape?
113 %                   '&Status=new';
114 %                   #'&Requestors='. #XXX Freeside customer requestor(s) (package?
115
116           onmouseover = "boxon(this);"
117           onmouseout  = "boxoff(this);"
118           title       = "<% 'Make appointment for '.
119                               FS::sched_avail::pretty_time($tod_row). '-'.
120                               FS::sched_avail::pretty_time($tod_row+$LengthMin)
121                         %>"
122           onclick     = "window.location.href = '<% $url %>'"
123 %
124 %       } else {
125 %         $droppable = 1;
126 %       }
127 %
128 %     }
129     ><% $content %></td>
130     <SCRIPT TYPE="text/javascript">
131
132       $('#<% $td_id %>').data('username', "<% $username %>");
133       $('#<% $td_id %>').data('starts',   <% $Date->epoch + $tod_row*60 %>);
134       $('#<% $td_id %>').data('epoch',    <% $Date->epoch %>);
135       $('#<% $td_id %>').data('tod_row',  <% $tod_row %>);
136
137 %     if ( $droppable ) {
138         $('#<% $td_id %>').droppable({
139           over: boxon_drop,
140           drop: reschedule_appointment,
141           tolerance: 'pointer'
142         });
143 %     }
144
145 %     if ( $draggable_ticketid ) {
146         $('#<% $td_id %>').draggable({
147           containment: '.titlebox-content',
148 %#          revert:      'invalid',
149           revert: true,
150           revertDuration: 0,
151         });
152         $('#<% $td_id %>').data('ticketid', <% $draggable_ticketid %>);
153         $('#<% $td_id %>').data('length',   <% $draggable_length * 60 %>);
154         $('#<% $td_id %>').data('cells',    <% $cells %>);
155         $('#<% $td_id %>').data('bgcolor',  "#<% $bgcolor %>");
156 %     }
157
158     </SCRIPT>
159 % }
160 <%ONCE>
161 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
162 my $default_timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
163 </%ONCE>
164 <%INIT>
165
166 use RTx::Schedule qw( UserDaySchedule );
167 use FS::sched_avail; #just for pretty_time
168
169 #what happened?  alas.  for constructing the ticket creation links
170 use FS::Record qw( qsearchs );
171 use FS::cust_main;
172
173 </%INIT>