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 |
/ ); |
54 |
} |
55 |
|
56 |
#private template search_region => sub {}; |
57 |
|
58 |
template 'view' => sub :CRUDView { |
59 |
my $self = shift; |
60 |
my $id = get('id'); |
61 |
my $record = $self->_get_record( $id ); |
62 |
|
63 |
my $update = $record->as_update_action( |
64 |
moniker => "update-" . Jifty->web->serial, |
65 |
); |
66 |
|
67 |
my $delete = $record->as_delete_action( |
68 |
moniker => "delete-" . Jifty->web->serial, |
69 |
); |
70 |
my $editing = $record->current_user_can('write'); |
71 |
warn "## current_user_can('write') = $editing\n"; |
72 |
$editing = 0 unless $self->current_user->editing; |
73 |
warn "## editing ",$editing ? 'ok' : 'DENIED'; |
74 |
|
75 |
div { { class is 'unit' } |
76 |
|
77 |
if ( $editing ) { |
78 |
form { |
79 |
outs_raw($delete->button( |
80 |
label => _('Delete unit'), |
81 |
class => 'float-crud-button button-delete', |
82 |
onclick => { |
83 |
submit => $delete, |
84 |
confirm => _('Really delete?'), |
85 |
# region => Jifty->web->current_region, |
86 |
replace_with => '/__jifty/empty', |
87 |
refresh_self => 1, |
88 |
args => { id => $id }, |
89 |
}, |
90 |
)); |
91 |
}; |
92 |
}; |
93 |
|
94 |
|
95 |
form { |
96 |
foreach my $f ( $self->display_columns ) { |
97 |
if ( $f eq 'material' ) { |
98 |
set( search_collection => $record->material ); |
99 |
render_region( |
100 |
name => 'unit-materials', |
101 |
path => '/materials/list', |
102 |
defaults => { |
103 |
page => 1, |
104 |
unit => $record->id, |
105 |
} |
106 |
); |
107 |
} else { |
108 |
my %opt; |
109 |
if ( ! $editing ) { |
110 |
$opt{render_mode} = 'read'; |
111 |
# skip fields without values |
112 |
$opt{render_as} = 'hidden' if ! defined( $update->record->$f ); |
113 |
} |
114 |
render_param( $update => $f, %opt ); |
115 |
} |
116 |
}; |
117 |
if ( $editing ) { |
118 |
div { |
119 |
{ class is 'submit_button' }; |
120 |
hyperlink( |
121 |
label => _('Update'), |
122 |
onclick => { |
123 |
submit => $update, |
124 |
refresh_self => 1, |
125 |
}, |
126 |
) |
127 |
}; |
128 |
} |
129 |
}; |
130 |
|
131 |
}; # div class unit |
132 |
|
133 |
show('/unitpictures/fragment', $record); |
134 |
|
135 |
hr {}; |
136 |
}; |
137 |
|
138 |
template 'new_item' => sub { |
139 |
my $self = shift; |
140 |
return unless $self->current_user->editing; |
141 |
|
142 |
my ( $object_type, $id ) = ( $self->object_type, get('id') ); |
143 |
my $record_class = $self->record_class; |
144 |
my $create = $record_class->as_create_action; |
145 |
|
146 |
h1 { _("New unit") }; |
147 |
|
148 |
form { |
149 |
|
150 |
foreach my $f ( $self->display_columns ) { |
151 |
# last if $f eq 'material' && ! $id; |
152 |
render_param( $create => $f ); # unless $f eq 'material'; |
153 |
#warn "## $f"; |
154 |
} |
155 |
|
156 |
div { |
157 |
{ class is 'submit_button' }; |
158 |
hyperlink( |
159 |
label => _("Add"), |
160 |
onclick => [ |
161 |
{ |
162 |
submit => $create, |
163 |
# args => { |
164 |
# }, |
165 |
}, |
166 |
{ refresh_self => 1 }, |
167 |
{ |
168 |
element => Jifty->web->current_region->parent->get_element( 'div.list' ), |
169 |
append => $self->fragment_for('view'), |
170 |
args => { |
171 |
object_type => $object_type, |
172 |
id => { result_of => $create, name => 'id' }, |
173 |
unit => get('unit'), |
174 |
}, |
175 |
}, |
176 |
], |
177 |
as_button => 1, |
178 |
); |
179 |
} |
180 |
|
181 |
}; |
182 |
}; |
183 |
|
184 |
1; |