AcePerl
view release on metacpan or search on metacpan
Ace/Browser/SearchSubs.pm view on Meta::CPAN
MAXOBJECTS The maximum number of objects that can be displayed
per page.
SEARCH_ICON An icon to use for search links. This is deprecated.
Use Configuration->Search_icon instead.
=head2 FUNCTIONS
These functions are exported:
=over 4
=cut
# Common constants and subroutines used by the various search scripts
use strict;
use vars qw(@ISA @EXPORT $VERSION);
use Ace::Browser::AceSubs qw(Configuration Url ResolveUrl);
use CGI qw(:standard *table *Tr *td);
require Exporter;
@ISA = qw(Exporter);
$VERSION = '1.30';
######################### This is the list of exported subroutines #######################
@EXPORT = qw(
MAXOBJECTS
SEARCH_ICON
AceSearchTable AceResultsTable AceSearchOffset
DisplayInstructions
);
# ----- constants used by the pattern search script ------
use constant ROWS => 10; # how many rows to allocate for search results
use constant COLS => 5; # " " columns " " " "
use constant MAXOBJECTS => ROWS * COLS; # total objects per screen
use constant ICONS => '/ico';
use constant SEARCH_ICON => '/ico/search.gif';
use constant SPACER_ICON => 'spacer.gif';
use constant LEFT_ICON => 'cylarrw.gif';
use constant RIGHT_ICON => 'cyrarrw.gif';
=item $offset = AceSearchOffset()
When the user is paging back and forth among a multi-page list of
results, this function returns the index of the first item to display.
=cut
sub AceSearchOffset {
my $offset = param('offset') || 0;
$offset += param('scroll') if param('scroll');
$offset;
}
=item AceSearchTable([{hash}],$title,@contents)
Given a title and the HTML contents, this formats the search into a
table and gives it the background and foreground colors used elsewhere
for searches. The formatted search is then printed.
The HTML contents are usually a fill-out form. For convenience, you
can provide the contents in multiple parts (lines or elements) and
they will be concatenated together.
If the first argument is a hashref, then its contents will be passed
to start_form() to override the form arguments.
=cut
sub AceSearchTable {
my %attributes = %{shift()} if ref($_[0]) eq 'HASH';
my ($title,@body) = @_;
print
start_form(-action=>url(-absolute=>1,-path_info=>1).'#results',%attributes),
a({-name=>'search'},''),
table({-border=>0,-width=>'100%'},
TR({-valign=>'MIDDLE'},
td({-class=>'searchbody'},@body))),
end_form;
}
=item AceResultsTable($objects,$count,$offset,$title)
This subroutine formats the results of a search into a pageable list
and prints out the resulting HTML. The following arguments are required:
$objects An array reference containing the objects to place in the
table.
$count The total number of objects.
$offset The offset into the array, as returned by AceSearchOffset()
$title A title for the table.
The array reference should contain no more than MAXOBJECTS objects.
The AceDB query should be arranged in such a way that this is the
case. A typical idiom is the following:
my $offset = AceSearchOffset();
my $query = param('query');
my $count;
my @objs = $db->fetch(-query=> $query,
-count => MAXOBJECTS,
-offset => $offset,
-total => \$count
);
AceResultsTable(\@objs,$count,$offset,'Here are the results');
=cut
sub AceResultsTable {
my ($objects,$count,$offset,$title) = @_;
Delete('scroll');
param(-name=>'offset',-value=>$offset);
my @cheaders = map { $offset + ROWS * $_ } (0..(@$objects-1)/ROWS) if @$objects;
my @rheaders = (1..min(ROWS,$count));
( run in 1.469 second using v1.01-cache-2.11-cpan-d8267643d1d )