/[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 28 - (hide annotations)
Mon Dec 10 14:56:12 2007 UTC (16 years, 3 months ago) by dpavlin
File size: 3539 byte(s)
added UnitPicture model, first try at user interface for it
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     hyperlink(
69     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     as_button => 1,
79     );
80     };
81     img { attr { src => "/static/pics/" . $record->picture->filename } }
82     tt{ $record->picture->filename }
83     };
84    
85     };
86    
87     template 'new_picture' => sub {
88     my $self = shift;
89     return unless $self->current_user->editing;
90    
91     my ( $id, $unit ) = get(qw(id unit));
92     my $record_class = $self->record_class;
93     my $create = $record_class->as_create_action(
94     moniker => "create-" . Jifty->web->serial,
95     );
96     warn "## unit $unit";
97    
98     my $attach_to =
99     Jifty->web->current_region->parent ?
100     Jifty->web->current_region->parent->get_element( 'div.list' ) :
101     Jifty->web->current_region;
102    
103     warn "## attach_to = $attach_to";
104    
105     form {
106     render_param($create => 'picture');
107     outs_raw( $create->hidden( unit => $unit ) );
108     hyperlink(
109     label => _("Add picture"),
110     class => "float-crud-button button-add",
111     onclick => [
112     {
113     submit => $create,
114     },
115     { refresh_self => 1 },
116     {
117     element => $attach_to,
118     append => $self->fragment_for('view'),
119     args => {
120     object_type => $self->object_type,
121     id => { result_of => $create, name => 'id' },
122     unit => $unit,
123     },
124     },
125     ],
126     as_button => 1,
127     );
128     };
129     };
130    
131     template 'fragment' => sub {
132     my ( $self, $unit ) = @_;
133    
134     warn "## unit = ", dump( $unit );
135    
136     my $unitpictures = Arh::Model::UnitPictureCollection->new;
137     $unitpictures->limit( column => 'unit', value => $unit->id );
138     warn "## ", $unitpictures->count, " pictures for unit ",$unit->id;
139    
140     div {
141     { class is 'pictures-by-unit' };
142    
143     em { 'pictures for unit ', $unit->name };
144    
145     set( search_collection => $unitpictures );
146     render_region(
147     name => 'unit-pictures',
148     path => '/unitpictures/list',
149     defaults => {
150     page => 1,
151     unit => $unit->id,
152     }
153     );
154     }
155     };
156    
157     1;

  ViewVC Help
Powered by ViewVC 1.1.26