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