/[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 12 by dpavlin, Thu Nov 29 19:32:41 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');
15                  if ( $fc->count ) {  
16                          h1 { _("Pictures available in system") };  template '/units' => page {
17                  }          h1 { _("Units available in system") };
18                  table {  
19                          while ( my $f = $fc->next ) {          my $search = Arh::Model::UnitCollection->new;
20                                  $present->{ $f->filename }++;          $search->unlimit;
21                                  my $delete = new_action( class => 'DeletePicture' );  
22                                  my $update = new_action( class => 'UpdatePicture', record => $f );          show( 'toggle_edit' ) if $search->count;
23                                  row {  
24                                          cell {          set( search_collection => $search );
25                                                  attr { class => 'picture' };          render_region(
26                                                  img { attr { src => "static/pics/" . $f->filename } }                  name => 'units',
27                                                  div { tt{ $f->filename } }                  path => '/units/list',
28                                          }                  defaults => {
29                                          cell {                          page => 1,
                                                 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 => 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,  
                                                         }  
                                                 );  
                                         }  
                                 }  
                         }  
30                  }                  }
31          }          );
32    
33  };  };
34    
35  template '/units' => page {  template 'toggle_edit' => sub {
36          h1 { _("Units available in system") };          my $self = shift;
37    
38            my $toggleedit = new_action(
39                    class => 'ToggleEdit',
40    #               moniker => 'toggle-edit',
41            );
42    
43          my $units = Arh::Model::UnitCollection->new;          my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing");
         $units->unlimit;  
44    
45          while ( my $u = $units->next ) {          warn "## $label\n";
46                  unit( $u );  
47            form {
48                    outs_raw( $toggleedit->button(
49                            label => $label,
50                            submit => $toggleedit,
51                    ));
52          }          }
53    
54  };  };
55    
56  sub unit {  template 'raw_pic' => sub {
57          my $unit = shift || die "no unit?";          my $filename = get('filename') or die "no filename?";
58          my $a = new_action( class => 'UpdateUnit', record => $unit );          my $image = Arh::Model::Picture->new;
59          warn "## current_user = ",dump( current_user );          $image->load_by_cols( filename => $filename );
60          form {          if ( $image->id ) {
61                  foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) {                  Jifty->handler->apache->content_type('image/jpg');
62                          if ( $f eq 'material' ) {                  Jifty->web->out($image->content);
63                                  my $material = $unit->material;          } else {
64                                  while ( my $um = $material->next ) {                  die "can't find picture $filename";
                                         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 );  
                         }  
                 }  
65          }          }
66  }  };
67    
68  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26