/[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 49 by dpavlin, Sun Apr 6 18:10:29 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 {  template 'pictures' => page {
11          my $fc = Arh::Model::PictureCollection->new;          my $fc = Arh::Model::PictureCollection->new;
12          $fc->unlimit;          $fc->unlimit;
13          my $present;          my $present;
14          form {          form {
15                  if ( $fc->count ) {                  if ( $fc->count ) {
16                          h1 { _("Pictures available in system") };                          h1 { _("Pictures available in system") };
17                    } else {
18                            span { outs _("No pubicly available pictures at this time...") }
19                  }                  }
20                  table {                  table {
21                          while ( my $f = $fc->next ) {                          while ( my $f = $fc->next ) {
# Line 23  template '/pictures' => page { Line 25  template '/pictures' => page {
25                                  row {                                  row {
26                                          cell {                                          cell {
27                                                  attr { class => 'picture' };                                                  attr { class => 'picture' };
28                                                  img { attr { src => "static/pics/" . $f->filename } }                                                  img { attr { src => "/static/pics/" . $f->filename } }
29                                                  div { tt{ $f->filename } }                                                  div { tt{ $f->filename } }
30                                          }                                          }
31                                          cell {                                          cell {
# Line 34  template '/pictures' => page { Line 36  template '/pictures' => page {
36                                                          div {                                                          div {
37                                                                  $delete->button(                                                                  $delete->button(
38                                                                          submit => $delete,                                                                          submit => $delete,
39                                                                          label => _('Delete'),                                                                          label => _('Delete picture'),
40                                                                          arguments => {                                                                          arguments => {
41                                                                                  id => $f->id,                                                                                  id => $f->id,
42                                                                          }                                                                          }
# Line 44  template '/pictures' => page { Line 46  template '/pictures' => page {
46                                          }                                          }
47                                  }                                  }
48                          }                          }
49                          row {                          warn "current_user->id: ",current_user->id;
50                                  cell { attr { colspan => 2 } h1 { _('Pending pictures') } }                          if ( current_user->id ) {
                         };  
                         warn "## present = ",dump( $present );  
                         foreach my $f ( Arh::Model::Picture->all_filenames ) {  
                                 next if $present->{$f};  
                                 my $create = new_action( class => 'CreatePicture' );  
51                                  row {                                  row {
52                                          cell {                                          cell { attr { colspan => 2 } h1 { _('Pending pictures') } }
53                                                  attr { class => 'picture' };                                  };
54                                                  img { attr { src => "static/pics/$f" } }                                  warn "## present = ",dump( $present );
55                                                  div { tt{ $f } }                                  foreach my $f ( Arh::Model::Picture->all_filenames ) {
56                                          }                                          next if $present->{$f};
57                                          cell {                                          my $create = new_action( class => 'CreatePicture' );
58                                                  attr { class => 'picture-description' };                                          row {
59                                                  render_param( $create => 'campaign' );                                                  cell {
60                                                  render_param( $create => 'type' );                                                          attr { class => 'picture' };
61                                                  $create->button(                                                          img { attr { src => "/static/pics/$f" } }
62                                                          submit => $create,                                                          div { tt{ $f } }
63                                                          label => _('Add'),                                                  }
64                                                          arguments => {                                                  cell {
65                                                                  filename => $f,                                                          attr { class => 'picture-description' };
66                                                          }                                                          render_param( $create => 'campaign' );
67                                                  );                                                          render_param( $create => 'type' );
68                                                            $create->button(
69                                                                    submit => $create,
70                                                                    label => _('Add'),
71                                                                    arguments => {
72                                                                            filename => $f,
73                                                                    }
74                                                            );
75                                                    }
76                                          }                                          }
77                                  }                                  }
78                          }                          }
# Line 76  template '/pictures' => page { Line 81  template '/pictures' => page {
81    
82  };  };
83    
84    use Jifty::View::Declare::CRUD;
85    Jifty::View::Declare::CRUD->mount_view('materials');
86    Jifty::View::Declare::CRUD->mount_view('UnitPictures');
87    Jifty::View::Declare::CRUD->mount_view('units');
88    #Jifty::View::Declare::CRUD->mount_view('locations');
89    
90  template '/units' => page {  template '/units' => page {
91          h1 { _("Units available in system") };          h1 { _("Units available in system") };
92    
93          my $units = Arh::Model::UnitCollection->new;          my $search = Arh::Model::UnitCollection->new;
94          $units->unlimit;          $search->unlimit;
95    
96            show( 'toggle_edit' ) if $search->count;
97    
98            set( search_collection => $search );
99            render_region(
100                    name => 'units',
101                    path => '/units/list',
102                    defaults => {
103                            page => 1,
104                    }
105            );
106    
         while ( my $u = $units->next ) {  
                 unit( $u );  
         }  
107  };  };
108    
109  sub unit {  template 'toggle_edit' => sub {
110          my $unit = shift || die "no unit?";          my $self = shift;
111          my $a = new_action( class => 'UpdateUnit', record => $unit );  
112          warn "## current_user = ",dump( current_user );          my $toggleedit = new_action(
113                    class => 'ToggleEdit',
114    #               moniker => 'toggle-edit',
115            );
116    
117            my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing");
118    
119            warn "## $label\n";
120    
121          form {          form {
122                  foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) {                  outs_raw( $toggleedit->button(
123                          if ( $f eq 'material' ) {                          label => $label,
124                                  my $material = $unit->material;                          submit => $toggleedit,
125                                  while ( my $um = $material->next ) {                  ));
126                                          my $m = new_action( class => 'UpdateMaterial', record => $um->material );          }
127                                          render_param( $m => 'name', label => _("Material"), render_mode => 'read' );  
128                                  }  };
129                          } else {  
130                                  my %opt;  template 'raw_pic' => sub {
131                                  $opt{render_mode} = 'read'; # unless          my $filename = get('image') or die "no image?";
132                                  warn "write $f ",$unit->current_user_can('write',$f) ? 'ok' : 'DENIED';          my $image = Arh::Model::Picture->new;
133                                  render_param( $a => $f, %opt );          $image->load_by_cols( filename => $filename );
134                          }          if ( $image->id ) {
135                  }                  Jifty->handler->apache->content_type('image/jpg');
136                    Jifty->web->out($image->content);
137            } else {
138                    die "can't find picture $filename";
139          }          }
140  }  };
141    
142  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26