--- lib/Arh/View/Units.pm 2007/12/10 14:56:12 28 +++ lib/Arh/View/Units.pm 2008/04/19 21:36:07 78 @@ -6,15 +6,212 @@ use base 'Jifty::View::Declare::CRUD'; use Jifty::View::Declare -base; +use Data::Dump qw/dump/; + sub object_type { 'Unit' }; +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; - return ( qw/name inv_id campaign material dimensions discovered_at description chronology location/ ); + return ( qw/ + unit_id + name + subcategory + category + site + gps + placement + context + discovery + function + reusage + ownership + presevation_place + inventory_nr + dimensions + condition + toplogy + technique + description + construction + iconography + decoration + motifs + inscription + language + font + author + chronology + chronostyle + explored + conservations + restorations + legal + links + sources + bibliography + copyright + material + / ); } #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 + +=cut + +template 'single' => page { + my $self = shift; + + my $id = get('id') || die "no 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; + my $page = shift || 1; + + if ( $collection->pager->last_page > 1 ) { + span { + { class is 'page-count' }; + outs( + _( "Found %1 units, showing %2-%3 on page %4/%5", + $collection->pager->total_entries, + $collection->pager->first, + $collection->pager->last, + $page, + $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 } } + ); + } + } + }; +}; + + template 'view' => sub :CRUDView { my $self = shift; my $id = get('id'); @@ -34,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', @@ -49,10 +245,7 @@ }, )); }; - }; - - form { foreach my $f ( $self->display_columns ) { if ( $f eq 'material' ) { set( search_collection => $record->material ); @@ -66,7 +259,11 @@ ); } else { my %opt; - $opt{render_mode} = 'read' if ! $editing; + if ( ! $editing ) { + $opt{render_mode} = 'read'; + # skip fields without values + $opt{render_as} = 'hidden' if ! defined( $update->record->$f ); + } render_param( $update => $f, %opt ); } }; @@ -79,10 +276,9 @@ submit => $update, refresh_self => 1, }, - ) - }; + ); + } } - }; }; # div class unit @@ -95,17 +291,18 @@ my $self = shift; return unless $self->current_user->editing; - my ( $object_type, $id ) = ( $self->object_type, get('id') ); - my $record_class = $self->record_class; - my $create = $record_class->as_create_action; + my ( $object_type, $id ) = ( $self->object_type, get('id') ); + my $record_class = $self->record_class; + my $create = $record_class->as_create_action; h1 { _("New unit") }; - form { + div { foreach my $f ( $self->display_columns ) { - last if $f eq 'material' && ! $id; - render_param( $create => $f ); # unless $f eq 'material'; +# last if $f eq 'material' && ! $id; + render_param( $create => $f ) unless $f eq 'material'; + #warn "## $f"; } div { @@ -115,8 +312,8 @@ onclick => [ { submit => $create, - # args => { - # }, +# args => { +# }, }, { refresh_self => 1 }, { @@ -131,7 +328,7 @@ ], as_button => 1, ); - } + }; }; };