--- lib/Arh/View.pm 2007/11/29 12:36:51 6 +++ lib/Arh/View.pm 2007/11/30 23:23:14 23 @@ -8,61 +8,71 @@ use Data::Dump qw/dump/; template '/pictures' => page { - h1 { _("Pictures available in system") }; 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 { - row { - cell { _('Part of campaign') } - cell { _('Picture filename') } - cell { _('Type of picture') } - cell {} - }; while ( my $f = $fc->next ) { $present->{ $f->filename }++; my $delete = new_action( class => 'DeletePicture' ); + my $update = new_action( class => 'UpdatePicture', record => $f ); row { - cell { $f->campaign->name } cell { + attr { class => 'picture' }; img { attr { src => "static/pics/" . $f->filename } } div { tt{ $f->filename } } } - cell { $f->type->name } cell { - $delete->button( - submit => $delete, - label => _('Delete'), - arguments => { - id => $f->id, + 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 => 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' ); + warn "current_user->id: ",current_user->id; + if ( current_user->id ) { row { - cell { render_param( $create => 'campaign' ) } - cell { - img { attr { src => "static/pics/$f" } } - div { tt{ $f } } - } - cell { render_param( $create => 'type' ) } - cell { - $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, + } + ); + } } } } @@ -70,5 +80,64 @@ } }; + +use Jifty::View::Declare::CRUD; +Jifty::View::Declare::CRUD->mount_view('materials'); + +use Jifty::View::Declare::CRUD; +Jifty::View::Declare::CRUD->mount_view('units'); + +template '/units' => page { + h1 { _("Units available in system") }; + + 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, + } + ); + +}; + +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 { + hyperlink( + label => $label, + onclick => { + submit => $toggleedit, + refresh_self => 1, + }, + ) + } + +}; 1;