line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Lazy::Widget::Composite; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
104
|
use CGI::Lazy::Globals; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
117
|
|
7
|
1
|
|
|
1
|
|
5
|
use base qw(CGI::Lazy::Widget); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1957
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# for new composite types need the following: ajaxSelect and dbwrite
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
12
|
|
|
|
|
|
|
sub ajaxBlank { |
13
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $widgets = []; |
16
|
0
|
|
|
|
|
|
my $output = []; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
push @$widgets, $_; |
20
|
0
|
|
|
|
|
|
push @$widgets, $_->ajaxBlank; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return $self->ajaxReturn($widgets, $output); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
27
|
|
|
|
|
|
|
sub ajaxSelect { |
28
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my %args = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $type = $self->type; |
32
|
0
|
|
|
|
|
|
$type = ucfirst $type; |
33
|
0
|
|
|
|
|
|
my $method = 'ajaxSelect'.$type; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $self->$method(%args); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
sub ajaxSelectManual { |
40
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
my %args = shift; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
47
|
|
|
|
|
|
|
sub ajaxSelectParentChild { |
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my %args = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
0
|
|
|
|
my $incoming = $args{incoming} || from_json(($self->q->param('POSTDATA') || $self->q->param('keywords') || $self->q->param('XForms:Model'))); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $parent = $self->members->{$self->relationship->{parent}->{id}}; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my %parentKeys; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
foreach my $child (keys %{$self->relationship->{children}}){ |
|
0
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $handle; |
59
|
0
|
|
|
|
|
|
$parentKeys{$self->relationship->{children}->{$child}->{parentKey}} = {handle => \$handle}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my %parentParams = ( |
64
|
|
|
|
|
|
|
incoming => $incoming, |
65
|
|
|
|
|
|
|
div => 1, |
66
|
|
|
|
|
|
|
vars => {%parentKeys}, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
$parentParams{searchLike} = $self->relationship->{parent}->{searchLike} if $self->relationship->{parent}->{searchLike}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $parentOutput = $parent->select(%parentParams); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# $self->q->util->debug->edump(\%parentParams); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if ($parent->multi) { |
76
|
0
|
|
|
|
|
|
return $self->ajaxReturn($parent, $parentOutput); |
77
|
|
|
|
|
|
|
} else { |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $widgets = [$parent]; |
80
|
0
|
|
|
|
|
|
my $output = [$parentOutput]; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
foreach my $child (keys %{$self->relationship->{children}}) { |
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my %childParams = ($self->relationship->{children}->{$child}->{childKey} => ${$parentKeys{$self->relationship->{children}->{$child}->{parentKey}}->{handle}}); |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
push @$widgets, $self->members->{$child}; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if ($parent->empty) { |
88
|
0
|
|
|
|
|
|
push @$output, $self->members->{$child}->ajaxBlank(); |
89
|
|
|
|
|
|
|
} else { |
90
|
0
|
|
|
|
|
|
push @$output, $self->members->{$child}->select(incoming => {%childParams}, div => 1); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $self->ajaxReturn($widgets, $output); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
99
|
|
|
|
|
|
|
sub ajaxSelectSelectableDataset { |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
0
|
|
|
|
|
|
my %args = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
0
|
|
|
|
my $incoming = $args{incoming} || from_json(($self->q->param('POSTDATA') || $self->q->param('keywords') || $self->q->param('XForms:Model'))); |
104
|
0
|
|
|
|
|
|
my $parent = $self->members->{$self->relationship->{parent}->{id}}; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $widgets = [$parent]; |
107
|
0
|
|
|
|
|
|
my $output = [$parent->rawContents(incoming => $incoming, div => 1)]; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
foreach my $child (keys %{$self->relationship->{children}}) { |
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $params = {}; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
foreach (@{$self->relationship->{children}->{$child}}) { |
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $value = $incoming->{$_->{parentParam}}; |
114
|
0
|
|
|
|
|
|
my $field = $_->{childField}; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$params->{$field} = $value; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
push @$widgets, $self->members->{$child}; |
120
|
0
|
|
|
|
|
|
push @$output, $self->members->{$child}->select(incoming => $params, div => 1); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return $self->ajaxReturn($widgets, $output); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
127
|
|
|
|
|
|
|
sub contents { |
128
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
129
|
0
|
|
|
|
|
|
my %args = @_; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $standalone = $self->vars->{standalone}; |
132
|
0
|
|
|
|
|
|
my $formOpenTag = ''; |
133
|
0
|
|
|
|
|
|
my $formCloseTag = ''; |
134
|
0
|
|
|
|
|
|
my $widgetID = $self->vars->{id}; |
135
|
0
|
|
|
|
|
|
my $members = $self->memberarray; |
136
|
0
|
|
|
|
|
|
my $output; |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if ($standalone) { |
139
|
0
|
|
0
|
|
|
|
$formOpenTag = $self->vars->{formOpenTag} || $self->q->start_form({-method => 'post', -action => $self->q->url}); |
140
|
0
|
|
|
|
|
|
$formCloseTag = $self->q->end_form; |
141
|
|
|
|
|
|
|
} |
142
|
0
|
0
|
|
|
|
|
my $divopen = $args{nodiv} ? '' : " "; |
143
|
0
|
0
|
|
|
|
|
my $divclose = $args{nodiv} ? '' : ""; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
foreach my $member (@$members) { |
146
|
0
|
|
|
|
|
|
$output .= $member->display(%args); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return $divopen. |
150
|
|
|
|
|
|
|
$formOpenTag. |
151
|
|
|
|
|
|
|
$output. |
152
|
|
|
|
|
|
|
$formCloseTag. |
153
|
|
|
|
|
|
|
$divclose; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
157
|
|
|
|
|
|
|
sub dbwrite { |
158
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
159
|
0
|
|
|
|
|
|
my %args = @_; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my $type = $self->type; |
162
|
0
|
|
|
|
|
|
$type = ucfirst $type; |
163
|
0
|
|
|
|
|
|
my $method = 'dbwrite'.$type; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
return $self->$method(%args);; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
170
|
|
|
|
|
|
|
sub dbwriteManual { |
171
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
172
|
0
|
|
|
|
|
|
my %args = @_; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
178
|
|
|
|
|
|
|
sub dbwriteParentChild { |
179
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
180
|
0
|
|
|
|
|
|
my %args = @_; |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my $parent = $self->members->{$self->relationship->{parent}->{id}}; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my %parentKeys; |
185
|
|
|
|
|
|
|
my $parentHandle; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
foreach my $child (keys %{$self->relationship->{children}}){ |
|
0
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$parentKeys{$self->relationship->{children}->{$child}->{parentKey}} = {handle => $parent->recordset->primarykeyhandle}; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
$parent->dbwrite(insert => {%parentKeys}, update => {%parentKeys}); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# $self->q->util->debug->edump(\%parentKeys); |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
foreach my $child (keys %{$self->relationship->{children}}) { |
|
0
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my %childParams = ($self->relationship->{children}->{$child}->{childKey} => { |
197
|
0
|
|
|
|
|
|
value => ${$parentKeys{$self->relationship->{children}->{$child}->{parentKey}}->{handle}}, |
198
|
|
|
|
|
|
|
}, |
199
|
|
|
|
|
|
|
); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# $self->q->util->debug->edump($child, ${$parentKeys{$self->relationship->{children}->{$child}->{parentKey}}->{handle}}); |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
$self->members->{$child}->dbwrite( |
204
|
|
|
|
|
|
|
insert => {%childParams}, |
205
|
|
|
|
|
|
|
update => {%childParams}, |
206
|
|
|
|
|
|
|
); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
return; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
213
|
|
|
|
|
|
|
sub dbwriteSelectableDataset { |
214
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
215
|
0
|
|
|
|
|
|
my %args = @_; |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
my $parent = $self->members->{$self->relationship->{parent}->{id}}; |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my $incoming = {}; |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
foreach my $child (keys %{$self->relationship->{children}}) { |
|
0
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
foreach (@{$self->relationship->{children}->{$child}}) { |
|
0
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
my $param = $_->{parentParam}; |
225
|
0
|
|
|
|
|
|
my $value = $self->q->param($param); |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
$incoming->{$param} = $value; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
my $widgets = [$parent]; |
232
|
0
|
|
|
|
|
|
my $output = [$parent->rawContents(incoming => $incoming, div => 1)]; |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
foreach my $child (keys %{$self->relationship->{children}}) { |
|
0
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
my %childParams = (); |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
foreach (@{$self->relationship->{children}->{$child}}) { |
|
0
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
my $value = $incoming->{$_->{parentParam}}; |
239
|
0
|
|
|
|
|
|
my $field = $_->{childField}; |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$childParams{$field} = {value => $value}; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
$self->members->{$child}->dbwrite( |
245
|
|
|
|
|
|
|
insert => {%childParams}, |
246
|
|
|
|
|
|
|
update => {%childParams}, |
247
|
|
|
|
|
|
|
); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
return; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
254
|
|
|
|
|
|
|
sub display { |
255
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
256
|
0
|
|
|
|
|
|
my %args = @_; |
257
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
return $self->contents(%args); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
262
|
|
|
|
|
|
|
sub memberarray { |
263
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
return $self->vars->{members}; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
269
|
|
|
|
|
|
|
sub members { |
270
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
return $self->{_members}; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
276
|
|
|
|
|
|
|
sub new { |
277
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
278
|
0
|
|
|
|
|
|
my $q = shift; |
279
|
0
|
|
|
|
|
|
my $vars = shift; |
280
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
|
my $widgetID = $vars->{id}; |
282
|
0
|
|
|
|
|
|
my $members = {}; |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
my $parsedMembers = []; |
285
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
foreach my $member (@{$vars->{members}}) { |
|
0
|
|
|
|
|
|
|
287
|
0
|
0
|
|
|
|
|
if (ref $member =~ /^CGI::Lazy::Widget/) { |
288
|
0
|
|
|
|
|
|
push @$parsedMembers, $member; |
289
|
|
|
|
|
|
|
} else { |
290
|
0
|
|
|
|
|
|
my $class = $member->{class}; |
291
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
my $widget = $q->widget->$class($member); |
293
|
0
|
|
|
|
|
|
push @$parsedMembers, $widget; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
0
|
|
|
|
|
|
$vars->{members} = $parsedMembers; |
298
|
|
|
|
|
|
|
|
299
|
0
|
|
|
|
|
|
foreach (@{$vars->{members}}) { |
|
0
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
|
$members->{$_->widgetID} = $_; |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
0
|
|
0
|
|
|
|
return bless { |
304
|
|
|
|
|
|
|
_q => $q, |
305
|
|
|
|
|
|
|
_vars => $vars, |
306
|
|
|
|
|
|
|
_members => $members, |
307
|
|
|
|
|
|
|
_widgetID => $widgetID, |
308
|
|
|
|
|
|
|
_type => $vars->{type} || 'manual', |
309
|
|
|
|
|
|
|
_relationship => $vars->{relationship}, |
310
|
|
|
|
|
|
|
}, $class; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
314
|
|
|
|
|
|
|
sub recordset { |
315
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
316
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
|
return $self->members->{$self->relationship->{parent}->{id}}->recordset; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
321
|
|
|
|
|
|
|
sub relationship { |
322
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
323
|
|
|
|
|
|
|
|
324
|
0
|
|
|
|
|
|
return $self->{_relationship}; |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
329
|
|
|
|
|
|
|
sub type { |
330
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
331
|
|
|
|
|
|
|
|
332
|
0
|
|
|
|
|
|
return $self->{_type}; |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
1 |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
__END__ |