/[Arh]/lib/Arh/View.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Arh/View.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 13 by dpavlin, Fri Nov 30 00:03:15 2007 UTC revision 55 by dpavlin, Sun Apr 6 21:07:20 2008 UTC
# Line 7  use Jifty::View::Declare -base; Line 7  use Jifty::View::Declare -base;
7    
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9    
10  template '/pictures' => page {  use Jifty::View::Declare::CRUD;
11          my $fc = Arh::Model::PictureCollection->new;  Jifty::View::Declare::CRUD->mount_view('materials');
12          $fc->unlimit;  Jifty::View::Declare::CRUD->mount_view('UnitPictures');
13          my $present;  Jifty::View::Declare::CRUD->mount_view('units');
14          form {  #Jifty::View::Declare::CRUD->mount_view('locations');
                 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,  
                                                                         }  
                                                                 )  
                                                         }  
                                                 }  
                                         }  
                                 }  
                         }  
                         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,  
                                                                 }  
                                                         );  
                                                 }  
                                         }  
                                 }  
                         }  
                 }  
         }  
   
 };  
15    
16  template '/units' => page {  template '/units' => page {
17          h1 { _("Units available in system") };          h1 { _("Units available in system") };
18    
19          my $units = Arh::Model::UnitCollection->new;          my $search = Arh::Model::UnitCollection->new;
20          $units->unlimit;          $search->unlimit;
21    
22            show( 'toggle_edit' ) if $search->count;
23    
24            set( search_collection => $search );
25            render_region(
26                    name => 'units',
27                    path => '/units/list',
28                    defaults => {
29                            page => 1,
30                    }
31            );
32    
         while ( my $u = $units->next ) {  
                 unit( $u );  
         }  
33  };  };
34    
35  sub unit {  template 'toggle_edit' => sub {
36          my $unit = shift || die "no unit?";          my $self = shift;
37          my $a = new_action( class => 'UpdateUnit', record => $unit );  
38            my $toggleedit = new_action(
39                    class => 'ToggleEdit',
40    #               moniker => 'toggle-edit',
41            );
42    
43            my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing");
44    
45            warn "## $label\n";
46    
47          form {          form {
48                  foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) {                  outs_raw( $toggleedit->button(
49                          my $can_write = $unit->current_user_can('write',$f);                          label => $label,
50                          #warn "write $f ",$can_write ? 'ok' : 'DENIED';                          submit => $toggleedit,
51                          if ( $f eq 'material' ) {                  ));
                                 set( UnitMaterialCollection => $unit->material );  
                                 show( '/unit/materials' );  
                         } else {  
                                 my %opt;  
                                 $opt{render_mode} = 'read' if ! $unit->current_user_can('write',$f);  
                                 render_param( $a => $f, %opt );  
                         }  
                 }  
52          }          }
 }  
53    
54  template '/unit/materials' => sub {  };
55          my $materials = get('UnitMaterialCollection');  
56          my $del_um = new_action( class => 'DeleteUnitMaterial', moniker => 'del_um' );  template 'raw_pic' => sub {
57          my $new_um = new_action( class => 'CreateUnitMaterial', moniker => 'new_um' );          my $filename = get('filename') or die "no filename?";
58          my $can_write;          my $image = Arh::Model::Picture->new;
59          while ( my $um = $materials->next ) {          $image->load_by_cols( filename => $filename );
60                  div { attr { class is 'form_field' }          if ( $image->id ) {
61                          span {                  Jifty->handler->apache->content_type('image/jpg');
62                                  span { attr { class is 'label' } _("Material") };                  Jifty->web->out($image->content);
63                                  span { $um->material->name };          } else {
64                                    die "can't find picture $filename";
                                 $can_write ||= $um->current_user_can('write');  
                                 if ( $can_write ) {  
                                         outs_raw($del_um->button(  
                                                 submit => $del_um,  
                                                 label => _('Delete'),  
                                                 arguments => {  
                                                         unit => $um->unit,  
                                                         material => $um->material  
                                                 },  
                                         ));  
                                 }  
                         }  
                 };  
   
                 if ( $can_write ) {  
                         render_param(  
                                 $new_um => 'material', label => _("Material"),  
                                 render_as => 'Arh::Web::Material',  
                                 # cludge to transfer arguments  
                                 hints => {  
                                         unit => $um->unit,  
                                 },  
                         );  
                 }  
65          }          }
66  };  };
67    

Legend:
Removed from v.13  
changed lines
  Added in v.55

  ViewVC Help
Powered by ViewVC 1.1.26