--- lib/Arh/View/Units.pm 2007/12/10 14:56:12 28 +++ lib/Arh/View/Units.pm 2008/04/08 23:38:42 69 @@ -6,15 +6,127 @@ 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') || 5; + 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 + +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 ); +}; + + template 'view' => sub :CRUDView { my $self = shift; my $id = get('id'); @@ -34,8 +146,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 +160,7 @@ }, )); }; - }; - - form { foreach my $f ( $self->display_columns ) { if ( $f eq 'material' ) { set( search_collection => $record->material ); @@ -66,7 +174,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 +191,9 @@ submit => $update, refresh_self => 1, }, - ) - }; + ); + } } - }; }; # div class unit @@ -95,17 +206,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 +227,8 @@ onclick => [ { submit => $create, - # args => { - # }, +# args => { +# }, }, { refresh_self => 1 }, { @@ -131,7 +243,7 @@ ], as_button => 1, ); - } + }; }; };