--- lib/Arh/View.pm 2007/11/29 19:32:41 12 +++ lib/Arh/View.pm 2008/04/06 21:07:20 55 @@ -7,106 +7,62 @@ use Data::Dump qw/dump/; -template '/pictures' => page { - my $fc = Arh::Model::PictureCollection->new; - $fc->unlimit; - my $present; - form { - if ( $fc->count ) { - h1 { _("Pictures available in system") }; - } - table { - while ( my $f = $fc->next ) { - $present->{ $f->filename }++; - my $delete = new_action( class => 'DeletePicture' ); - my $update = new_action( class => 'UpdatePicture', record => $f ); - row { - cell { - attr { class => 'picture' }; - img { attr { src => "static/pics/" . $f->filename } } - div { tt{ $f->filename } } - } - cell { - attr { class => 'picture-description' }; - render_param( $update => 'campaign', render_mode => 'read' ); - render_param( $update => 'type', render_mode => 'read' ); - if ( $f->current_user_can('write') ) { - div { - $delete->button( - submit => $delete, - label => _('Delete'), - arguments => { - id => $f->id, - } - ) - } - } - } - } - } - 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' ); - 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, - } - ); - } - } - } +use Jifty::View::Declare::CRUD; +Jifty::View::Declare::CRUD->mount_view('materials'); +Jifty::View::Declare::CRUD->mount_view('UnitPictures'); +Jifty::View::Declare::CRUD->mount_view('units'); +#Jifty::View::Declare::CRUD->mount_view('locations'); + +template '/units' => page { + h1 { _("Units available in system") }; + + my $search = Arh::Model::UnitCollection->new; + $search->unlimit; + + show( 'toggle_edit' ) if $search->count; + + set( search_collection => $search ); + render_region( + name => 'units', + path => '/units/list', + defaults => { + page => 1, } - } + ); }; -template '/units' => page { - h1 { _("Units available in system") }; +template 'toggle_edit' => sub { + my $self = shift; + + my $toggleedit = new_action( + class => 'ToggleEdit', +# moniker => 'toggle-edit', + ); - my $units = Arh::Model::UnitCollection->new; - $units->unlimit; + my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing"); - while ( my $u = $units->next ) { - unit( $u ); + warn "## $label\n"; + + form { + outs_raw( $toggleedit->button( + label => $label, + submit => $toggleedit, + )); } + }; -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/ ) { - 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' ); - } - } else { - my %opt; - $opt{render_mode} = 'read'; # unless - warn "write $f ",$unit->current_user_can('write',$f) ? 'ok' : 'DENIED'; - render_param( $a => $f, %opt ); - } - } +template 'raw_pic' => sub { + my $filename = get('filename') or die "no filename?"; + my $image = Arh::Model::Picture->new; + $image->load_by_cols( filename => $filename ); + if ( $image->id ) { + Jifty->handler->apache->content_type('image/jpg'); + Jifty->web->out($image->content); + } else { + die "can't find picture $filename"; } -} +}; 1;