--- lib/Arh/View/Units.pm 2007/11/30 17:50:34 20 +++ lib/Arh/View/Units.pm 2008/04/08 21:34:16 66 @@ -6,23 +6,122 @@ use base 'Jifty::View::Declare::CRUD'; use Jifty::View::Declare -base; +use Data::Dump qw/dump/; + sub object_type { 'Unit' }; +sub per_page { get('per_page') || 5 }; + +sub display_columns { + my $self = shift; + 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 {}; +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 $record = $self->_get_record( get('id') ); + my $id = get('id'); + my $record = $self->_get_record( $id ); my $update = $record->as_update_action( moniker => "update-" . Jifty->web->serial, ); - my $can_write = $record->current_user_can('write'); - #warn "write ",$can_write ? 'ok' : 'DENIED'; + my $delete = $record->as_delete_action( + moniker => "delete-" . Jifty->web->serial, + ); + my $editing = $record->current_user_can('write'); + warn "## current_user_can('write') = $editing\n"; + $editing = 0 unless $self->current_user->editing; + warn "## editing ",$editing ? 'ok' : 'DENIED'; + + div { { class is 'unit' } + + if ( $editing ) { + form { + outs_raw($delete->button( + label => _('Delete unit'), + class => 'float-crud-button button-delete', + onclick => { + submit => $delete, + confirm => _('Really delete?'), +# region => Jifty->web->current_region, + replace_with => '/__jifty/empty', + refresh_self => 1, + args => { id => $id }, + }, + )); + }; + }; + form { - foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { + foreach my $f ( $self->display_columns ) { if ( $f eq 'material' ) { set( search_collection => $record->material ); render_region( @@ -35,11 +134,15 @@ ); } else { my %opt; - $opt{render_mode} = 'read' if ! $can_write; + if ( ! $editing ) { + $opt{render_mode} = 'read'; + # skip fields without values + $opt{render_as} = 'hidden' if ! defined( $update->record->$f ); + } render_param( $update => $f, %opt ); } }; - if ( $can_write ) { + if ( $editing ) { div { { class is 'submit_button' }; hyperlink( @@ -52,7 +155,58 @@ }; } }; + + }; # div class unit + + show('/unitpictures/fragment', $record); + hr {}; }; +template 'new_item' => sub { + 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; + + h1 { _("New unit") }; + + form { + + foreach my $f ( $self->display_columns ) { +# last if $f eq 'material' && ! $id; + render_param( $create => $f ) unless $f eq 'material'; + #warn "## $f"; + } + + div { + { class is 'submit_button' }; + hyperlink( + label => _("Add"), + onclick => [ + { + submit => $create, +# args => { +# }, + }, + { refresh_self => 1 }, + { + element => Jifty->web->current_region->parent->get_element( 'div.list' ), + append => $self->fragment_for('view'), + args => { + object_type => $object_type, + id => { result_of => $create, name => 'id' }, + unit => get('unit'), + }, + }, + ], + as_button => 1, + ); + } + + }; +}; + 1;