| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Gantry::Plugins::CRUD; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
61509
|
use strict; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
157
|
|
|
4
|
4
|
|
|
4
|
|
23
|
use Carp; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
253
|
|
|
5
|
4
|
|
|
4
|
|
1372
|
use Data::FormValidator; |
|
|
4
|
|
|
|
|
39907
|
|
|
|
4
|
|
|
|
|
205
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
4
|
|
|
|
|
319
|
use Gantry::Utils::CRUDHelp qw( |
|
8
|
|
|
|
|
|
|
clean_dates clean_params form_profile write_file verify_permission |
|
9
|
4
|
|
|
4
|
|
569
|
); |
|
|
4
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
26
|
use base 'Exporter'; |
|
|
4
|
|
|
|
|
5
|
|
|
|
4
|
|
|
|
|
8263
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( select_multiple_closure write_file verify_permission ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
16
|
|
|
|
|
|
|
# Constructor |
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
3
|
|
|
3
|
1
|
9
|
my $class = shift; |
|
21
|
3
|
|
|
|
|
32
|
my $callbacks = { @_ }; |
|
22
|
|
|
|
|
|
|
|
|
23
|
3
|
50
|
|
|
|
23
|
unless ( defined $callbacks->{template} ) { |
|
24
|
0
|
|
|
|
|
0
|
$callbacks->{template} = 'form.tt'; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
else { |
|
27
|
3
|
|
|
|
|
10
|
$callbacks->{ignore_default_template} = 1; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
19
|
return bless $callbacks, $class; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
34
|
|
|
|
|
|
|
# Accessors, so we don't misspell hash keys |
|
35
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub add_action { |
|
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ( defined $self->{add_action} ) { |
|
41
|
0
|
|
|
|
|
|
return $self->{add_action}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
else { |
|
44
|
0
|
|
|
|
|
|
croak 'add_action not defined or misspelled'; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub edit_action { |
|
49
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ( defined $self->{edit_action} ) { |
|
52
|
0
|
|
|
|
|
|
return $self->{edit_action} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
else { |
|
55
|
0
|
|
|
|
|
|
croak 'edit_action not defined or misspelled'; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub delete_action { |
|
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( defined $self->{delete_action} ) { |
|
63
|
0
|
|
|
|
|
|
return $self->{delete_action} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
else { |
|
66
|
0
|
|
|
|
|
|
croak 'delete_action not defined or misspelled'; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub form { |
|
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ( defined $self->{form} ) { |
|
74
|
0
|
|
|
|
|
|
return $self->{form} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
else { |
|
77
|
0
|
|
|
|
|
|
croak 'form not defined or misspelled'; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub redirect { |
|
82
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
83
|
0
|
|
|
|
|
|
return $self->{redirect} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub template { |
|
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
88
|
0
|
|
|
|
|
|
return $self->{template} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub text_descr { |
|
92
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
93
|
0
|
|
|
|
|
|
return $self->{text_descr} |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub use_clean_dates { |
|
97
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
98
|
0
|
|
|
|
|
|
return $self->{use_clean_dates}; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub turn_off_clean_params { |
|
102
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
103
|
0
|
|
|
|
|
|
return $self->{turn_off_clean_params}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub validator { |
|
107
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
108
|
0
|
|
|
|
|
|
return $self->{validator} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
112
|
|
|
|
|
|
|
# Methods users call |
|
113
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#------------------------------------------------- |
|
116
|
|
|
|
|
|
|
# $self->add( $your_self, { put => 'your', data => 'here' } ) |
|
117
|
|
|
|
|
|
|
#------------------------------------------------- |
|
118
|
|
|
|
|
|
|
sub add { |
|
119
|
0
|
|
|
0
|
1
|
|
my ( $self, $your_self, $data ) = @_; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Use the specified default template in the config if no |
|
122
|
|
|
|
|
|
|
# template was specified to the crud module and there is a |
|
123
|
|
|
|
|
|
|
# default defined. |
|
124
|
0
|
0
|
0
|
|
|
|
if ( |
|
125
|
|
|
|
|
|
|
( ! $self->{ignore_default_template} ) and |
|
126
|
|
|
|
|
|
|
( $your_self->fish_config( 'default_form_template' ) ) |
|
127
|
|
|
|
|
|
|
) { |
|
128
|
0
|
|
|
|
|
|
$your_self->stash->view->template( |
|
129
|
|
|
|
|
|
|
$your_self->fish_config( 'default_form_template' ) |
|
130
|
|
|
|
|
|
|
); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
else { |
|
133
|
0
|
|
|
|
|
|
$your_self->stash->view->template( $self->template ); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
$your_self->stash->view->title( 'Add ' . $self->text_descr ) |
|
137
|
|
|
|
|
|
|
unless $your_self->stash->view->title; |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $params = $your_self->get_param_hash(); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Redirect if user pressed 'Cancel' |
|
142
|
0
|
0
|
|
|
|
|
if ( $params->{cancel} ) { |
|
143
|
0
|
|
|
|
|
|
my $redirect = $self->_find_redirect( |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
|
|
|
|
|
|
gantry_site => $your_self, |
|
146
|
|
|
|
|
|
|
data => $data, |
|
147
|
|
|
|
|
|
|
user_req => 'add', |
|
148
|
|
|
|
|
|
|
action => 'cancel', |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
); |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $your_self->relocate( $redirect ); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# get and hold the form description |
|
156
|
0
|
|
|
|
|
|
my $form = $self->form->( $your_self, $data ); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Check form data |
|
159
|
0
|
|
|
|
|
|
my $show_form = 0; |
|
160
|
0
|
|
|
|
|
|
my $results; |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if ( $your_self->is_post ) { |
|
163
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( keys %{ $params } == 0 ); |
|
|
0
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
if ( $self->validator ) { |
|
166
|
0
|
|
|
|
|
|
$results = $self->validator->( |
|
167
|
|
|
|
|
|
|
{ |
|
168
|
|
|
|
|
|
|
self => $your_self, |
|
169
|
|
|
|
|
|
|
params => $params, |
|
170
|
|
|
|
|
|
|
form => $form, |
|
171
|
|
|
|
|
|
|
profile => form_profile( $form->{fields} ), |
|
172
|
|
|
|
|
|
|
action => 'add', |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
else { |
|
177
|
0
|
|
|
|
|
|
$results = Data::FormValidator->check( |
|
178
|
|
|
|
|
|
|
$params, |
|
179
|
|
|
|
|
|
|
form_profile( $form->{fields} ), |
|
180
|
|
|
|
|
|
|
); |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( $results->has_invalid ); |
|
184
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( $results->has_missing ); |
|
185
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( $form->{ error_text } ); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
else { |
|
188
|
0
|
|
|
|
|
|
$show_form = 1; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
|
if ( $show_form ) { |
|
192
|
|
|
|
|
|
|
# order is important, first put in the form... |
|
193
|
0
|
|
|
|
|
|
$your_self->stash->view->form( $form ); |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# ... then add error results |
|
196
|
0
|
0
|
|
|
|
|
if ( $your_self->method eq 'POST' ) { |
|
197
|
0
|
|
|
|
|
|
$your_self->stash->view->form->results( $results ); |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
else { |
|
201
|
0
|
|
|
|
|
|
my $redirect; |
|
202
|
0
|
0
|
|
|
|
|
my $action = $params->{submit_add_another} |
|
203
|
|
|
|
|
|
|
? 'submit_add_another' |
|
204
|
|
|
|
|
|
|
: 'submit'; |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# remove submit button entry |
|
207
|
0
|
|
|
|
|
|
delete $params->{submit}; |
|
208
|
0
|
|
|
|
|
|
delete $params->{submit_add_another}; |
|
209
|
|
|
|
|
|
|
|
|
210
|
0
|
0
|
|
|
|
|
if ( $self->turn_off_clean_params ) { |
|
211
|
0
|
0
|
|
|
|
|
if ( $self->use_clean_dates ) { |
|
212
|
0
|
|
|
|
|
|
clean_dates( $params, $form->{ fields } ); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
else { |
|
216
|
0
|
|
|
|
|
|
clean_params( $params, $form->{ fields } ); |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
$self->add_action->( $your_self, $params, $data ); |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# Find redirect. |
|
222
|
0
|
|
|
|
|
|
$redirect = $self->_find_redirect( |
|
223
|
|
|
|
|
|
|
{ |
|
224
|
|
|
|
|
|
|
gantry_site => $your_self, |
|
225
|
|
|
|
|
|
|
data => $data, |
|
226
|
|
|
|
|
|
|
action => $action, |
|
227
|
|
|
|
|
|
|
user_req => 'add' |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
); |
|
230
|
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
return $your_self->relocate( $redirect ); |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
} # END: add |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
#------------------------------------------------- |
|
236
|
|
|
|
|
|
|
# $self->edit( $your_self, { put => 'your', data => 'here' } ); |
|
237
|
|
|
|
|
|
|
#------------------------------------------------- |
|
238
|
|
|
|
|
|
|
sub edit { |
|
239
|
0
|
|
|
0
|
1
|
|
my ( $self, $your_self, $data ) = @_; |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# Use the specified default template in the config if no |
|
242
|
|
|
|
|
|
|
# template was specified to the crud module and there is a |
|
243
|
|
|
|
|
|
|
# default defined. |
|
244
|
0
|
0
|
0
|
|
|
|
if ( |
|
245
|
|
|
|
|
|
|
( ! $self->{ignore_default_template} ) and |
|
246
|
|
|
|
|
|
|
( $your_self->fish_config( 'default_form_template' ) ) |
|
247
|
|
|
|
|
|
|
) { |
|
248
|
0
|
|
|
|
|
|
$your_self->stash->view->template( |
|
249
|
|
|
|
|
|
|
$your_self->fish_config( 'default_form_template' ) |
|
250
|
|
|
|
|
|
|
); |
|
251
|
|
|
|
|
|
|
} |
|
252
|
|
|
|
|
|
|
else { |
|
253
|
0
|
|
|
|
|
|
$your_self->stash->view->template( $self->template ); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
0
|
0
|
|
|
|
|
$your_self->stash->view->title( 'Edit ' . $self->text_descr() ) |
|
257
|
|
|
|
|
|
|
unless $your_self->stash->view->title; |
|
258
|
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
my %params = $your_self->get_param_hash(); |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
# Redirect if 'Cancel' |
|
262
|
0
|
0
|
|
|
|
|
if ( $params{cancel} ) { |
|
263
|
0
|
|
|
|
|
|
my $redirect = $self->_find_redirect( |
|
264
|
|
|
|
|
|
|
{ |
|
265
|
|
|
|
|
|
|
gantry_site => $your_self, |
|
266
|
|
|
|
|
|
|
data => $data, |
|
267
|
|
|
|
|
|
|
action => 'cancel', |
|
268
|
|
|
|
|
|
|
user_req => 'edit', |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
); |
|
271
|
0
|
|
|
|
|
|
return $your_self->relocate( $redirect ); |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# get and hold the form description |
|
275
|
0
|
|
|
|
|
|
my $form = $self->form->( $your_self, $data ); |
|
276
|
|
|
|
|
|
|
|
|
277
|
0
|
0
|
0
|
|
|
|
croak 'Your form callback gave me nothing' unless defined $form and $form; |
|
278
|
|
|
|
|
|
|
|
|
279
|
0
|
|
|
|
|
|
my $show_form = 0; |
|
280
|
0
|
|
|
|
|
|
my $results; |
|
281
|
|
|
|
|
|
|
|
|
282
|
0
|
0
|
|
|
|
|
if ( $your_self->is_post ) { |
|
283
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( keys %params == 0 ); |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# Check form data |
|
286
|
0
|
0
|
|
|
|
|
if ( $self->validator ) { |
|
287
|
|
|
|
|
|
|
$results = $self->validator->( |
|
288
|
|
|
|
|
|
|
{ |
|
289
|
|
|
|
|
|
|
self => $your_self, |
|
290
|
|
|
|
|
|
|
params => \%params, |
|
291
|
|
|
|
|
|
|
form => $form, |
|
292
|
0
|
|
|
|
|
|
profile => form_profile( $form->{ fields } ), |
|
293
|
|
|
|
|
|
|
action => 'edit', |
|
294
|
|
|
|
|
|
|
} |
|
295
|
|
|
|
|
|
|
); |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
else { |
|
298
|
|
|
|
|
|
|
$results = Data::FormValidator->check( |
|
299
|
|
|
|
|
|
|
\%params, |
|
300
|
0
|
|
|
|
|
|
form_profile( $form->{ fields } ), |
|
301
|
|
|
|
|
|
|
); |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
|
|
304
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( $results->has_invalid ); |
|
305
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( $results->has_missing ); |
|
306
|
0
|
0
|
|
|
|
|
$show_form = 1 if ( $form->{ error_text } ); |
|
307
|
|
|
|
|
|
|
} |
|
308
|
|
|
|
|
|
|
else { |
|
309
|
0
|
|
|
|
|
|
$show_form = 1; |
|
310
|
|
|
|
|
|
|
} |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
# Form has errors |
|
313
|
0
|
0
|
|
|
|
|
if ( $show_form ) { |
|
314
|
|
|
|
|
|
|
# order matters, get form data first... |
|
315
|
0
|
|
|
|
|
|
$your_self->stash->view->form( $form ); |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# ... then overlay with results |
|
318
|
0
|
0
|
|
|
|
|
if ( $your_self->method eq 'POST' ) { |
|
319
|
0
|
|
|
|
|
|
$your_self->stash->view->form->results( $results ); |
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
# Form looks good, make update |
|
324
|
|
|
|
|
|
|
else { |
|
325
|
0
|
|
|
|
|
|
my $redirect; |
|
326
|
0
|
0
|
|
|
|
|
my $action = $params{submit_add_another} |
|
327
|
|
|
|
|
|
|
? 'submit_add_another' |
|
328
|
|
|
|
|
|
|
: 'submit'; |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
# remove submit button entry |
|
331
|
0
|
|
|
|
|
|
delete $params{submit}; |
|
332
|
0
|
|
|
|
|
|
delete $params{submit_add_another}; |
|
333
|
|
|
|
|
|
|
|
|
334
|
0
|
0
|
|
|
|
|
if ( $self->turn_off_clean_params ) { |
|
335
|
0
|
0
|
|
|
|
|
if ( $self->use_clean_dates ) { |
|
336
|
0
|
|
|
|
|
|
clean_dates( \%params, $form->{ fields } ); |
|
337
|
|
|
|
|
|
|
} |
|
338
|
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
else { |
|
340
|
0
|
|
|
|
|
|
clean_params( \%params, $form->{ fields } ); |
|
341
|
|
|
|
|
|
|
} |
|
342
|
|
|
|
|
|
|
|
|
343
|
0
|
|
|
|
|
|
$self->edit_action->( $your_self, \%params, $data ); |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
# Find redirect. |
|
346
|
0
|
|
|
|
|
|
$redirect = $self->_find_redirect( |
|
347
|
|
|
|
|
|
|
{ |
|
348
|
|
|
|
|
|
|
gantry_site => $your_self, |
|
349
|
|
|
|
|
|
|
data => $data, |
|
350
|
|
|
|
|
|
|
action => $action, |
|
351
|
|
|
|
|
|
|
user_req => 'edit' |
|
352
|
|
|
|
|
|
|
} |
|
353
|
|
|
|
|
|
|
); |
|
354
|
|
|
|
|
|
|
|
|
355
|
0
|
|
|
|
|
|
return $your_self->relocate( $redirect ); |
|
356
|
|
|
|
|
|
|
} |
|
357
|
|
|
|
|
|
|
} # END: edit |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
#------------------------------------------------- |
|
360
|
|
|
|
|
|
|
# $self->delete( $your_self, $confirm, { other => 'data' } ) |
|
361
|
|
|
|
|
|
|
#------------------------------------------------- |
|
362
|
|
|
|
|
|
|
sub delete { |
|
363
|
0
|
|
|
0
|
1
|
|
my ( $self, $your_self, $yes, $data ) = @_; |
|
364
|
|
|
|
|
|
|
|
|
365
|
0
|
0
|
|
|
|
|
$your_self->stash->view->template( 'delete.tt' ) |
|
366
|
|
|
|
|
|
|
unless $your_self->stash->view->template(); |
|
367
|
0
|
0
|
|
|
|
|
$your_self->stash->view->title( 'Delete' ) |
|
368
|
|
|
|
|
|
|
unless $your_self->stash->view->title; |
|
369
|
|
|
|
|
|
|
|
|
370
|
0
|
0
|
|
|
|
|
if ( $your_self->params->{cancel} ) { |
|
371
|
0
|
|
|
|
|
|
my $redirect = $self->_find_redirect( |
|
372
|
|
|
|
|
|
|
{ |
|
373
|
|
|
|
|
|
|
gantry_site => $your_self, |
|
374
|
|
|
|
|
|
|
data => $data, |
|
375
|
|
|
|
|
|
|
action => 'cancel', |
|
376
|
|
|
|
|
|
|
user_req => 'delete' |
|
377
|
|
|
|
|
|
|
} |
|
378
|
|
|
|
|
|
|
); |
|
379
|
0
|
|
|
|
|
|
return $your_self->relocate( $redirect ); |
|
380
|
|
|
|
|
|
|
} |
|
381
|
|
|
|
|
|
|
|
|
382
|
0
|
0
|
0
|
|
|
|
if ( ( defined $yes ) and ( $yes eq 'yes' ) ) { |
|
383
|
|
|
|
|
|
|
|
|
384
|
0
|
|
|
|
|
|
$self->delete_action->( $your_self, $data ); |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
# Move along, it's already dead |
|
387
|
0
|
|
|
|
|
|
my $redirect = $self->_find_redirect( |
|
388
|
|
|
|
|
|
|
{ |
|
389
|
|
|
|
|
|
|
gantry_site => $your_self, |
|
390
|
|
|
|
|
|
|
data => $data, |
|
391
|
|
|
|
|
|
|
action => 'submit', |
|
392
|
|
|
|
|
|
|
user_req => 'delete' |
|
393
|
|
|
|
|
|
|
} |
|
394
|
|
|
|
|
|
|
); |
|
395
|
0
|
|
|
|
|
|
return $your_self->relocate( $redirect ); |
|
396
|
|
|
|
|
|
|
} |
|
397
|
|
|
|
|
|
|
else { |
|
398
|
0
|
|
|
|
|
|
$your_self->stash->view->form->message ( |
|
399
|
|
|
|
|
|
|
'Delete ' . $self->text_descr() . '?' |
|
400
|
|
|
|
|
|
|
); |
|
401
|
|
|
|
|
|
|
} |
|
402
|
|
|
|
|
|
|
} |
|
403
|
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
405
|
|
|
|
|
|
|
# Helpers |
|
406
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
407
|
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
sub _find_redirect { |
|
409
|
0
|
|
|
0
|
|
|
my ( $self, $args ) = @_; |
|
410
|
0
|
|
|
|
|
|
my $your_self = $args->{ gantry_site }; |
|
411
|
0
|
|
|
|
|
|
my $data = $args->{ data }; |
|
412
|
0
|
|
|
|
|
|
my $action = $args->{ action }; |
|
413
|
0
|
|
|
|
|
|
my $user_req = $args->{ user_req }; |
|
414
|
|
|
|
|
|
|
|
|
415
|
0
|
|
|
|
|
|
my $retval; |
|
416
|
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
|
my $redirect_sub = $self->redirect; |
|
418
|
|
|
|
|
|
|
|
|
419
|
0
|
0
|
|
|
|
|
if ( $redirect_sub ) { |
|
420
|
0
|
|
|
|
|
|
$retval = $redirect_sub->( $your_self, $data, $action, $user_req ); |
|
421
|
|
|
|
|
|
|
} |
|
422
|
|
|
|
|
|
|
else { |
|
423
|
0
|
|
|
|
|
|
$retval = $your_self->location(); |
|
424
|
|
|
|
|
|
|
} |
|
425
|
|
|
|
|
|
|
|
|
426
|
0
|
|
|
|
|
|
return $retval; |
|
427
|
|
|
|
|
|
|
} |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
430
|
|
|
|
|
|
|
# Helper functions offered for export |
|
431
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
sub select_multiple_closure { |
|
434
|
0
|
|
|
0
|
1
|
|
my $field_name = shift; |
|
435
|
0
|
|
|
|
|
|
my $db_selected = shift; |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
return sub { |
|
438
|
0
|
|
|
0
|
|
|
my $id = shift; |
|
439
|
0
|
|
|
|
|
|
my $params = shift; |
|
440
|
|
|
|
|
|
|
|
|
441
|
0
|
|
|
|
|
|
my @real_keys = grep ! /^\./, keys %{ $params }; |
|
|
0
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
|
|
443
|
0
|
0
|
|
|
|
|
if ( @real_keys ) { |
|
444
|
0
|
0
|
|
|
|
|
return unless $params->{ $field_name }; |
|
445
|
0
|
|
|
|
|
|
my @param_ids = split /\0/, $params->{ $field_name }; |
|
446
|
0
|
|
|
|
|
|
foreach my $param_id ( @param_ids ) { |
|
447
|
0
|
0
|
|
|
|
|
return 1 if ( $param_id == $id ); |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
} |
|
450
|
|
|
|
|
|
|
else { |
|
451
|
0
|
|
|
|
|
|
return $db_selected->{ $id }; |
|
452
|
|
|
|
|
|
|
} |
|
453
|
0
|
|
|
|
|
|
}; |
|
454
|
|
|
|
|
|
|
} |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
1; |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
__END__ |