/[Frey]/trunk/lib/Frey/View/NoPager.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/View/NoPager.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 962 by dpavlin, Wed Jan 7 17:50:03 2009 UTC revision 963 by dpavlin, Wed Jan 7 20:31:51 2009 UTC
# Line 11  use JSON::Syck; Line 11  use JSON::Syck;
11  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
12    
13  has search => (  has search => (
14            documentation => 'Search for',
15          is => 'rw',          is => 'rw',
16          isa => 'Str',          isa => 'Str',
17  #       required => 1,  #       required => 1,
18          default => '',          default => '',
19  );  );
20    
21  has 'on_page' => (      # FIXME Frey::Web->page, sigh!  has 'page' => (
22            documentation => 'display page',
23          is => 'rw',          is => 'rw',
24          isa => 'Int',          isa => 'Int',
25          default => 1,          default => 1,
26  );  );
27    
28    has 'on_page' => (
29            documentation => 'numer of items on page',
30            is => 'rw',
31            isa => 'Int',
32            default => 30,
33    );
34    
35  has 'sort' => (  has 'sort' => (
36          is => 'rw',          is => 'rw',
37          isa => 'Str',          isa => 'Str',
38            default => '',
39  );  );
40    
 our $v = {  
         search => '',  
         hits => 0,  
         page => 0,  
         max_page => 0,  
         time => '',  
         id => time() . rand(99),  
 };  
   
 our $json;  
   
 sub json {  
         my ($self) = @_;  
         return  
         '<textarea id="json" style="display:none">' .  
         $self->html_escape( JSON::Syck::Dump( $v ) ) .  
         '</textarea>';  
 }  
   
41  sub results_as_markup {  sub results_as_markup {
42          my ($self) = @_;          my ($self) = @_;
43    
44          my ($search,$page) = ( $self->search , $self->on_page );          my ( $search,$page ) = ( $self->search , $self->page );
45    
46            my $v = {
47                    search => $search,
48                    page => $page,
49                    max_page => $page,
50                    id => time() . rand(99),
51            };
52    
53          sub next_page {          sub next_page {
54                  my $self = shift;                  my $self = shift;
55                  return                  my $json = $self->html_escape( JSON::Syck::Dump( $v ) );
56                     qq|<div id="next_page">|  
57                   . join("\n", @_) . $self->json()                  my $message = join("\n", @_);
58                   . qq|</div>|  
59                   ;                  # <textarea id="json" style="display:none">
60                    return qq|
61                            <div id="next_page">
62                                    $message
63                                    <textarea id="json">
64                                    $json
65                                    </textarea>
66                            </div>
67                    |
68                    ;
69          }          }
70    
71          if (! $search || $search =~ m/^\s*$/) {          if (! $search || $search =~ m/^\s*$/) {
# Line 66  sub results_as_markup { Line 73  sub results_as_markup {
73                  return $self->next_page;                  return $self->next_page;
74          }          }
75    
         if (! $page) {  
                 $v->{status} = 'Error: no page number?';  
                 return $self->next_page;  
         }  
   
76          $search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/);          $search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/);
         $v->{search} = $search;  
   
         $v->{page} = $page;  
77    
78          my $node = new Search::Estraier::Node(%{ $self->config->{estraier} });          my $node = new Search::Estraier::Node(%{ $self->config->{estraier} });
79    
80          my $on_page = 30;          my $on_page = $self->on_page;
81          my $skip = ( $page - 1 ) * $on_page;          my $skip = ( $page - 1 ) * $on_page;
82    
83          my $cond = new Search::Estraier::Condition;          my $cond = new Search::Estraier::Condition;
# Line 87  sub results_as_markup { Line 86  sub results_as_markup {
86          $cond->set_skip( $skip );          $cond->set_skip( $skip );
87          $cond->set_order( $self->sort ) if $self->sort;          $cond->set_order( $self->sort ) if $self->sort;
88    
89            warn "INFO: estraier for '$search' page $page with $on_page items, first $skip";
90    
91          my $nres = $node->search($cond, ( $self->config->{estraier}->{depth} || 0 ) );          my $nres = $node->search($cond, ( $self->config->{estraier}->{depth} || 0 ) );
92    
93          my $out;          my $out;
# Line 191  sub results_as_markup { Line 192  sub results_as_markup {
192                  );                  );
193          }          }
194    
195          $self->wrap_in_page( 0 ); # disable <body> and status bar          warn "# v = ", dump( $v );
196    
197            return ( $out, $v->{status} ) if wantarray;
198    
199            $self->wrap_in_page( 0 ); # disable <body> and status bar for ajax call
200          return $out;          return $out;
201    
202  }  }
# Line 213  sub as_markup { Line 217  sub as_markup {
217                  });                  });
218          |);          |);
219    
220            my ( $results, $status ) = $self->results_as_markup;
221    
222          my $html = join("\n",          my $html = join("\n",
223          qq|          qq|
224                  <div id="search_form_div">                  <div id="search_form_div">
# Line 223  sub as_markup { Line 229  sub as_markup {
229                                  <input type="submit" class="submit" value="search">                                  <input type="submit" class="submit" value="search">
230    
231                                  <span id="status" class="note">                                  <span id="status" class="note">
232                                  |, $v->{status}, qq|                                          $status
233                                  </span>                                  </span>
234    
235                          </form>                          </form>
# Line 231  sub as_markup { Line 237  sub as_markup {
237    
238                  <div style="margin-top: 3em;">                  <div style="margin-top: 3em;">
239                  <!-- Dynamic Content -->                  <!-- Dynamic Content -->
240                          |, $self->results_as_markup, qq|                          $results
241    
242                          <!-- Back Button Content -->                          <!-- Back Button Content -->
243                          <div style="position:absolute;top:0px;left:0px;visibility:hidden;" id="spacer">space</div>                          <div style="position:absolute;top:0px;left:0px;visibility:hidden;" id="spacer">space</div>
# Line 245  sub as_markup { Line 251  sub as_markup {
251          |          |
252          );          );
253    
         $self->wrap_in_page( 1 ); # FIXME results_as_markup will turn it off  
254          return $html;          return $html;
255  }  }
256    

Legend:
Removed from v.962  
changed lines
  Added in v.963

  ViewVC Help
Powered by ViewVC 1.1.26