line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::PopupTreeSelect::Dynamic; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
29625
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
72
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.2'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use base 'HTML::PopupTreeSelect'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1495
|
|
10
|
1
|
|
|
1
|
|
25267
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1633
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# template source files, included at the bottom |
13
|
|
|
|
|
|
|
our $TEMPLATE_SRC; |
14
|
|
|
|
|
|
|
our $NODE_TEMPLATE_SRC; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# override new() to setup defaults for dynamic_url and dynamic_params |
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
1
|
|
my ($pkg, %args) = @_; |
19
|
0
|
|
|
|
|
|
my $self = $pkg->SUPER::new(%args); |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if ($self->{dynamic_url}) { |
22
|
|
|
|
|
|
|
# quote literal URL |
23
|
0
|
|
|
|
|
|
$self->{dynamic_url} = qq{"$self->{dynamic_url}"}; |
24
|
|
|
|
|
|
|
} else { |
25
|
|
|
|
|
|
|
# setup default |
26
|
0
|
|
|
|
|
|
$self->{dynamic_url} = q{window.location}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
0
|
|
|
|
$self->{dynamic_params} ||= ""; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
$self->{include_prototype} = 1 unless defined $self->{include_prototype}; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# override output to drive the dynamic template |
37
|
|
|
|
|
|
|
sub output { |
38
|
0
|
|
|
0
|
0
|
|
my ($self, $template) = @_; |
39
|
0
|
|
0
|
|
|
|
$template ||= HTML::Template->new(scalarref => \$TEMPLATE_SRC, |
40
|
|
|
|
|
|
|
die_on_bad_params => 0, |
41
|
|
|
|
|
|
|
global_vars => 1, |
42
|
|
|
|
|
|
|
); |
43
|
0
|
0
|
|
|
|
|
if( $self->{include_prototype} ) { |
44
|
0
|
|
|
|
|
|
eval { require HTML::Prototype }; |
|
0
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
croak "requires HTML::Prototype unless 'include_prototype' option is fase" |
46
|
|
|
|
|
|
|
if( $@ ); |
47
|
0
|
|
|
|
|
|
my $prototype = HTML::Prototype->new(); |
48
|
0
|
|
|
|
|
|
my $js = $prototype->define_javascript_functions; |
49
|
0
|
|
|
|
|
|
$template->param(prototype_js => $js); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# setup template parameters |
53
|
0
|
|
|
|
|
|
my %param = map { ($_, $self->{$_}) } qw(name height width |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
indent_width onselect |
55
|
|
|
|
|
|
|
form_field form_field_form |
56
|
|
|
|
|
|
|
button_label |
57
|
|
|
|
|
|
|
button_image title |
58
|
|
|
|
|
|
|
include_css resizable |
59
|
|
|
|
|
|
|
image_path scrollbars |
60
|
|
|
|
|
|
|
hide_selects hide_textareas |
61
|
|
|
|
|
|
|
dynamic_url dynamic_params |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# get output for the widget |
65
|
0
|
|
|
|
|
|
$template->param(%param); |
66
|
0
|
|
|
|
|
|
return $template->output; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# handle |
70
|
|
|
|
|
|
|
sub handle_get_node { |
71
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
72
|
0
|
|
|
|
|
|
my $query = $args{query}; |
73
|
0
|
0
|
|
|
|
|
croak("Missing required parameter 'query'.") unless $query; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $id = $query->param('id'); |
76
|
0
|
|
|
|
|
|
my $data = $self->{data}; |
77
|
0
|
|
|
|
|
|
my $node = $data; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $template = HTML::Template->new(scalarref => \$NODE_TEMPLATE_SRC, |
80
|
|
|
|
|
|
|
global_vars => 1, |
81
|
|
|
|
|
|
|
die_on_bad_params => 0); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my @node_loop; |
84
|
0
|
0
|
|
|
|
|
if (not defined $id) { |
85
|
|
|
|
|
|
|
# return the root (handle multiple roots if an array ref) |
86
|
0
|
0
|
|
|
|
|
if( ref $data eq 'ARRAY' ) { |
|
|
0
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $count = 0; |
88
|
0
|
|
|
|
|
|
@node_loop = map { $self->_output_node($_, $count++) } (@$data); |
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} elsif( ref $data eq 'HASH' ) { |
90
|
0
|
|
|
|
|
|
@node_loop = ( $self->_output_node($data, "0") ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} else { |
93
|
|
|
|
|
|
|
# return the children of this node |
94
|
0
|
|
|
|
|
|
my $parent; |
95
|
0
|
0
|
|
|
|
|
if( ref $data eq 'ARRAY' ) { |
|
|
0
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$parent = $self->_find_node($data, $id); |
97
|
|
|
|
|
|
|
} elsif( ref $data eq 'HASH' ) { |
98
|
0
|
|
|
|
|
|
$parent = $self->_find_node($data->children, $id); |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
my $child_id = 0; |
101
|
0
|
|
|
|
|
|
foreach my $node (@{$parent->{children}}) { |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
push(@node_loop, $self->_output_node($node, "$id/$child_id")); |
103
|
0
|
|
|
|
|
|
$child_id++; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
$template->param(node_loop => \@node_loop); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# setup global template parameters |
109
|
0
|
|
|
|
|
|
my %param = map { ($_, $self->{$_}) } qw(name height width |
|
0
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
indent_width onselect |
111
|
|
|
|
|
|
|
form_field form_field_form |
112
|
|
|
|
|
|
|
button_label |
113
|
|
|
|
|
|
|
button_image title |
114
|
|
|
|
|
|
|
include_css resizable |
115
|
|
|
|
|
|
|
image_path scrollbars |
116
|
|
|
|
|
|
|
hide_selects hide_textareas |
117
|
|
|
|
|
|
|
dynamic_url dynamic_params |
118
|
|
|
|
|
|
|
); |
119
|
0
|
|
|
|
|
|
$template->param(\%param); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $template->output(); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _find_node { |
125
|
0
|
|
|
0
|
|
|
my ($self, $data, $id) = @_; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# if it's a single digit, then it's a leaf |
128
|
0
|
0
|
|
|
|
|
if( $id =~ /^\d+$/ ) { |
129
|
0
|
|
|
|
|
|
return $data->[$id]; |
130
|
|
|
|
|
|
|
} else { |
131
|
|
|
|
|
|
|
# recurse down a level |
132
|
0
|
|
|
|
|
|
my ($car, $cdr) = split('/', $id, 2); |
133
|
0
|
|
|
|
|
|
return $self->_find_node($data->[$car]->{children}, $cdr); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _output_node { |
138
|
0
|
|
|
0
|
|
|
my ($self, $node, $id) = @_; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# setup template data for a single node |
141
|
0
|
0
|
|
|
|
|
my %param = (label => $node->{label}, |
|
|
0
|
|
|
|
|
|
142
|
|
|
|
|
|
|
value => $node->{value}, |
143
|
|
|
|
|
|
|
id => $id, |
144
|
|
|
|
|
|
|
open => $node->{open} ? 1 : 0, |
145
|
|
|
|
|
|
|
inactive => $node->{inactive} ? 1 : 0); |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
0
|
|
|
|
if ($node->{children} and @{$node->{children}}) { |
|
0
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$param{has_children} = 1; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
return \%param; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$TEMPLATE_SRC = <
|
155
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
END |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
$NODE_TEMPLATE_SRC = <
|
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
ondblclick="_toggle_expand('')" onclick="_toggle_select('', '')"> |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
onclick="_toggle_select('', '')"> |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
END |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
1; |
527
|
|
|
|
|
|
|
__END__ |