6 |
use base 'Jifty::View::Declare::CRUD'; |
use base 'Jifty::View::Declare::CRUD'; |
7 |
use Jifty::View::Declare -base; |
use Jifty::View::Declare -base; |
8 |
|
|
9 |
|
use Data::Dump qw/dump/; |
10 |
|
|
11 |
sub object_type { 'Unit' }; |
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 {}; |
#private template search_region => sub {}; |
58 |
|
|
59 |
template 'view' => sub :CRUDView { |
template 'view' => sub :CRUDView { |
60 |
my $self = shift; |
my $self = shift; |
61 |
my $record = $self->_get_record( get('id') ); |
my $id = get('id'); |
62 |
|
my $record = $self->_get_record( $id ); |
63 |
|
|
64 |
my $update = $record->as_update_action( |
my $update = $record->as_update_action( |
65 |
moniker => "update-" . Jifty->web->serial, |
moniker => "update-" . Jifty->web->serial, |
66 |
); |
); |
67 |
|
|
68 |
my $can_write = $record->current_user_can('write'); |
my $delete = $record->as_delete_action( |
69 |
#warn "write ",$can_write ? 'ok' : 'DENIED'; |
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 { |
form { |
97 |
foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { |
foreach my $f ( $self->display_columns ) { |
98 |
if ( $f eq 'material' ) { |
if ( $f eq 'material' ) { |
99 |
set( search_collection => $record->material ); |
set( search_collection => $record->material ); |
100 |
render_region( |
render_region( |
107 |
); |
); |
108 |
} else { |
} else { |
109 |
my %opt; |
my %opt; |
110 |
$opt{render_mode} = 'read' if ! $can_write; |
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 ); |
render_param( $update => $f, %opt ); |
116 |
} |
} |
117 |
}; |
}; |
118 |
if ( $can_write ) { |
if ( $editing ) { |
119 |
div { |
div { |
120 |
{ class is 'submit_button' }; |
{ class is 'submit_button' }; |
121 |
hyperlink( |
hyperlink( |
128 |
}; |
}; |
129 |
} |
} |
130 |
}; |
}; |
131 |
|
|
132 |
|
}; # div class unit |
133 |
|
|
134 |
|
show('/unitpictures/fragment', $record); |
135 |
|
|
136 |
hr {}; |
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; |
1; |