/[Arh]/lib/Arh/View/UnitPictures.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

Annotation of /lib/Arh/View/UnitPictures.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (hide annotations)
Sun Apr 6 14:42:08 2008 UTC (16 years ago) by dpavlin
File size: 3824 byte(s)
added action to upload pictures
1 dpavlin 28 package Arh::View::UnitPictures;
2    
3     use strict;
4     use warnings;
5    
6     use base 'Jifty::View::Declare::CRUD';
7     use Jifty::View::Declare -base;
8    
9     use Data::Dump qw/dump/;
10    
11     sub object_type { 'UnitPicture' };
12    
13     private template search_region => sub {};
14     private template 'no_items_found' => sub {};
15    
16     sub display_columns {
17     my $self = shift;
18     return ('picture');
19     }
20    
21     sub edit_columns {
22     my $self = shift;
23     return ('picture');
24     }
25    
26     template 'list' => sub {
27     my $self = shift;
28    
29     my ( $page, $unit ) = get(qw(page unit));
30     my $item_path = $self->fragment_for("view");
31     my $fragment_for_new_picture = $self->fragment_for('new_picture');
32     my $collection = $self->_current_collection();
33     # XXX show just pictures from current unit
34     $collection->limit( column => 'unit', value => $unit ) if $unit;
35     div {
36     { class is 'pictures' };
37    
38     show('./search_region');
39     show( './paging_top', $collection, $page );
40     show( './list_items', $collection, $item_path );
41     show( './paging_bottom', $collection, $page );
42    
43     render_region(
44     name => 'new_picture',
45     path => $fragment_for_new_picture,
46     defaults => {
47     object_type => $self->object_type,
48     unit => $unit,
49     },
50     );
51     }
52    
53     };
54    
55     template 'view' => sub :CRUDView {
56     my $self = shift;
57     my ( $id, $unit ) = get(qw(id unit));
58     my $record = $self->_get_record( $id );
59    
60     my $delete = $record->as_delete_action(
61     moniker => "delete-" . Jifty->web->serial,
62     );
63    
64     warn "## id: $id unit $unit";
65    
66     form {
67     if ( $record->current_user_can('delete') && $self->current_user->editing ) {
68 dpavlin 29 outs_raw( $delete->button(
69 dpavlin 28 label => _("Delete picture"),
70     class => "float-crud-button button-delete",
71     onclick => {
72     submit => $delete,
73     confirm => _('Really delete?'),
74     replace_with => '/__jifty/empty',
75     refresh_self => 1,
76     args => { id => $id },
77     },
78 dpavlin 29 ));
79 dpavlin 28 };
80     img { attr { src => "/static/pics/" . $record->picture->filename } }
81     tt{ $record->picture->filename }
82     };
83    
84     };
85    
86     template 'new_picture' => sub {
87     my $self = shift;
88     return unless $self->current_user->editing;
89    
90     my ( $id, $unit ) = get(qw(id unit));
91 dpavlin 44 warn "## unit $id $unit";
92    
93     # my $record_class = $self->record_class;
94     # warn "## new_picture record_class: $record_class\n";
95     # my $create = $record_class->as_create_action(
96    
97     my $create = new_action(
98     class => 'UploadPicture',
99 dpavlin 28 moniker => "create-" . Jifty->web->serial,
100     );
101    
102     my $attach_to =
103     Jifty->web->current_region->parent ?
104     Jifty->web->current_region->parent->get_element( 'div.list' ) :
105     Jifty->web->current_region;
106    
107     warn "## attach_to = $attach_to";
108    
109     form {
110 dpavlin 44 { class is 'create-picture' };
111     render_action( $create => [ 'campaign', 'content', 'type' ] );
112 dpavlin 28 outs_raw( $create->hidden( unit => $unit ) );
113     hyperlink(
114     label => _("Add picture"),
115     class => "float-crud-button button-add",
116     onclick => [
117     {
118     submit => $create,
119     },
120     { refresh_self => 1 },
121     {
122     element => $attach_to,
123     append => $self->fragment_for('view'),
124     args => {
125     object_type => $self->object_type,
126     id => { result_of => $create, name => 'id' },
127     unit => $unit,
128     },
129     },
130     ],
131     as_button => 1,
132     );
133     };
134     };
135    
136     template 'fragment' => sub {
137     my ( $self, $unit ) = @_;
138    
139 dpavlin 30 #warn "## unit = ", dump( $unit );
140 dpavlin 28
141     my $unitpictures = Arh::Model::UnitPictureCollection->new;
142     $unitpictures->limit( column => 'unit', value => $unit->id );
143     warn "## ", $unitpictures->count, " pictures for unit ",$unit->id;
144    
145     div {
146     { class is 'pictures-by-unit' };
147    
148 dpavlin 33 if ( $unitpictures->count ) {
149     em { _('Pictures for unit'), ' ', $unit->name };
150     } else {
151     em { _('No pictures for unit'), ' ', $unit->name };
152 dpavlin 36 }
153 dpavlin 33
154 dpavlin 36 set( search_collection => $unitpictures );
155     render_region(
156     name => 'unit-pictures',
157     path => '/unitpictures/list',
158     defaults => {
159     page => 1,
160     unit => $unit->id,
161     }
162     );
163    
164 dpavlin 28 }
165     };
166    
167     1;

  ViewVC Help
Powered by ViewVC 1.1.26