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

  ViewVC Help
Powered by ViewVC 1.1.26