--- lib/Arh/View.pm 2007/11/29 15:13:10 7 +++ lib/Arh/View.pm 2008/04/07 09:20:01 59 @@ -7,65 +7,65 @@ use Data::Dump qw/dump/; -template '/pictures' => page { - h1 { _("Pictures available in system") }; - my $fc = Arh::Model::PictureCollection->new; - $fc->unlimit; - my $present; - form { - table { - while ( my $f = $fc->next ) { - $present->{ $f->filename }++; - my $delete = new_action( class => 'DeletePicture' ); - row { - cell { - img { attr { src => "static/pics/" . $f->filename } } - div { tt{ $f->filename } } - } - cell { - ul { - li { _("Part of campaign"), ': ', $f->campaign->name; } - li { _("Type of picture"), ': ', $f->type->name } - div { $delete->button( - submit => $delete, - label => _('Delete'), - arguments => { - id => $f->id, - } - ) - } - } - } - } - } - row { - cell { attr { colspan => 4 } outs _('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 { - img { attr { src => "static/pics/$f" } } - div { tt{ $f } } - } - cell { - 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 'toggle_edit' => sub { + my $self = shift; + + # don't show editing for anonymous users + return unless $self->current_user->id; + + my $toggleedit = new_action( + class => 'ToggleEdit', +# moniker => 'toggle-edit', + ); + + my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing"); + + warn "## $label\n"; + + form { + outs_raw( $toggleedit->button( + label => $label, + 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"; + } +}; + 1;