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