This commit was generated by cvs2svn to compensate for changes in r10640,
[freeside.git] / rt / share / html / Elements / CollectionList
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 <%INIT>
49 if (!$Collection && $Class eq 'RT::Tickets') {
50     $Collection = RT::Tickets->new( $session{'CurrentUser'} );
51     $Collection->FromSQL($Query);
52 }
53
54 my $TotalFound = $Collection->CountAll();
55 return '' if !$TotalFound && !$ShowEmpty;
56
57 # XXX: ->{'order_by'} is hacky, but there is no way to check if
58 # collection is ordered or not
59 if ( @OrderBy && ($AllowSorting || !$Collection->{'order_by'}) ) {
60     if ( $OrderBy[0] =~ /\|/ ) {
61         @OrderBy = split /\|/, $OrderBy[0];
62         @Order = split /\|/,$Order[0];
63     }
64     $Collection->OrderByCols(
65         map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
66         ( 0 .. $#OrderBy )
67     );
68 }
69
70 $Collection->RowsPerPage( $Rows ) if $Rows;
71 $Page = 1 unless $Page && $Page > 0;    # workaround problems with $Page = '' or undef
72 $Collection->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
73
74 # DisplayFormat lets us use a "temporary" format for display, while 
75 # still using our original format for next/prev page links.
76 # bulk update uses this feature to add checkboxes
77
78 $DisplayFormat ||= $Format;
79
80 # Scrub the html of the format string to remove any potential nasties.
81 $Format = $m->comp('/Elements/ScrubHTML', Content => $Format);
82 $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $DisplayFormat);
83
84 my @Format = $m->comp('/Elements/CollectionAsTable/ParseFormat', Format => $DisplayFormat);
85
86 # Find the maximum number of items in any row, so we can pad the table.
87 my ($maxitems, $item) = (0, 0);
88 foreach my $col (@Format) {
89     $item++;
90     if ( $col->{title} && ($col->{title} eq 'NEWLINE') ) {
91         $item = 0;
92     }
93     else {
94         $maxitems = $item if $item > $maxitems;
95     }
96 }
97
98 $Class ||= ref $Collection;
99 $Class =~ s/s$//;
100 $Class =~ s/:/_/g;
101
102 $m->out('<table border="0" cellspacing="0" cellpadding="1"' . 
103         ' width="100%" class="' . 
104         ($Collection->isa('RT::Tickets') ? 'ticket-list' : 'collection') . '">');
105
106 if ( $ShowHeader ) {
107   $m->comp('/Elements/CollectionAsTable/Header',
108            %ARGS,
109            Class        => $Class,
110            Format       => \@Format,
111            FormatString => $Format,
112            Order        => \@Order,
113            OrderBy      => \@OrderBy,
114            Rows         => $Rows,
115            Page         => $Page,
116            AllowSorting => $AllowSorting, 
117            BaseURL      => $BaseURL,
118            GenericQueryArgs => $GenericQueryArgs,
119            maxitems     => $maxitems,
120            );
121 }
122
123 my ($i, $column_map) = (0, {});
124 while ( my $record = $Collection->Next ) {
125     # Every ten rows, flush the buffer and put something on the page.
126     #broken w/FS, causes rows to be output prematurely
127     #$m->flush_buffer unless ++$i % 10;
128     ++$i;
129
130     my $warning = 0;
131     my $Classes = '';
132
133     $m->callback(
134         CallbackName => 'EachRow',
135         Record       => $record,
136         Warning      => \$warning,
137         Classes      => \$Classes,
138         Format       => \@Format,
139     );
140
141     $m->comp('/Elements/CollectionAsTable/Row',
142         i         => $i,
143         Format    => \@Format,
144         record    => $record,
145         maxitems  => $maxitems,
146         ColumnMap => $column_map,
147         Class     => $Class,
148         Warning   => $warning,
149         Classes   => $Classes,
150     );
151 }
152
153 $m->out('</table>');
154 if ( $Rows && $ShowNavigation && $TotalFound > $Rows ) {
155   my $oddRows = ($TotalFound && $TotalFound % $Rows == 0 )? 0 : 1;
156   my $pages = int( $TotalFound / $Rows ) + $oddRows;
157   $pages = 1 if $pages < 1;
158
159
160   my %query_args = map { $_ => $ARGS{$_} } @PassArguments;
161   $m->comp(
162         '/Elements/CollectionListPaging',
163         BaseURL     => $BaseURL,
164         Rows        => $Rows,
165         TotalFound  => $TotalFound,
166         CurrentPage => $Page,
167         Pages       => $pages,
168         URLParams   => \%query_args
169     );
170
171 }
172
173 </%INIT>
174 <%ARGS>
175 $Class         => ''
176 $Collection    => undef
177 $Format        => undef
178 $DisplayFormat => undef
179 @Order         => ()
180 @OrderBy       => ()
181 $GenericQueryArgs => undef
182 $Rows          => undef
183 $Page          => 1
184 $Title         => loc('Ticket Search')
185 $BaseURL       => RT->Config->Get('WebPath') . $m->request_comp->path .'?'
186 @PassArguments => qw( Query Format Rows Page Order OrderBy)
187
188 $AllowSorting   => 0
189 $ShowNavigation => 1
190 $ShowHeader     => 1
191 $ShowEmpty      => 0
192 $Query => 0
193 </%ARGS>