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