line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::Form::MemberUpdate; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11739846
|
use meon::Web::Util; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use HTML::FormHandler::Moose; |
6
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
7
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has '+name' => (default => 'form-member-update'); |
10
|
|
|
|
|
|
|
has '+widget_wrapper' => ( default => 'Bootstrap' ); |
11
|
|
|
|
|
|
|
sub build_form_element_class { ['form-horizontal'] }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'configured_field_list' => (is=>'ro',isa=>'ArrayRef',lazy_build=>1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _build_configured_field_list { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $member = $self->c->member; |
19
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
20
|
|
|
|
|
|
|
my $form_config = $self->config; |
21
|
|
|
|
|
|
|
my @fields = map { |
22
|
|
|
|
|
|
|
my $name = $_->getAttribute('name'); |
23
|
|
|
|
|
|
|
my $type = $_->getAttribute('type'); |
24
|
|
|
|
|
|
|
my $label = $_->getAttribute('label'); |
25
|
|
|
|
|
|
|
my $multi = $_->getAttribute('multiple'); |
26
|
|
|
|
|
|
|
my @options; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ($type eq 'Select') { |
29
|
|
|
|
|
|
|
@options = $xpc->findnodes('w:option',$_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
( |
33
|
|
|
|
|
|
|
$name => { |
34
|
|
|
|
|
|
|
type => $type, |
35
|
|
|
|
|
|
|
value => '', |
36
|
|
|
|
|
|
|
required => !!$_->getAttribute('required'), |
37
|
|
|
|
|
|
|
default => $member->get_member_meta($name), |
38
|
|
|
|
|
|
|
(defined($label) ? (label => $label) : ()), |
39
|
|
|
|
|
|
|
(defined($multi) ? (multiple => $multi) : ()), |
40
|
|
|
|
|
|
|
(@options ? ( |
41
|
|
|
|
|
|
|
options => [ |
42
|
|
|
|
|
|
|
map {+{ |
43
|
|
|
|
|
|
|
label => $_->textContent, |
44
|
|
|
|
|
|
|
value => $_->getAttribute('value'), |
45
|
|
|
|
|
|
|
}} @options |
46
|
|
|
|
|
|
|
], |
47
|
|
|
|
|
|
|
) : ()), |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
) |
50
|
|
|
|
|
|
|
} $xpc->findnodes('w:fields/w:field',$form_config); |
51
|
|
|
|
|
|
|
die 'no fields provided' unless @fields; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return \@fields; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub field_list { |
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
return [ |
59
|
|
|
|
|
|
|
@{$self->configured_field_list}, |
60
|
|
|
|
|
|
|
submit => { |
61
|
|
|
|
|
|
|
type => 'Submit', |
62
|
|
|
|
|
|
|
value => 'Update', |
63
|
|
|
|
|
|
|
element_class => 'btn btn-primary', |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub submitted { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $redirect = $self->get_config_text('redirect'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my @field_names; |
74
|
|
|
|
|
|
|
my @field_list = @{$self->configured_field_list}; |
75
|
|
|
|
|
|
|
while (@field_list) { |
76
|
|
|
|
|
|
|
push(@field_names,shift(@field_list)); |
77
|
|
|
|
|
|
|
shift(@field_list); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $member = $self->c->member; |
81
|
|
|
|
|
|
|
foreach my $field_name (@field_names) { |
82
|
|
|
|
|
|
|
my $field_value = $self->field($field_name)->value; |
83
|
|
|
|
|
|
|
# empty array is like undef |
84
|
|
|
|
|
|
|
$field_value = undef |
85
|
|
|
|
|
|
|
if ((ref($field_value) eq 'ARRAY') && (@$field_value == 0)); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if (defined $field_value) { |
88
|
|
|
|
|
|
|
$member->set_member_meta($field_name, $field_value); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
|
|
|
|
|
|
$member->delete_member_meta($field_name); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
$member->store; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$self->redirect($redirect); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |