/[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 29 - (show annotations)
Mon Dec 10 15:16:52 2007 UTC (12 years, 3 months ago) by dpavlin
File size: 3536 byte(s)
fix delete
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 { '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 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 => "/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 my $record_class = $self->record_class;
92 my $create = $record_class->as_create_action(
93 moniker => "create-" . Jifty->web->serial,
94 );
95 warn "## unit $unit";
96
97 my $attach_to =
98 Jifty->web->current_region->parent ?
99 Jifty->web->current_region->parent->get_element( 'div.list' ) :
100 Jifty->web->current_region;
101
102 warn "## attach_to = $attach_to";
103
104 form {
105 render_param($create => 'picture');
106 outs_raw( $create->hidden( unit => $unit ) );
107 hyperlink(
108 label => _("Add picture"),
109 class => "float-crud-button button-add",
110 onclick => [
111 {
112 submit => $create,
113 },
114 { refresh_self => 1 },
115 {
116 element => $attach_to,
117 append => $self->fragment_for('view'),
118 args => {
119 object_type => $self->object_type,
120 id => { result_of => $create, name => 'id' },
121 unit => $unit,
122 },
123 },
124 ],
125 as_button => 1,
126 );
127 };
128 };
129
130 template 'fragment' => sub {
131 my ( $self, $unit ) = @_;
132
133 warn "## unit = ", dump( $unit );
134
135 my $unitpictures = Arh::Model::UnitPictureCollection->new;
136 $unitpictures->limit( column => 'unit', value => $unit->id );
137 warn "## ", $unitpictures->count, " pictures for unit ",$unit->id;
138
139 div {
140 { class is 'pictures-by-unit' };
141
142 em { 'pictures for unit ', $unit->name };
143
144 set( search_collection => $unitpictures );
145 render_region(
146 name => 'unit-pictures',
147 path => '/unitpictures/list',
148 defaults => {
149 page => 1,
150 unit => $unit->id,
151 }
152 );
153 }
154 };
155
156 1;

  ViewVC Help
Powered by ViewVC 1.1.26