line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::Form::FileDelete; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
9269273
|
use Digest::SHA qw(sha1_hex); |
|
2
|
|
|
|
|
7445
|
|
|
2
|
|
|
|
|
294
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
452
|
use HTML::FormHandler::Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
7
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has '+name' => (default => 'form-file-delete'); |
10
|
|
|
|
|
|
|
has '+widget_wrapper' => ( default => 'Bootstrap' ); |
11
|
|
|
|
|
|
|
sub build_form_element_class { ['form-horizontal'] }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'file_field_list' => (is=>'ro',isa=>'ArrayRef',lazy_build=>1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _build_file_field_list { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $dir = $self->get_config_folder('dir'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my @fields = map { |
21
|
|
|
|
|
|
|
my $label = $_->basename; |
22
|
|
|
|
|
|
|
my $name = sha1_hex($label); |
23
|
|
|
|
|
|
|
( |
24
|
|
|
|
|
|
|
$name => { |
25
|
|
|
|
|
|
|
type => 'Checkbox', |
26
|
|
|
|
|
|
|
name => $name, |
27
|
|
|
|
|
|
|
label => $label, |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
) |
30
|
|
|
|
|
|
|
} sort $dir->children(no_hidden => 1); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return \@fields; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub field_list { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
return [ |
38
|
|
|
|
|
|
|
@{$self->file_field_list}, |
39
|
|
|
|
|
|
|
submit => { |
40
|
|
|
|
|
|
|
type => 'Submit', |
41
|
|
|
|
|
|
|
value => 'Delete selected', |
42
|
|
|
|
|
|
|
element_class => 'btn btn-primary', |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub submitted { |
48
|
|
|
|
|
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $redirect = $self->get_config_text('redirect'); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $dir = $self->get_config_folder('dir'); |
53
|
|
|
|
|
|
|
foreach my $file ($dir->children(no_hidden => 1)) { |
54
|
|
|
|
|
|
|
my $field = $self->field(sha1_hex($file->basename)); |
55
|
|
|
|
|
|
|
unlink $file |
56
|
|
|
|
|
|
|
if $field && $field->value; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->redirect($redirect); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |