line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::Plugins::AjaxFORM;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
791
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
169
|
|
5
|
1
|
|
|
1
|
|
1115
|
use Data::FormValidator;
|
|
1
|
|
|
|
|
34396
|
|
|
1
|
|
|
|
|
55
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
835
|
use Gantry::Utils::CRUDHelp qw( clean_dates clean_params form_profile );
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
87
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use base 'Exporter';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1085
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( select_multiple_closure );
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
14
|
|
|
|
|
|
|
# Constructor
|
15
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new {
|
18
|
0
|
|
|
0
|
1
|
|
my $class = shift;
|
19
|
0
|
|
|
|
|
|
my $callbacks = { @_ };
|
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
unless ( defined $callbacks->{template} ) {
|
22
|
0
|
|
|
|
|
|
$callbacks->{template} = 'form.tt';
|
23
|
|
|
|
|
|
|
}
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return bless $callbacks, $class;
|
26
|
|
|
|
|
|
|
}
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
29
|
|
|
|
|
|
|
# Accessors, so we don't misspell hash keys
|
30
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub cancel_action {
|
33
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if ( defined $self->{cancel_action} ) {
|
36
|
0
|
|
|
|
|
|
return $self->{cancel_action}
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
else {
|
39
|
0
|
|
|
|
|
|
croak 'cancel_action not defined or misspelled';
|
40
|
|
|
|
|
|
|
}
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub success_action {
|
44
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ( defined $self->{success_action} ) {
|
47
|
0
|
|
|
|
|
|
return $self->{success_action}
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
else {
|
50
|
0
|
|
|
|
|
|
croak 'success_action not defined or misspelled';
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub process_action {
|
55
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ( defined $self->{process_action} ) {
|
58
|
0
|
|
|
|
|
|
return $self->{process_action}
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
else {
|
61
|
0
|
|
|
|
|
|
croak 'process_action not defined or misspelled';
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub form {
|
66
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ( defined $self->{form} ) {
|
69
|
0
|
|
|
|
|
|
return $self->{form}
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
else {
|
72
|
0
|
|
|
|
|
|
croak 'form not defined or misspelled';
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub text_descr {
|
77
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
78
|
0
|
|
|
|
|
|
return $self->{text_descr}
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub user_data {
|
82
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
83
|
0
|
|
|
|
|
|
return $self->{user_data}
|
84
|
|
|
|
|
|
|
}
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub use_clean_dates {
|
87
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
88
|
0
|
|
|
|
|
|
return $self->{use_clean_dates};
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub turn_off_clean_params {
|
92
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
93
|
0
|
|
|
|
|
|
return $self->{turn_off_clean_params};
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
97
|
|
|
|
|
|
|
# Methods users call
|
98
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#-------------------------------------------------
|
101
|
|
|
|
|
|
|
# $self->process( $your_self )
|
102
|
|
|
|
|
|
|
#-------------------------------------------------
|
103
|
|
|
|
|
|
|
sub process {
|
104
|
0
|
|
|
0
|
1
|
|
my ( $self, $your_self ) = @_;
|
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $form;
|
107
|
0
|
|
|
|
|
|
my $show_form = 0;
|
108
|
0
|
|
|
|
|
|
my $params = $your_self->get_param_hash();
|
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if ($params->{cancel}) {
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Redirect if user pressed 'Cancel'
|
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return $self->cancel_action->($your_self, $params, 'cancel');
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} else {
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# get and hold the form desription
|
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$form = $self->form->($your_self, $self->user_data);
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Check form data
|
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $results = Data::FormValidator->check(
|
125
|
|
|
|
|
|
|
$params,
|
126
|
|
|
|
|
|
|
form_profile($form->{fields}),
|
127
|
|
|
|
|
|
|
);
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# check to see if we need to display the form
|
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
$show_form = 1 if (keys %{$params} == 0);
|
|
0
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
$show_form = 1 if ($results->has_invalid);
|
133
|
0
|
0
|
|
|
|
|
$show_form = 1 if ($results->has_missing);
|
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if ($show_form) {
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# order is important, first put in the form...
|
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$your_self->stash->view->form($form);
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# ...then add any error results
|
142
|
|
|
|
|
|
|
|
143
|
0
|
0
|
|
|
|
|
if ($your_self->method eq 'POST') {
|
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$your_self->stash->view->form->results($results);
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
}
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} else {
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# remove submit button entry
|
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
delete $params->{submit};
|
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
if ($self->turn_off_clean_params) {
|
156
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
if ($self->use_clean_dates) {
|
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
clean_dates($params, $form->{fields});
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
}
|
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
} else { clean_params($params, $form->{fields}); }
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# do something with the form data
|
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$self->process_action->($your_self, $params, $self->user_data);
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# move along, we're all done here
|
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return $self->success_action->($your_self, $params, 'submit');
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
}
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
}
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
} # END: process
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
180
|
|
|
|
|
|
|
# Helper functions offered for export
|
181
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub select_multiple_closure {
|
184
|
0
|
|
|
0
|
1
|
|
my $field_name = shift;
|
185
|
0
|
|
|
|
|
|
my $db_selected = shift;
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
return sub {
|
188
|
0
|
|
|
0
|
|
|
my $id = shift;
|
189
|
0
|
|
|
|
|
|
my $params = shift;
|
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my @real_keys = grep ! /^\./, keys %{ $params };
|
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
if ( @real_keys ) {
|
194
|
0
|
0
|
|
|
|
|
return unless $params->{ $field_name };
|
195
|
0
|
|
|
|
|
|
my @param_ids = split /\0/, $params->{ $field_name };
|
196
|
0
|
|
|
|
|
|
foreach my $param_id ( @param_ids ) {
|
197
|
0
|
0
|
|
|
|
|
return 1 if ( $param_id == $id );
|
198
|
|
|
|
|
|
|
}
|
199
|
|
|
|
|
|
|
}
|
200
|
|
|
|
|
|
|
else {
|
201
|
0
|
|
|
|
|
|
return $db_selected->{ $id };
|
202
|
|
|
|
|
|
|
}
|
203
|
0
|
|
|
|
|
|
};
|
204
|
|
|
|
|
|
|
}
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
1;
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
__END__
|