--- lib/Arh/View/Units.pm 2008/04/08 21:34:16 66 +++ lib/Arh/View/Units.pm 2008/04/19 23:07:08 80 @@ -10,7 +10,11 @@ sub object_type { 'Unit' }; -sub per_page { get('per_page') || 5 }; +sub per_page { + my $per_page = get('per_page') || 3; + warn "## Units per_page = $per_page\n"; + return $per_page; +}; sub display_columns { my $self = shift; @@ -58,6 +62,73 @@ #private template search_region => sub {}; +=for later + +template 'index.html' => page { + my $self = shift; + title is $self->object_type; + form { + render_region( + name => $self->object_type.'-list', + path => $self->fragment_base_path.'/list' + ); + }; +}; + +template 'list' => sub { + my $self = shift; + + my ( $page ) = get('page'); + + my $item_path = get('item_path') || $self->fragment_for("view"); + my $collection = $self->_current_collection(); + + if ( $self->per_page == 1 ) { + warn "## bulk import get to last page\n"; + $page = $collection->pager->last_page; + } + + div { + {class is 'crud-'.$self->object_type}; + + show('./search_region'); + show( './paging_top', $collection, $page ); + show( './paging_bottom', $collection, $page ); + show( './list_items', $collection, $item_path ); + show( './paging_bottom', $collection, $page ); + + show( './new_item_region'); + } + +}; + +=cut + +=head2 single + +display singe unit on page, using C or C for unit id + +=cut + +template 'single' => page { + my $self = shift; + + my $id = get('unit') || get('id') || warn "no unit or id?"; + + my $item = Arh::Model::Unit->new; + $item->load( $id ); + die _("Can't find item %1", $id) unless $item->id; + + title is $item->name; + + render_region( + name => 'item-' . $item->id, + path => $self->fragment_for('view'), + defaults => { id => $item->id, object_type => $self->object_type } + ); + +}; + private template 'paging_top' => sub { my $self = shift; my $collection = shift; @@ -75,11 +146,69 @@ $collection->pager->last_page ) ); - } + } } - show( './paging_bottom', $collection, $page ); +}; + +private template paging_bottom => sub { + my $self = shift; + my $collection = shift; + my $page = shift || 0; + div { + { class is 'paging' }; + if ( $collection->pager->previous_page ) { + span { + hyperlink( + label => _("Previous Page"), + onclick => { + args => { page => $collection->pager->previous_page } + } + ); + } + } + + my ( $f_p, $t_p ) = ( '...', '...' ); + + my $from = $page - 15; + if ( $from < 0 ) { + $from = $collection->pager->first_page; + $f_p = ''; + } + my $to = $page + 15; + if ( $to > $collection->pager->last_page ) { + $to = $collection->pager->last_page; + $t_p = ''; + } + + outs $f_p; + + foreach my $p ( $from .. $to ) { + if ( $p == $page ) { + b { $p } + } else { + span { + hyperlink( + label => $p, + onclick => + { args => { page => $p } } + ); + } + } + } + outs $t_p; + + if ( $collection->pager->next_page ) { + span { + hyperlink( + label => _("Next Page"), + onclick => + { args => { page => $collection->pager->next_page } } + ); + } + } + }; }; @@ -102,8 +231,7 @@ div { { class is 'unit' } - if ( $editing ) { - form { + if ( $editing ) { outs_raw($delete->button( label => _('Delete unit'), class => 'float-crud-button button-delete', @@ -117,10 +245,7 @@ }, )); }; - }; - - form { foreach my $f ( $self->display_columns ) { if ( $f eq 'material' ) { set( search_collection => $record->material ); @@ -151,10 +276,9 @@ submit => $update, refresh_self => 1, }, - ) - }; + ); + } } - }; }; # div class unit @@ -173,7 +297,7 @@ h1 { _("New unit") }; - form { + div { foreach my $f ( $self->display_columns ) { # last if $f eq 'material' && ! $id; @@ -204,7 +328,7 @@ ], as_button => 1, ); - } + }; }; };