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