b36101e73e44ef347678d726cbc8a9603389e906
[freeside.git] / rt / html / Elements / TicketList
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2007 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/copyleft/gpl.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 <table border="0" cellspacing="0" cellpadding="1" width="100%">
49
50 % if ($ShowHeader) {
51 <& /Elements/CollectionAsTable/Header, 
52     Format => \@Format, 
53     FormatString => $Format,
54     AllowSorting => $AllowSorting, 
55     Order => $Order, 
56     Query => $Query,
57     Rows => $Rows,
58     Page => $Page,
59     OrderBy => $OrderBy , 
60     BaseURL => $BaseURL,
61     maxitems => $maxitems &> 
62 % }
63
64 %   my $i;
65 %   while (my $record = $Collection->Next) {
66 %   $i++;
67 % # Every ten rows, flush the buffer and put something on the page.
68 % # hun, this flushes things out out-of-order for me on "RT at a glance"...?
69 % # $m->flush_buffer() unless ($i % 10);
70 <&   /Elements/CollectionAsTable/Row, Format => \@Format, i => $i, record => $record, maxitems => $maxitems &>
71 %   }
72
73 </table>
74
75 % if ($Rows && $ShowNavigation) {
76 <hr>
77 % my $oddRows;
78 % if (($TotalFound % $Rows) == 0) {
79 % $oddRows = 0;
80 % } else { $oddRows = 1; }
81 % my $pages = int($TotalFound/$Rows)+$oddRows;
82 % $pages = 1 if $pages < 1;
83 <&|/l, $Page, $pages &>Page [_1] of [_2]</&>
84
85 <%perl>
86 my $prev = $m->comp(
87     '/Elements/QueryString',
88     Query   => $Query,
89     Format  => $Format,
90     Rows    => $Rows,
91     OrderBy => $OrderBy,
92     Order   => $Order,
93     Page    => ( $Page - 1 )
94 );
95 my $next = $m->comp(
96     '/Elements/QueryString',
97     Query   => $Query,
98     Format  => $Format,
99     Rows    => $Rows,
100     OrderBy => $OrderBy,
101     Order   => $Order,
102     Page    => ( $Page + 1 )
103 );
104 </%perl>
105 % if ($Page > 1) {
106 <a href="<%$BaseURL%><%$prev%>"><&|/l&>Previous Page</&></a>
107 % }
108 % if (($Page * $Rows) < $TotalFound) {
109 <a href="<%$BaseURL%><%$next%>"><&|/l&>Next Page</&></a>
110 % }
111 % }
112 <%INIT>
113 my $maxitems = 0;
114
115 $Format ||= $RT::DefaultSearchResultFormat;
116
117 # DisplayFormat lets us use a "temporary" format for display, while 
118 # still using our original format for next/prev page links.
119 # bulk update uses this feature to add checkboxes
120
121
122 $DisplayFormat ||= $Format;
123
124 # Scrub the html of the format string to remove any potential nasties.
125 $Format = $m->comp('/Elements/ScrubHTML', Content => $Format);
126 $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $DisplayFormat);
127
128
129 unless ($Collection) {
130         $Collection = RT::Tickets->new($session{'CurrentUser'});
131         $Collection->FromSQL($Query);
132 }
133
134 my (@Format) = $m->comp('/Elements/CollectionAsTable/ParseFormat', Format => $DisplayFormat);
135
136 # Find the maximum number of items in any row, so we can pad the table.
137 my $item = 0;
138 foreach my $col (@Format) {
139     $item++;
140     if ( $col->{title} && ($col->{title} eq 'NEWLINE') ) {
141         $item = 0;
142     }
143     else {
144         $maxitems = $item if $item > $maxitems;
145     }
146 }
147
148 if ($OrderBy =~ /\|/) {
149     # Multiple Sorts
150     my @OrderBy = split /\|/,$OrderBy;
151     my @Order = split /\|/,$Order;
152     $Collection->OrderByCols(
153         map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
154         .. $#OrderBy ) );; 
155 } else {
156     $Collection->OrderBy(FIELD => $OrderBy, ORDER => $Order); 
157 }
158
159 $Collection->RowsPerPage($Rows) if ($Rows);
160 $Page = 1 unless $Page > 0; # workaround problems with Page = '' or undef
161 $Collection->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
162 my $TotalFound =  $Collection->CountAll();
163
164 </%INIT>
165 <%ARGS>
166 $Query => undef
167 $Rows => 50
168 $Page => 1
169 $Title => 'Ticket Search'
170 $Collection => undef
171 $AllowSorting => undef
172 $Order => undef
173 $OrderBy => undef
174 $BaseURL => undef
175 $Format => $RT::DefaultSearchResultFormat
176 $DisplayFormat => undef
177 $ShowNavigation => 1
178 $ShowHeader => 1
179 </%ARGS>