/[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 64 - (hide annotations)
Mon Apr 7 15:50:57 2008 UTC (16 years ago) by dpavlin
File size: 4062 byte(s)
fix upload in firefox
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 dpavlin 50 sub object_type { 'Picture' };
12 dpavlin 28
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 dpavlin 53
36     warn "## list page: $page unit: $unit fragment_for_new_picture: $fragment_for_new_picture item_path: $item_path";
37    
38 dpavlin 28 div {
39     { class is 'pictures' };
40    
41     show('./search_region');
42     show( './paging_top', $collection, $page );
43     show( './list_items', $collection, $item_path );
44     show( './paging_bottom', $collection, $page );
45    
46     render_region(
47     name => 'new_picture',
48     path => $fragment_for_new_picture,
49     defaults => {
50     object_type => $self->object_type,
51     unit => $unit,
52     },
53     );
54     }
55    
56     };
57    
58     template 'view' => sub :CRUDView {
59     my $self = shift;
60     my ( $id, $unit ) = get(qw(id unit));
61     my $record = $self->_get_record( $id );
62    
63     my $delete = $record->as_delete_action(
64     moniker => "delete-" . Jifty->web->serial,
65     );
66    
67 dpavlin 53 warn "## view id: $id unit $unit";
68 dpavlin 28
69 dpavlin 64 div {
70     { class is 'single-picture' };
71 dpavlin 53
72 dpavlin 28 if ( $record->current_user_can('delete') && $self->current_user->editing ) {
73 dpavlin 64 form {
74 dpavlin 29 outs_raw( $delete->button(
75 dpavlin 28 label => _("Delete picture"),
76     class => "float-crud-button button-delete",
77     onclick => {
78     submit => $delete,
79     confirm => _('Really delete?'),
80     replace_with => '/__jifty/empty',
81     refresh_self => 1,
82     args => { id => $id },
83     },
84 dpavlin 29 ));
85 dpavlin 64 }
86 dpavlin 28 };
87 dpavlin 64
88     img { attr { src => "/static/pics/thumb/" . $record->thumbnail } };
89     span { $record->type->name };
90     tt { $record->filename };
91    
92 dpavlin 28 };
93    
94     };
95    
96     template 'new_picture' => sub {
97     my $self = shift;
98     return unless $self->current_user->editing;
99    
100     my ( $id, $unit ) = get(qw(id unit));
101 dpavlin 50 warn "## new_picture id: $id unit: $unit";
102 dpavlin 44
103 dpavlin 50 my $record_class = $self->record_class;
104     warn "## new_picture record_class: $record_class\n";
105 dpavlin 53 # my $create = $record_class->as_create_action(
106     my $create = new_action(
107     class => 'UploadPicture',
108 dpavlin 28 moniker => "create-" . Jifty->web->serial,
109     );
110    
111     my $attach_to =
112 dpavlin 61 Jifty->web->current_region->parent ?
113     Jifty->web->current_region->parent->get_element( 'div.list' ) :
114     Jifty->web->current_region;
115 dpavlin 28
116     warn "## attach_to = $attach_to";
117    
118     form {
119 dpavlin 44 render_action( $create => [ 'campaign', 'content', 'type' ] );
120 dpavlin 53 outs_raw( $create->hidden( unit => $unit ) );
121 dpavlin 64 form_submit( label => _('Add picture') );
122     =for firefox-only
123 dpavlin 28 hyperlink(
124     label => _("Add picture"),
125     class => "float-crud-button button-add",
126     onclick => [
127     {
128     submit => $create,
129     },
130     { refresh_self => 1 },
131     {
132     element => $attach_to,
133     append => $self->fragment_for('view'),
134     args => {
135     object_type => $self->object_type,
136     id => { result_of => $create, name => 'id' },
137     unit => $unit,
138     },
139     },
140     ],
141     as_button => 1,
142     );
143 dpavlin 64 =cut
144 dpavlin 28 };
145     };
146    
147     template 'fragment' => sub {
148     my ( $self, $unit ) = @_;
149    
150 dpavlin 30 #warn "## unit = ", dump( $unit );
151 dpavlin 28
152 dpavlin 50 my $unitpictures = Arh::Model::PictureCollection->new;
153 dpavlin 28 $unitpictures->limit( column => 'unit', value => $unit->id );
154     warn "## ", $unitpictures->count, " pictures for unit ",$unit->id;
155    
156     div {
157     { class is 'pictures-by-unit' };
158    
159 dpavlin 33 if ( $unitpictures->count ) {
160     em { _('Pictures for unit'), ' ', $unit->name };
161 dpavlin 50
162 dpavlin 33 } else {
163     em { _('No pictures for unit'), ' ', $unit->name };
164 dpavlin 36 }
165 dpavlin 33
166 dpavlin 54 set( search_collection => $unitpictures );
167    
168     render_region(
169     name => 'unit-pictures',
170     path => '/unitpictures/list',
171     defaults => {
172     page => 1,
173     unit => $unit->id,
174     }
175     );
176    
177 dpavlin 28 }
178     };
179    
180     1;

  ViewVC Help
Powered by ViewVC 1.1.26