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

  ViewVC Help
Powered by ViewVC 1.1.26