/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (show annotations)
Sun Apr 6 18:17:42 2008 UTC (15 years, 11 months ago) by dpavlin
File size: 3789 byte(s)
cleanup: remove UnitPicture and put unit_id into picture itself
1 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 { 'Picture' };
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 outs_raw( $delete->button(
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 ));
79 };
80 img { attr { src => "/raw_pic?image=" . $record->filename } }
81 tt{ $record->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 warn "## new_picture id: $id unit: $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 moniker => "create-" . Jifty->web->serial,
97 );
98
99 my $attach_to =
100 Jifty->web->current_region->parent ?
101 Jifty->web->current_region->parent->get_element( 'div.list' ) :
102 Jifty->web->current_region;
103
104 warn "## attach_to = $attach_to";
105
106 form {
107 render_action( $create => [ 'campaign', 'content', 'type' ] );
108 hyperlink(
109 label => _("Add picture"),
110 class => "float-crud-button button-add",
111 onclick => [
112 {
113 submit => $create,
114 args => {
115 picture => { result_of => $picture, name => 'id' },
116 unit => $unit,
117 }
118 },
119 { refresh_self => 1 },
120 {
121 element => $attach_to,
122 append => $self->fragment_for('view'),
123 args => {
124 object_type => $self->object_type,
125 id => { result_of => $create, name => 'id' },
126 unit => $unit,
127 },
128 },
129 ],
130 as_button => 1,
131 );
132 };
133 };
134
135 template 'fragment' => sub {
136 my ( $self, $unit ) = @_;
137
138 #warn "## unit = ", dump( $unit );
139
140 my $unitpictures = Arh::Model::PictureCollection->new;
141 $unitpictures->limit( column => 'unit', value => $unit->id );
142 warn "## ", $unitpictures->count, " pictures for unit ",$unit->id;
143
144 div {
145 { class is 'pictures-by-unit' };
146
147 if ( $unitpictures->count ) {
148 em { _('Pictures for unit'), ' ', $unit->name };
149
150 set( search_collection => $unitpictures );
151 render_region(
152 name => 'unit-pictures',
153 path => '/unitpictures/list',
154 defaults => {
155 page => 1,
156 unit => $unit->id,
157 }
158 );
159
160 } else {
161 em { _('No pictures for unit'), ' ', $unit->name };
162 }
163
164 }
165 };
166
167 1;

  ViewVC Help
Powered by ViewVC 1.1.26