/[Frey]/trunk/lib/Frey/ORM/Pager.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/ORM/Pager.pm

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

revision 143 by dpavlin, Wed Jul 16 14:17:46 2008 UTC revision 207 by dpavlin, Fri Oct 31 15:33:15 2008 UTC
# Line 33  has 'items' => ( Line 33  has 'items' => (
33          },          },
34  );  );
35    
36    has 'range_around' => (
37            is => 'rw',
38            isa => 'Int',
39            default => 10,
40    );
41    
42    sub first_item {
43            my $self = shift;
44            $self->items->[0];
45    }
46    
47  sub last_item {  sub last_item {
48          my $self = shift;          my $self = shift;
         warn "## last_item = ",  
49          my $last = $#{ $self->items };          my $last = $#{ $self->items };
50          $self->update_collection if $last < 0;          $self->update_collection if $last < 0;
51          $self->items->[ $#{ $self->items } ];          $self->items->[ $#{ $self->items } ];
# Line 54  sub update_collection { Line 64  sub update_collection {
64    
65          warn "## update_collection from iterator";          warn "## update_collection from iterator";
66    
67            if ( ! $self->fey_class->can('collection') ) {
68                    warn "ERROR: ", $self->fey_class, " can't do collection";
69                    return;
70            }
71    
72          my $i = $self->fey_class->collection( $self->pager );          my $i = $self->fey_class->collection( $self->pager );
73          while ( my $u = $i->next ) {          while ( my $u = $i->next ) {
74                  $self->add_item(                  $self->add_item(
# Line 101  sub render_pager { Line 116  sub render_pager {
116    
117          my $pager = $self->pager;          my $pager = $self->pager;
118    
119            my @show_pages;
120            my $after_current = 0;
121    
122            if ( $pager->current_page <= $self->range_around + 2 ) {
123                    @show_pages = ( $pager->first_page .. $pager->current_page );
124                    $after_current = $self->range_around - $pager->current_page;
125            } else {
126                    @show_pages = ( $pager->first_page, '', $pager->current_page - $self->range_around .. $pager->current_page );
127            }
128    
129            if ( $pager->current_page + $self->range_around + 1 >= $pager->last_page ) {
130                    push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );
131            } else {
132                    push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $self->range_around, '', $pager->last_page );
133            }
134    
135            warn "## show_pages = ",dump( @show_pages );
136    
137          return join( ' ',          return join( ' ',
138                          qq|<div class="notice">|,                          qq|<div class="notice">|,
139                          'Showing',                          'Showing',
# Line 112  sub render_pager { Line 145  sub render_pager {
145                          Frey::Web::Links->new(                          Frey::Web::Links->new(
146                                  name => 'page',                                  name => 'page',
147                                  current => $pager->current_page,                                  current => $pager->current_page,
148                                  values => [ $pager->first_page .. $pager->last_page ],                                  values => \@show_pages,
149                                    empty => '...',
150                                    current_tag => 'b',
151                          )->links,                          )->links,
152                          qq|</div>|                          qq|</div>|
153                  );                  );

Legend:
Removed from v.143  
changed lines
  Added in v.207

  ViewVC Help
Powered by ViewVC 1.1.26