/[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 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 56  template '/pictures' => page { Line 58  template '/pictures' => page {
58                                          row {                                          row {
59                                                  cell {                                                  cell {
60                                                          attr { class => 'picture' };                                                          attr { class => 'picture' };
61                                                          img { attr { src => "static/pics/$f" } }                                                          img { attr { src => "/static/pics/$f" } }
62                                                          div { tt{ $f } }                                                          div { tt{ $f } }
63                                                  }                                                  }
64                                                  cell {                                                  cell {
# Line 79  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            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                          my $can_write = $unit->current_user_can('write',$f);                          label => $label,
124                          #warn "write $f ",$can_write ? 'ok' : 'DENIED';                          submit => $toggleedit,
125                          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 );  
                         }  
                 }  
126          }          }
 }  
127    
128  template '/unit/materials' => sub {  };
         my $materials = get('UnitMaterialCollection');  
         my $del_um = new_action( class => 'DeleteUnitMaterial', moniker => 'del_um' );  
         my $new_um = new_action( class => 'CreateUnitMaterial', moniker => 'new_um' );  
         my $can_write;  
         while ( my $um = $materials->next ) {  
                 div { attr { class is 'form_field' }  
                         span {  
                                 span { attr { class is 'label' } _("Material") };  
                                 span { $um->material->name };  
                   
                                 $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  
                                                 },  
                                         ));  
                                 }  
                         }  
                 };  
129    
130                  if ( $can_write ) {  template 'raw_pic' => sub {
131                          render_param(          my $filename = get('image') or die "no image?";
132                                  $new_um => 'material', label => _("Material"),          my $image = Arh::Model::Picture->new;
133                                  render_as => 'Arh::Web::Material',          $image->load_by_cols( filename => $filename );
134                                  # cludge to transfer arguments          if ( $image->id ) {
135                                  hints => {                  Jifty->handler->apache->content_type('image/jpg');
136                                          unit => $um->unit,                  Jifty->web->out($image->content);
137                                  },          } else {
138                          );                  die "can't find picture $filename";
                 }  
139          }          }
140  };  };
141    

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

  ViewVC Help
Powered by ViewVC 1.1.26