--- lib/Arh/View.pm 2007/11/29 19:32:41 12 +++ lib/Arh/View.pm 2007/11/30 00:03:15 13 @@ -44,30 +44,33 @@ } } } - row { - cell { attr { colspan => 2 } h1 { _('Pending pictures') } } - }; - warn "## present = ",dump( $present ); - foreach my $f ( Arh::Model::Picture->all_filenames ) { - next if $present->{$f}; - my $create = new_action( class => 'CreatePicture' ); + warn "current_user->id: ",current_user->id; + if ( current_user->id ) { row { - cell { - attr { class => 'picture' }; - img { attr { src => "static/pics/$f" } } - div { tt{ $f } } - } - cell { - attr { class => 'picture-description' }; - render_param( $create => 'campaign' ); - render_param( $create => 'type' ); - $create->button( - submit => $create, - label => _('Add'), - arguments => { - filename => $f, - } - ); + cell { attr { colspan => 2 } h1 { _('Pending pictures') } } + }; + warn "## present = ",dump( $present ); + foreach my $f ( Arh::Model::Picture->all_filenames ) { + next if $present->{$f}; + my $create = new_action( class => 'CreatePicture' ); + row { + cell { + attr { class => 'picture' }; + img { attr { src => "static/pics/$f" } } + div { tt{ $f } } + } + cell { + attr { class => 'picture-description' }; + render_param( $create => 'campaign' ); + render_param( $create => 'type' ); + $create->button( + submit => $create, + label => _('Add'), + arguments => { + filename => $f, + } + ); + } } } } @@ -90,23 +93,58 @@ sub unit { my $unit = shift || die "no unit?"; my $a = new_action( class => 'UpdateUnit', record => $unit ); - warn "## current_user = ",dump( current_user ); form { foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { + my $can_write = $unit->current_user_can('write',$f); + #warn "write $f ",$can_write ? 'ok' : 'DENIED'; if ( $f eq 'material' ) { - my $material = $unit->material; - while ( my $um = $material->next ) { - my $m = new_action( class => 'UpdateMaterial', record => $um->material ); - render_param( $m => 'name', label => _("Material"), render_mode => 'read' ); - } + set( UnitMaterialCollection => $unit->material ); + show( '/unit/materials' ); } else { my %opt; - $opt{render_mode} = 'read'; # unless - warn "write $f ",$unit->current_user_can('write',$f) ? 'ok' : 'DENIED'; + $opt{render_mode} = 'read' if ! $unit->current_user_can('write',$f); render_param( $a => $f, %opt ); } } } } +template '/unit/materials' => sub { + my $materials = get('UnitMaterialCollection'); + my $del_um = new_action( class => 'DeleteUnitMaterial', moniker => 'del_um' ); + my $new_um = new_action( class => 'CreateUnitMaterial', moniker => 'new_um' ); + my $can_write; + while ( my $um = $materials->next ) { + div { attr { class is 'form_field' } + span { + span { attr { class is 'label' } _("Material") }; + span { $um->material->name }; + + $can_write ||= $um->current_user_can('write'); + if ( $can_write ) { + outs_raw($del_um->button( + submit => $del_um, + label => _('Delete'), + arguments => { + unit => $um->unit, + material => $um->material + }, + )); + } + } + }; + + if ( $can_write ) { + render_param( + $new_um => 'material', label => _("Material"), + render_as => 'Arh::Web::Material', + # cludge to transfer arguments + hints => { + unit => $um->unit, + }, + ); + } + } +}; + 1;