1 |
<%args> |
2 |
$q |
3 |
$max => 10 |
4 |
$item_fragment => 'long' |
5 |
$coll => undef |
6 |
$result_moniker => 'search' |
7 |
$result => undef |
8 |
</%args> |
9 |
<%init> |
10 |
|
11 |
use Data::Dump qw/dump/; |
12 |
|
13 |
$result ||= Jifty->web->response->result( $result_moniker ); |
14 |
if ( $result and $result->content('search') ) { |
15 |
$coll = $result->content('search'); |
16 |
} elsif (! defined($coll)) { |
17 |
warn "called without result for $result_moniker"; |
18 |
} |
19 |
|
20 |
#warn "notes: ",dump($result->message, $result->error) if ($result); |
21 |
|
22 |
my $pos = 1; |
23 |
|
24 |
my ($prev,$next) = (undef, $pos + 1); |
25 |
|
26 |
my $uid = time(); |
27 |
|
28 |
</%init> |
29 |
% if ($result and $result->message) { |
30 |
<div class="grep-note"> |
31 |
<div class="message"><% $result->message %></div> |
32 |
</div> |
33 |
% } |
34 |
% if ($result and $result->error) { |
35 |
<div class="grep-note"> |
36 |
<div class="error"><% $result->error %></div> |
37 |
</div> |
38 |
% } |
39 |
% if ($coll) { |
40 |
% my $count = $coll->count; |
41 |
<div class="results"> |
42 |
% while ( my $i = $coll->next and $pos <= $max ) { |
43 |
% $next = ( $pos == $max or $pos == $count ) ? undef : $pos + 1; |
44 |
<& "/fragments/item/$item_fragment", item => $i, pos => "$uid-$pos", prev => $prev ? "$uid-$prev" : undef, next => $next ? "$uid-$next" : undef &> |
45 |
% $prev = $pos++; |
46 |
% } |
47 |
</div> |
48 |
% if ($pos > $max and $pos < $count ) { |
49 |
<div class="grep-note"> |
50 |
<div class="message"> |
51 |
Found more than <% $max %> results for '<% $q %>', refine search query.... |
52 |
</div> |
53 |
</div> |
54 |
% } |
55 |
% } |