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

Annotation of /lib/Arh/View/Units.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (hide annotations)
Tue Apr 8 23:22:22 2008 UTC (16 years ago) by dpavlin
File size: 4805 byte(s)
bunch of changes:
- added bulk create link (which still doesn't work all that well)
- 
1 dpavlin 15 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 dpavlin 58 use Data::Dump qw/dump/;
10    
11 dpavlin 15 sub object_type { 'Unit' };
12    
13 dpavlin 67 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 dpavlin 66
19 dpavlin 23 sub display_columns {
20     my $self = shift;
21 dpavlin 39 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 dpavlin 58 construction
42 dpavlin 39 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 dpavlin 63 material
60 dpavlin 39 / );
61 dpavlin 23 }
62    
63 dpavlin 15 #private template search_region => sub {};
64    
65 dpavlin 67 =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 dpavlin 66 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 dpavlin 67 }
125 dpavlin 66 }
126     };
127    
128    
129 dpavlin 15 template 'view' => sub :CRUDView {
130     my $self = shift;
131 dpavlin 23 my $id = get('id');
132     my $record = $self->_get_record( $id );
133 dpavlin 15
134     my $update = $record->as_update_action(
135     moniker => "update-" . Jifty->web->serial,
136     );
137    
138 dpavlin 23 my $delete = $record->as_delete_action(
139     moniker => "delete-" . Jifty->web->serial,
140     );
141     my $editing = $record->current_user_can('write');
142     warn "## current_user_can('write') = $editing\n";
143     $editing = 0 unless $self->current_user->editing;
144     warn "## editing ",$editing ? 'ok' : 'DENIED';
145 dpavlin 15
146 dpavlin 28 div { { class is 'unit' }
147 dpavlin 23
148 dpavlin 67 if ( $editing ) {
149 dpavlin 23 outs_raw($delete->button(
150 dpavlin 28 label => _('Delete unit'),
151     class => 'float-crud-button button-delete',
152 dpavlin 23 onclick => {
153     submit => $delete,
154     confirm => _('Really delete?'),
155     # region => Jifty->web->current_region,
156     replace_with => '/__jifty/empty',
157     refresh_self => 1,
158     args => { id => $id },
159     },
160     ));
161     };
162    
163     foreach my $f ( $self->display_columns ) {
164 dpavlin 15 if ( $f eq 'material' ) {
165     set( search_collection => $record->material );
166     render_region(
167     name => 'unit-materials',
168     path => '/materials/list',
169     defaults => {
170     page => 1,
171     unit => $record->id,
172     }
173     );
174     } else {
175     my %opt;
176 dpavlin 58 if ( ! $editing ) {
177     $opt{render_mode} = 'read';
178     # skip fields without values
179     $opt{render_as} = 'hidden' if ! defined( $update->record->$f );
180     }
181 dpavlin 15 render_param( $update => $f, %opt );
182     }
183     };
184 dpavlin 23 if ( $editing ) {
185 dpavlin 20 div {
186     { class is 'submit_button' };
187     hyperlink(
188     label => _('Update'),
189     onclick => {
190     submit => $update,
191     refresh_self => 1,
192     },
193 dpavlin 67 );
194     }
195 dpavlin 20 }
196 dpavlin 28
197     }; # div class unit
198    
199     show('/unitpictures/fragment', $record);
200    
201 dpavlin 15 hr {};
202     };
203    
204 dpavlin 23 template 'new_item' => sub {
205     my $self = shift;
206     return unless $self->current_user->editing;
207    
208 dpavlin 66 my ( $object_type, $id ) = ( $self->object_type, get('id') );
209     my $record_class = $self->record_class;
210     my $create = $record_class->as_create_action;
211 dpavlin 23
212     h1 { _("New unit") };
213    
214 dpavlin 67 div {
215 dpavlin 23
216     foreach my $f ( $self->display_columns ) {
217 dpavlin 39 # last if $f eq 'material' && ! $id;
218 dpavlin 63 render_param( $create => $f ) unless $f eq 'material';
219 dpavlin 42 #warn "## $f";
220 dpavlin 23 }
221    
222     div {
223     { class is 'submit_button' };
224     hyperlink(
225     label => _("Add"),
226     onclick => [
227     {
228     submit => $create,
229 dpavlin 39 # args => {
230     # },
231 dpavlin 23 },
232     { refresh_self => 1 },
233     {
234     element => Jifty->web->current_region->parent->get_element( 'div.list' ),
235     append => $self->fragment_for('view'),
236     args => {
237     object_type => $object_type,
238     id => { result_of => $create, name => 'id' },
239     unit => get('unit'),
240     },
241     },
242     ],
243     as_button => 1,
244     );
245 dpavlin 67 };
246 dpavlin 23
247     };
248     };
249    
250 dpavlin 15 1;

  ViewVC Help
Powered by ViewVC 1.1.26