import rt 3.8.8
[freeside.git] / rt / html / Ticket / Elements / Tabs
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %# 
29 %# 
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %# 
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %# 
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %# 
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Callback, Ticket => $Ticket, actions=> $actions, tabs => $tabs, %ARGS &>
49 <& /Elements/Tabs, 
50     tabs => $tabs, 
51     actions => $actions, 
52     current_tab => $current_tab, 
53     current_toptab => $current_toptab,
54     Title => $Title &> 
55 <%INIT>
56
57 my $tabs = {};
58 my $current_toptab = "Search/Build.html",
59 my $searchtabs = {};
60 my $actions;
61
62 if ( $Ticket) {
63         
64 my $id   = $Ticket->id();
65
66 if ( defined $session{'tickets'} ) {
67
68         # we have to update session data if we get new ItemMap
69         my $updatesession = 1 unless($session{'tickets'}->{'item_map'});
70
71         my $item_map = $session{'tickets'}->ItemMap;
72
73         if ($updatesession) {
74                 $session{'i'}++;
75                 $session{'tickets'}->PrepForSerialization();
76         }
77
78         # Don't display prev links if we're on the first ticket
79         if ($item_map->{$Ticket->Id}->{prev}) {
80                 $searchtabs->{'_a'} = {
81                             class => "nav",
82                             path => "Ticket/Display.html?id=" . $item_map->{first},
83                             title => '<< ' . loc('First') };
84                 $searchtabs->{"_b"} = { class => "nav",
85                             path => "Ticket/Display.html?id=" . $item_map->{$Ticket->Id}->{prev},
86                                   title => '< ' . loc('Prev') };
87        } 
88
89
90         # Don't display next links if we're on the last ticket
91         if ($item_map->{$Ticket->Id}->{next}) {
92             $searchtabs->{'d'} = { class => "nav",
93                             path => "Ticket/Display.html?id=" . $item_map->{$Ticket->Id}->{next},
94                              title => loc('Next') . ' >' };
95             $searchtabs->{'e'} = {
96                            class => "nav",
97                            path => "Ticket/Display.html?id=" . $item_map->{last},
98                            title => loc('Last') . ' >>' };
99         }
100 }
101
102
103
104 $tabs->{"this"} = { class => "currentnav",
105                     path  => "Ticket/Display.html?id=" . $Ticket->id,
106                     title => "#" . $id,
107                     current_subtab => $current_subtab };
108
109 my $ticket_page_tabs = {
110     _A => { title => loc('Display'),
111             path  => "Ticket/Display.html?id=" . $id, },
112
113     _Ab => { title => loc('History'),
114              path  => "Ticket/History.html?id=" . $id, },
115     _B => { title => loc('Basics'),
116             path  => "Ticket/Modify.html?id=" . $id, },
117
118     _C => { title => loc('Dates'),
119             path  => "Ticket/ModifyDates.html?id=" . $id, },
120     _D =>
121       { title => loc('People'), path => "Ticket/ModifyPeople.html?id=" . $id, },
122     _E => { title => loc('Links'),
123             path  => "Ticket/ModifyLinks.html?id=" . $id, },
124     _F => { title => loc('Reminders'),
125             path  => "Ticket/Reminders.html?id=" . $id,
126             separator => 1, },
127     _X => { title => loc('Jumbo'),
128             path  => "Ticket/ModifyAll.html?id=" . $id, 
129  },
130
131 };
132
133 foreach my $tab ( sort keys %{$ticket_page_tabs} ) {
134     if ( $ticket_page_tabs->{$tab}->{'path'} eq $current_tab ) {
135         $ticket_page_tabs->{$tab}->{"subtabs"}        = $subtabs;
136         $tabs->{'this'}->{"current_subtab"}        = 
137         $ticket_page_tabs->{$tab}->{"path"};
138     }
139 }
140 $tabs->{'this'}->{"subtabs"} = $ticket_page_tabs;
141 $current_tab = "Ticket/Display.html?id=" . $id;
142
143 my %can = (
144     ModifyTicket => $Ticket->CurrentUserHasRight('ModifyTicket'),
145 );
146
147 if ( $can{'ModifyTicket'} or $Ticket->CurrentUserHasRight('ReplyToTicket') ) {
148     $actions->{'F'} = {
149         title => loc('Reply'),
150         path  => "Ticket/Update.html?Action=Respond&id=" . $id,
151     };
152 }
153
154 if ( $can{'ModifyTicket'} ) {
155     if ( $Ticket->Status ne 'resolved' ) {
156         $actions->{'G'} = {
157             path => "Ticket/Update.html?Action=Comment&DefaultStatus=resolved&id=" . $id,
158             title => loc('Resolve') };
159     }
160     if ( $Ticket->Status ne 'open' ) {
161         $actions->{'A'} = { path => "Ticket/Display.html?Status=open&id=" . $id,
162                             title => loc('Open it') };
163     }
164 }
165
166 if ( $Ticket->CurrentUserHasRight('OwnTicket') ) {
167     if ( $Ticket->OwnerObj->Id == $RT::Nobody->id
168          and ( $can{'ModifyTicket'} or $Ticket->CurrentUserHasRight('TakeTicket') ) )
169     {
170         $actions->{'B'} = {
171             path => "Ticket/Display.html?Action=Take&id=" . $id,
172             title => loc('Take'),
173         };
174     }
175     elsif ( $Ticket->OwnerObj->id != $session{CurrentUser}->id 
176             and ( $can{'ModifyTicket'} or $Ticket->CurrentUserHasRight('StealTicket') ) )
177     {
178         $actions->{'C'} = {
179             path => "Ticket/Display.html?Action=Steal&id=" . $id,
180             title => loc('Steal'),
181         };
182     }
183 }
184
185 if ( $can{'ModifyTicket'} or $Ticket->CurrentUserHasRight('CommentOnTicket') ) {
186     $actions->{'E'} = {
187         title => loc('Comment'),
188         path  => "Ticket/Update.html?Action=Comment&id=" . $id,
189     };
190 }
191 }
192
193 if ( (defined $actions->{A} || defined $actions->{B} || defined $actions->{C})
194     && (defined $actions->{E} || defined $actions->{F} || defined $actions->{G}) ) { 
195     
196     if    (defined $actions->{C}) { $actions->{C}->{separator} = 1 }
197     elsif (defined $actions->{B}) { $actions->{B}->{separator} = 1 }
198     elsif (defined $actions->{A}) { $actions->{A}->{separator} = 1 }
199 }
200
201 my $args;
202 $args= "?" . $m->comp(
203     '/Elements/QueryString',
204     Query   => $ARGS{'Query'}   || $session{'CurrentSearchHash'}->{'Query'},
205     Format  => $ARGS{'Format'}  || $session{'CurrentSearchHash'}->{'Format'},
206     OrderBy => $ARGS{'OrderBy'} || $session{'CurrentSearchHash'}->{'OrderBy'},
207     Order   => $ARGS{'Order'}   || $session{'CurrentSearchHash'}->{'Order'},
208     Page   => $ARGS{'Page'}   || $session{'CurrentSearchHash'}->{'Page'},
209     Rows    => $ARGS{'Rows'},
210   ) if ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'});
211 $args ||= '';
212
213 $tabs->{"f"} = { path      => "Search/Build.html?NewQuery=1",
214                  title     => loc('New Search')};
215 $tabs->{"g"} = { path      => "Search/Build.html$args",
216                  title     => loc('Edit Search')};
217 $tabs->{"h"} = { path      => "Search/Edit.html$args",
218                  title     => loc('Advanced'),
219                  separator => 1 };
220 if ($args) {
221   $tabs->{"i"} = { path      => "Search/Results.html$args",
222                    title     => loc('Show Results'),
223                    };
224   if ($current_tab =~ m{Search/Results.html}) {
225     $current_tab = "Search/Results.html$args";
226   }
227   $tabs->{"j"} = { path      => "Search/Bulk.html$args",
228                    title     => loc('Bulk Update'),
229                    };
230   if ($current_tab =~  m{Search/Bulk.html}) {
231     $current_tab = "Search/Bulk.html$args";
232   }
233   foreach my $searchtab (keys %{$searchtabs}) {
234     ($searchtab =~ /^_/) ? $tabs->{"s".$searchtab} = $searchtabs->{$searchtab} : $tabs->{"z_".$searchtab} = $searchtabs->{$searchtab};
235   }
236 }
237
238
239 </%INIT>
240
241   
242 <%ARGS>
243 $Ticket => undef
244 $subtabs => undef
245 $current_tab => ''
246 $current_subtab => ''
247 $Title => undef
248 </%ARGS>