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

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

  ViewVC Help
Powered by ViewVC 1.1.26