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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69 - (show annotations)
Tue Apr 8 23:38:42 2008 UTC (16 years ago) by dpavlin
File size: 4853 byte(s)
added prev/next page to top pager also
1 package Arh::View::Units;
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 { 'Unit' };
12
13 sub per_page {
14 my $per_page = get('per_page') || 5;
15 warn "## Units per_page = $per_page\n";
16 return $per_page;
17 };
18
19 sub display_columns {
20 my $self = shift;
21 return ( qw/
22 unit_id
23 name
24 subcategory
25 category
26 site
27 gps
28 placement
29 context
30 discovery
31 function
32 reusage
33 ownership
34 presevation_place
35 inventory_nr
36 dimensions
37 condition
38 toplogy
39 technique
40 description
41 construction
42 iconography
43 decoration
44 motifs
45 inscription
46 language
47 font
48 author
49 chronology
50 chronostyle
51 explored
52 conservations
53 restorations
54 legal
55 links
56 sources
57 bibliography
58 copyright
59 material
60 / );
61 }
62
63 #private template search_region => sub {};
64
65 =for later
66
67 template 'index.html' => page {
68 my $self = shift;
69 title is $self->object_type;
70 form {
71 render_region(
72 name => $self->object_type.'-list',
73 path => $self->fragment_base_path.'/list'
74 );
75 };
76 };
77
78 template 'list' => sub {
79 my $self = shift;
80
81 my ( $page ) = get('page');
82
83 my $item_path = get('item_path') || $self->fragment_for("view");
84 my $collection = $self->_current_collection();
85
86 if ( $self->per_page == 1 ) {
87 warn "## bulk import get to last page\n";
88 $page = $collection->pager->last_page;
89 }
90
91 div {
92 {class is 'crud-'.$self->object_type};
93
94 show('./search_region');
95 show( './paging_top', $collection, $page );
96 show( './paging_bottom', $collection, $page );
97 show( './list_items', $collection, $item_path );
98 show( './paging_bottom', $collection, $page );
99
100 show( './new_item_region');
101 }
102
103 };
104
105 =cut
106
107 private template 'paging_top' => sub {
108 my $self = shift;
109 my $collection = shift;
110 my $page = shift || 1;
111
112 if ( $collection->pager->last_page > 1 ) {
113 span {
114 { class is 'page-count' };
115 outs(
116 _( "Found %1 units, showing %2-%3 on page %4/%5",
117 $collection->pager->total_entries,
118 $collection->pager->first,
119 $collection->pager->last,
120 $page,
121 $collection->pager->last_page
122 )
123 );
124 }
125 }
126 show( './paging_bottom', $collection, $page );
127 };
128
129
130 template 'view' => sub :CRUDView {
131 my $self = shift;
132 my $id = get('id');
133 my $record = $self->_get_record( $id );
134
135 my $update = $record->as_update_action(
136 moniker => "update-" . Jifty->web->serial,
137 );
138
139 my $delete = $record->as_delete_action(
140 moniker => "delete-" . Jifty->web->serial,
141 );
142 my $editing = $record->current_user_can('write');
143 warn "## current_user_can('write') = $editing\n";
144 $editing = 0 unless $self->current_user->editing;
145 warn "## editing ",$editing ? 'ok' : 'DENIED';
146
147 div { { class is 'unit' }
148
149 if ( $editing ) {
150 outs_raw($delete->button(
151 label => _('Delete unit'),
152 class => 'float-crud-button button-delete',
153 onclick => {
154 submit => $delete,
155 confirm => _('Really delete?'),
156 # region => Jifty->web->current_region,
157 replace_with => '/__jifty/empty',
158 refresh_self => 1,
159 args => { id => $id },
160 },
161 ));
162 };
163
164 foreach my $f ( $self->display_columns ) {
165 if ( $f eq 'material' ) {
166 set( search_collection => $record->material );
167 render_region(
168 name => 'unit-materials',
169 path => '/materials/list',
170 defaults => {
171 page => 1,
172 unit => $record->id,
173 }
174 );
175 } else {
176 my %opt;
177 if ( ! $editing ) {
178 $opt{render_mode} = 'read';
179 # skip fields without values
180 $opt{render_as} = 'hidden' if ! defined( $update->record->$f );
181 }
182 render_param( $update => $f, %opt );
183 }
184 };
185 if ( $editing ) {
186 div {
187 { class is 'submit_button' };
188 hyperlink(
189 label => _('Update'),
190 onclick => {
191 submit => $update,
192 refresh_self => 1,
193 },
194 );
195 }
196 }
197
198 }; # div class unit
199
200 show('/unitpictures/fragment', $record);
201
202 hr {};
203 };
204
205 template 'new_item' => sub {
206 my $self = shift;
207 return unless $self->current_user->editing;
208
209 my ( $object_type, $id ) = ( $self->object_type, get('id') );
210 my $record_class = $self->record_class;
211 my $create = $record_class->as_create_action;
212
213 h1 { _("New unit") };
214
215 div {
216
217 foreach my $f ( $self->display_columns ) {
218 # last if $f eq 'material' && ! $id;
219 render_param( $create => $f ) unless $f eq 'material';
220 #warn "## $f";
221 }
222
223 div {
224 { class is 'submit_button' };
225 hyperlink(
226 label => _("Add"),
227 onclick => [
228 {
229 submit => $create,
230 # args => {
231 # },
232 },
233 { refresh_self => 1 },
234 {
235 element => Jifty->web->current_region->parent->get_element( 'div.list' ),
236 append => $self->fragment_for('view'),
237 args => {
238 object_type => $object_type,
239 id => { result_of => $create, name => 'id' },
240 unit => get('unit'),
241 },
242 },
243 ],
244 as_button => 1,
245 );
246 };
247
248 };
249 };
250
251 1;

  ViewVC Help
Powered by ViewVC 1.1.26