summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2006-10-25 17:36:28 +0000
committerivan <ivan>2006-10-25 17:36:28 +0000
commit5eb3dab3ea20a9861074a41bef19c9ac4dcb2336 (patch)
treeaa65377cb8b9f0f32f2d05b3a441b828ef2a3d7b /httemplate
parent3a060deb9ca28876b17b4f6781abee3d1e233ba0 (diff)
pagination patch from UNTD - limit the number of page links displayed and have a drop-down option for selecting number of entries per page
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/elements/pager.html64
-rwxr-xr-xhttemplate/search/cust_main.cgi34
-rw-r--r--httemplate/search/elements/search.html62
3 files changed, 90 insertions, 70 deletions
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'});
<A HREF="<% $cgi->self_url %>"><B><FONT SIZE="+1">Previous</FONT></B></A>
+
+% }
%
-% }
-% 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 ) {
<FONT SIZE="+2"><% $page %></FONT>
-%
-% } else {
-% $cgi->param('offset', $poff);
-%
+% } else {
+% $cgi->param('offset', $poff);
+%
+% if ( $page > $prevpage+1 ) {
+ ...
+% }
<A HREF="<% $cgi->self_url %>"><% $page %></A>
+
+% }
%
-% }
-% }
-% 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'});
<A HREF="<% $cgi->self_url %>"><B><FONT SIZE="+1">Next</FONT></B></A>
%
-% }
-% }
+% }
%
-
+% }
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 .= '<A HREF="'. $cgi->self_url.
-% '"><B><FONT SIZE="+1">Previous</FONT></B></A> ';
-% }
-% my $poff;
-% my $page;
-% for ( $poff = 0; $poff < $total; $poff += $maxrecords ) {
-% $page++;
-% if ( $offset == $poff ) {
-% $pager .= qq!<FONT SIZE="+2">$page</FONT> !;
-% } else {
-% $cgi->param('offset', $poff);
-% $pager .= qq!<A HREF="!. $cgi->self_url. qq!">$page</A> !;
-% }
-% }
-% unless ( $offset + $maxrecords > $total ) {
-% $cgi->param('offset', $offset + $maxrecords);
-% $pager .= '<A HREF="'. $cgi->self_url.
-% '"><B><FONT SIZE="+1">Next</FONT></B></A> ';
-% }
-% }
-% #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 {
-
<TABLE>
<TR>
+
<TD VALIGN="bottom">
+
+ <FORM>
+
<% $total %> total <% $opt{'name'} %>
+
+% if ( $confmax && $total > $confmax ) {
+% $cgi->delete('maxrecords');
+% $cgi->param('_dummy', 1);
+
+%# ( show <SELECT NAME="maxrecords" onChange="this.form.submit();">
+ ( show <SELECT NAME="maxrecords" onChange="window.location = '<% $cgi->self_url %>;maxrecords=' + this.options[this.selectedIndex].value;">
+
+% foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
+ <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
+% }
+
+ </SELECT> per page )
+
+% $cgi->param('maxrecords', $maxrecords);
+% }
+
+
<% defined($opt{'html_posttotal'})
? ( ref($opt{'html_posttotal'})
? &{$opt{'html_posttotal'}}()
@@ -348,14 +366,18 @@
: ''
%>
<BR>
+
% 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] ) %><BR>
-% }
+ <% sprintf( $count, $count_arrayref->[++$n] ) %><BR>
+
+% }
% }
+ </FORM>
</TD>
+
% unless ( $opt{'disable_download'} ) {
<TD ALIGN="right">
@@ -367,12 +389,19 @@
as <A HREF="<% $cgi->self_url %>">CSV file</A>
</TD>
+% $cgi->param('_type', "html" );
% }
</TR>
<TR>
<TD COLSPAN=2>
- <% $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' ) %>
% }
% }
-