--- lib/Arh/View.pm 2007/12/10 14:56:12 28 +++ lib/Arh/View.pm 2008/04/19 21:36:07 78 @@ -7,135 +7,98 @@ 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") }; - } else { - span { outs _("No pubicly available pictures at this time...") } - } - 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 picture'), - arguments => { - id => $f->id, - } - ) - } - } - } - } - } - warn "current_user->id: ",current_user->id; - if ( current_user->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('Materials'); Jifty::View::Declare::CRUD->mount_view('UnitPictures'); -Jifty::View::Declare::CRUD->mount_view('units'); -Jifty::View::Declare::CRUD->mount_view('locations'); +Jifty::View::Declare::CRUD->mount_view('Units'); +Jifty::View::Declare::CRUD->mount_view('Units', 'Arh::View::Units', '/units/bulk' ); +#Jifty::View::Declare::CRUD->mount_view('locations'); template '/units' => page { h1 { _("Units available in system") }; - show( 'toggle_edit' ); - 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, + per_page => get('per_page'), } ); }; -private template '/toggle_edit' => sub { +template 'toggle_edit' => sub { my $self = shift; - # no fun for anonymous users + # don't show editing for anonymous users return unless $self->current_user->id; - render_region( - name => 'toggle-edit', - path => '/toggle_edit_region', + my $toggleedit = new_action( + class => 'ToggleEdit', +# moniker => 'toggle-edit', ); -}; - -template 'toggle_edit_region' => sub { - my $self = shift; - - my $toggleedit = new_action( class => 'ToggleEdit' ); - my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing"); warn "## $label\n"; form { - hyperlink( + outs_raw( $toggleedit->button( label => $label, - onclick => { - submit => $toggleedit, - refresh_self => 1, - }, - ) + submit => $toggleedit, + )); + } + +}; + +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"; + } +}; + +template '/index.html' => page { + my $units = Arh::Model::UnitCollection->new; + $units->unlimit; + $units->order_by( column => 'id', order => 'DESC' ); + + my $last = get('last') || 15; + + h1 { _("Last %1 units entered", $last) }; + + ol { + class is 'units'; + for ( 1 .. $last ) { + my $unit = $units->next || last; + li { + outs( $unit->name, ' ' ); + hyperlink( + label => $unit->unit_id, + url => '/units/single?id=' . $unit->id, + ); + span { class is 'unit details'; + outs join(', ', grep(defined($_), + $unit->subcategory, + $unit->category->name, + $unit->location->name, + $unit->site->name, + )); + } + } + } } };