--- lib/Arh/View.pm 2007/11/29 19:32:41 12 +++ lib/Arh/View.pm 2007/12/10 14:56:12 28 @@ -7,13 +7,15 @@ use Data::Dump qw/dump/; -template '/pictures' => page { +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 ) { @@ -23,7 +25,7 @@ row { cell { attr { class => 'picture' }; - img { attr { src => "static/pics/" . $f->filename } } + img { attr { src => "/static/pics/" . $f->filename } } div { tt{ $f->filename } } } cell { @@ -34,7 +36,7 @@ div { $delete->button( submit => $delete, - label => _('Delete'), + label => _('Delete picture'), arguments => { id => $f->id, } @@ -44,30 +46,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, + } + ); + } } } } @@ -76,37 +81,63 @@ }; +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 $units = Arh::Model::UnitCollection->new; - $units->unlimit; + show( 'toggle_edit' ); + + my $search = Arh::Model::UnitCollection->new; + $search->unlimit; + + set( search_collection => $search ); + render_region( + name => 'units', + path => '/units/list', + defaults => { + page => 1, + } + ); - while ( my $u = $units->next ) { - unit( $u ); - } }; -sub unit { - my $unit = shift || die "no unit?"; - my $a = new_action( class => 'UpdateUnit', record => $unit ); - warn "## current_user = ",dump( current_user ); +private template '/toggle_edit' => sub { + my $self = shift; + + # no fun for anonymous users + return unless $self->current_user->id; + + render_region( + name => 'toggle-edit', + path => '/toggle_edit_region', + ); + +}; + +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 { - 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 ); - } - } + hyperlink( + label => $label, + onclick => { + submit => $toggleedit, + refresh_self => 1, + }, + ) } -} + +}; 1;