From: ivan Date: Wed, 25 Oct 2006 17:36:28 +0000 (+0000) Subject: pagination patch from UNTD - limit the number of page links displayed and have a... X-Git-Tag: TRIXBOX_2_6~891 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=5eb3dab3ea20a9861074a41bef19c9ac4dcb2336 pagination patch from UNTD - limit the number of page links displayed and have a drop-down option for selecting number of entries per page --- diff --git a/httemplate/elements/pager.html b/httemplate/elements/pager.html index 2327594a8..a53300f53 100644 --- a/httemplate/elements/pager.html +++ b/httemplate/elements/pager.html @@ -1,43 +1,55 @@ +% my %opt = @_; +% my $pager = ''; % +% if ( $opt{'total'} != $opt{'num_rows'} && $opt{'maxrecords'} ) { % -% my %opt = @_; -% -% my $pager = ''; -% if ( $opt{'total'} != $opt{'num_rows'} && $opt{'maxrecords'} ) { -% unless ( $opt{'offset'} == 0 ) { -% $cgi->param('offset', $opt{'offset'} - $opt{'maxrecords'}); -% - +% unless ( $opt{'offset'} == 0 ) { +% $cgi->param('offset', $opt{'offset'} - $opt{'maxrecords'}); Previous + +% } % -% } -% my $page = 0; -% for ( my $poff = 0; $poff < $opt{'total'}; $poff += $opt{'maxrecords'} ) { -% $page++; -% if ( $opt{'offset'} == $poff ) { +% my $page = 0; +% my $prevpage = 0; +% my $over = 0; +% my $step = $opt{total} / 10; # 10 evenly spaced +% for ( my $poff = 0; $poff < $opt{total}; $poff += $opt{maxrecords} ) { +% $page++; +% +% next unless +% $page <= 4 #first four +% || $page >= ( $opt{total} / $opt{maxrecords} ) - 3 #last four +% || abs( ($opt{offset}-$poff) / $opt{maxrecords} ) <= 3 #w/i 3 of current +% || $poff > $over # evenly spaced +% ; % - +% $over += $step if $poff > $over; +% +% if ( $opt{'offset'} == $poff ) { <% $page %> -% -% } else { -% $cgi->param('offset', $poff); -% +% } else { +% $cgi->param('offset', $poff); +% +% if ( $page > $prevpage+1 ) { + ... +% } <% $page %> + +% } % -% } -% } -% unless ( $opt{'offset'} + $opt{'maxrecords'} > $opt{'total'} ) { -% $cgi->param('offset', $opt{'offset'} + $opt{'maxrecords'}); +% $prevpage = $page; % - +% } +% +% unless ( $opt{'offset'} + $opt{'maxrecords'} > $opt{'total'} ) { +% $cgi->param('offset', $opt{'offset'} + $opt{'maxrecords'}); Next % -% } -% } +% } % - +% } diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index 509fb294d..1b6b52675 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -238,33 +238,13 @@ <% $total %> matching customers found -% -% #begin pager -% my $pager = ''; -% if ( $total != scalar(@cust_main) && $maxrecords ) { -% unless ( $offset == 0 ) { -% $cgi->param('offset', $offset - $maxrecords); -% $pager .= 'Previous '; -% } -% my $poff; -% my $page; -% for ( $poff = 0; $poff < $total; $poff += $maxrecords ) { -% $page++; -% if ( $offset == $poff ) { -% $pager .= qq!$page !; -% } else { -% $cgi->param('offset', $poff); -% $pager .= qq!$page !; -% } -% } -% unless ( $offset + $maxrecords > $total ) { -% $cgi->param('offset', $offset + $maxrecords); -% $pager .= 'Next '; -% } -% } -% #end pager + +% my $pager = include( '/elements/pager.html', +% 'offset' => $offset, +% 'num_rows' => scalar(@cust_main), +% 'total' => $total, +% 'maxrecords' => $maxrecords, +% ); % % unless ( $cgi->param('cancelled') ) { % if ( $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 14e1dd095..689cbe389 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -1,5 +1,3 @@ -% -% % # options example... % # (everything not commented required is optional) % # @@ -98,7 +96,7 @@ % % my $type = ''; % my $limit = ''; -% my($maxrecords, $total, $offset, $count_arrayref); +% my($confmax, $maxrecords, $total, $offset, $count_arrayref); % % if ( $cgi->param('_type') =~ /^(csv|\w*\.xls)$/ ) { % @@ -108,11 +106,16 @@ % % unless (exists($opt{'count_query'}) && length($opt{'count_query'})) { % ( $opt{'count_query'} = $opt{'query'} ) =~ -% s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i; +% s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i; #silly vim:/ % } % % my $conf = new FS::Conf; -% $maxrecords = $conf->config('maxsearchrecordsperpage'); +% $confmax = $conf->config('maxsearchrecordsperpage'); +% if ( $cgi->param('maxrecords') =~ /^(\d+)$/ ) { +% $maxrecords = $1; +% } else { +% $maxrecords ||= $confmax; +% } % % $limit = $maxrecords ? "LIMIT $maxrecords" : ''; % @@ -321,12 +324,6 @@ ) : '' %> -% my $pager = include ( '/elements/pager.html', -% 'offset' => $offset, -% 'num_rows' => scalar(@$rows), -% 'total' => $total, -% 'maxrecords' => $maxrecords, -% ); % % unless ( $total ) { % unless ( $opt{'disable_nonefound'} ) { @@ -335,11 +332,32 @@ % } % } else { - + + % unless ( $opt{'disable_download'} ) { +% $cgi->param('_type', "html" ); % }
+ +
+ <% $total %> total <% $opt{'name'} %> + +% if ( $confmax && $total > $confmax ) { +% $cgi->delete('maxrecords'); +% $cgi->param('_dummy', 1); + +%# ( show + +% foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) { + +% } + + per page ) + +% $cgi->param('maxrecords', $maxrecords); +% } + + <% defined($opt{'html_posttotal'}) ? ( ref($opt{'html_posttotal'}) ? &{$opt{'html_posttotal'}}() @@ -348,14 +366,18 @@ : '' %>
+ % if ( $opt{'count_addl'} ) { -% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { +% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { - <% sprintf( $count, $count_arrayref->[++$n] ) %>
-% } + <% sprintf( $count, $count_arrayref->[++$n] ) %>
+ +% } % } +
@@ -367,12 +389,19 @@ as CSV file
- <% $pager %> + + <% my $pager = include ( '/elements/pager.html', + 'offset' => $offset, + 'num_rows' => scalar(@$rows), + 'total' => $total, + 'maxrecords' => $maxrecords, + ) %> <% include('/elements/table-grid.html') %> @@ -545,4 +574,3 @@ <% include( '/elements/footer.html' ) %> % } % } -