--- lib/Arh/View/Units.pm 2007/11/30 20:13:06 22 +++ lib/Arh/View/Units.pm 2007/11/30 23:23:14 23 @@ -8,21 +8,50 @@ sub object_type { 'Unit' }; +sub display_columns { + my $self = shift; + return ( qw/name inv_id campaign material dimensions discovered_at description chronology location/ ); +} + #private template search_region => sub {}; 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'; + + + if ( $editing ) { + form { + outs_raw($delete->button( + label => _('Delete'), + class => 'float-crud-button', + 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 +64,11 @@ ); } else { my %opt; - $opt{render_mode} = 'read' if ! $can_write; + $opt{render_mode} = 'read' if ! $editing; render_param( $update => $f, %opt ); } }; - if ( $can_write ) { + if ( $editing ) { div { { class is 'submit_button' }; hyperlink( @@ -55,4 +84,48 @@ 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 ) { + render_param( $create => $f ) unless $f eq 'material'; + } + + 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;