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 |
23 |
sub display_columns { |
14 |
|
|
my $self = shift; |
15 |
dpavlin |
39 |
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 |
dpavlin |
58 |
construction |
36 |
dpavlin |
39 |
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 |
dpavlin |
63 |
material |
54 |
dpavlin |
39 |
/ ); |
55 |
dpavlin |
23 |
} |
56 |
|
|
|
57 |
dpavlin |
15 |
#private template search_region => sub {}; |
58 |
|
|
|
59 |
|
|
template 'view' => sub :CRUDView { |
60 |
|
|
my $self = shift; |
61 |
dpavlin |
23 |
my $id = get('id'); |
62 |
|
|
my $record = $self->_get_record( $id ); |
63 |
dpavlin |
15 |
|
64 |
|
|
my $update = $record->as_update_action( |
65 |
|
|
moniker => "update-" . Jifty->web->serial, |
66 |
|
|
); |
67 |
|
|
|
68 |
dpavlin |
23 |
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 |
dpavlin |
15 |
|
76 |
dpavlin |
28 |
div { { class is 'unit' } |
77 |
dpavlin |
23 |
|
78 |
|
|
if ( $editing ) { |
79 |
|
|
form { |
80 |
|
|
outs_raw($delete->button( |
81 |
dpavlin |
28 |
label => _('Delete unit'), |
82 |
|
|
class => 'float-crud-button button-delete', |
83 |
dpavlin |
23 |
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 |
dpavlin |
28 |
|
96 |
dpavlin |
15 |
form { |
97 |
dpavlin |
23 |
foreach my $f ( $self->display_columns ) { |
98 |
dpavlin |
15 |
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 |
dpavlin |
58 |
if ( ! $editing ) { |
111 |
|
|
$opt{render_mode} = 'read'; |
112 |
|
|
# skip fields without values |
113 |
|
|
$opt{render_as} = 'hidden' if ! defined( $update->record->$f ); |
114 |
|
|
} |
115 |
dpavlin |
15 |
render_param( $update => $f, %opt ); |
116 |
|
|
} |
117 |
|
|
}; |
118 |
dpavlin |
23 |
if ( $editing ) { |
119 |
dpavlin |
20 |
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 |
dpavlin |
15 |
}; |
131 |
dpavlin |
28 |
|
132 |
|
|
}; # div class unit |
133 |
|
|
|
134 |
|
|
show('/unitpictures/fragment', $record); |
135 |
|
|
|
136 |
dpavlin |
15 |
hr {}; |
137 |
|
|
}; |
138 |
|
|
|
139 |
dpavlin |
23 |
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 |
dpavlin |
39 |
# last if $f eq 'material' && ! $id; |
153 |
dpavlin |
63 |
render_param( $create => $f ) unless $f eq 'material'; |
154 |
dpavlin |
42 |
#warn "## $f"; |
155 |
dpavlin |
23 |
} |
156 |
|
|
|
157 |
|
|
div { |
158 |
|
|
{ class is 'submit_button' }; |
159 |
|
|
hyperlink( |
160 |
|
|
label => _("Add"), |
161 |
|
|
onclick => [ |
162 |
|
|
{ |
163 |
|
|
submit => $create, |
164 |
dpavlin |
39 |
# args => { |
165 |
|
|
# }, |
166 |
dpavlin |
23 |
}, |
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 |
dpavlin |
15 |
1; |