| 1 | package HTML::PopupTreeSelect::Dynamic; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '1.2'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use base 'HTML::PopupTreeSelect'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # template source files, included at the bottom | ||||||||||||||||||||||||||||
| 13 | 1 | our $TEMPLATE_SRC; | |||||||||||||||||||||||||||
| 14 | 1 | our $NODE_TEMPLATE_SRC; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # override new() to setup defaults for dynamic_url and dynamic_params | ||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 0 | my ($pkg, %args) = @_; | |||||||||||||||||||||||||||
| 19 | 0 | my $self = $pkg->SUPER::new(%args); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if ($self->{dynamic_url}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | $self->{dynamic_params} ||= ""; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"dynamic_params"} ||= ""
MC/DC0%0/1
$self->{"dynamic_params"} ||= ""
$self->{"dynamic_params"}
Truth table0%0/2
A
A= $self->{"dynamic_params"}
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $self->{include_prototype} = 1 unless defined $self->{include_prototype}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # override output to drive the dynamic template | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub output { | ||||||||||||||||||||||||||
|
Subroutine
output: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $template) = @_; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | $template ||= HTML::Template->new(scalarref => \$TEMPLATE_SRC, | ||||||||||||||||||||||||||
|
Condition0%0/3
$template ||= "HTML::Template"->new("scalarref", \$HTML::PopupTreeSelect::Dynamic::TEMPLATE_SRC, "die_on_bad_params", 0, "global_vars", 1)
MC/DC0%0/2
$template ||= "HTML::Template"->new("scalarref", \$HTML::PopupTreeSelect::Dynamic::TEMPLATE_SRC, "die_on_bad_params", 0, "global_vars", 1)
$template
"HTML::Template"->new("scalarref", \$HTML::PopupTreeSelect::Dynamic::TEMPLATE_SRC, "die_on_bad_params", 0, "global_vars", 1)
Truth table0%0/3
A ||= B
A= $templateB= "HTML::Template"->new("scalarref", \$HTML::PopupTreeSelect::Dynamic::TEMPLATE_SRC, "die_on_bad_params", 0, "global_vars", 1)
| |||||||||||||||||||||||||||||
| 40 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||
| 41 | global_vars => 1, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if( $self->{include_prototype} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | eval { require HTML::Prototype }; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | croak "requires HTML::Prototype unless 'include_prototype' option is fase" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub handle_get_node { | ||||||||||||||||||||||||||
|
Subroutine
handle_get_node: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 72 | 0 | my $query = $args{query}; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | croak("Missing required parameter 'query'.") unless $query; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if (not defined $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | # return the root (handle multiple roots if an array ref) | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if( ref $data eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 87 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 88 | 0 | @node_loop = map { $self->_output_node($_, $count++) } (@$data); | |||||||||||||||||||||||||||
| 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 | ▶ | if( ref $data eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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}}) { | |||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _find_node { | ||||||||||||||||||||||||||
|
Subroutine
_find_node: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 125 | 0 | my ($self, $data, $id) = @_; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # if it's a single digit, then it's a leaf | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if( $id =~ /^\d+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _output_node { | ||||||||||||||||||||||||||
|
Subroutine
_output_node: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 138 | 0 | my ($self, $node, $id) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # setup template data for a single node | ||||||||||||||||||||||||||||
| 141 | my %param = (label => $node->{label}, | ||||||||||||||||||||||||||||
| 142 | value => $node->{value}, | ||||||||||||||||||||||||||||
| 143 | id => $id, | ||||||||||||||||||||||||||||
| 144 | open => $node->{open} ? 1 : 0, | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | inactive => $node->{inactive} ? 1 : 0); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ($node->{children} and @{$node->{children}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$node->{"children"} and @{$node->{"children"};}
MC/DC0%0/2
$node->{"children"} and @{$node->{"children"};}
$node->{"children"}
@{$node->{"children"};}
Truth table0%0/3
A and B
A= $node->{"children"}B= @{$node->{"children"};}
| |||||||||||||||||||||||||||||
| 148 | 0 | $param{has_children} = 1; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | return \%param; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1 | $TEMPLATE_SRC = <<END; | |||||||||||||||||||||||||||
| 155 | <tmpl_if include_css><style type="text/css"><!-- | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | /* style for the box around the widget */ | ||||||||||||||||||||||||||||
| 158 | .hpts-outer { | ||||||||||||||||||||||||||||
| 159 | visibility: hidden; | ||||||||||||||||||||||||||||
| 160 | position: absolute; | ||||||||||||||||||||||||||||
| 161 | top: 0px; | ||||||||||||||||||||||||||||
| 162 | left: 0px; | ||||||||||||||||||||||||||||
| 163 | border: 2px outset #333333; | ||||||||||||||||||||||||||||
| 164 | background-color: #ffffff; | ||||||||||||||||||||||||||||
| 165 | filter: progid:DXImageTransform.Microsoft.dropShadow( Color=bababa,offx=3,offy=3,positive=true); | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | /* style for the box that contains the tree */ | ||||||||||||||||||||||||||||
| 169 | .hpts-inner { | ||||||||||||||||||||||||||||
| 170 | <tmpl_if scrollbars> | ||||||||||||||||||||||||||||
| 171 | overflow: scroll; | ||||||||||||||||||||||||||||
| 172 | </tmpl_if> | ||||||||||||||||||||||||||||
| 173 | width: <tmpl_var width>px; | ||||||||||||||||||||||||||||
| 174 | <tmpl_if height> | ||||||||||||||||||||||||||||
| 175 | height: <tmpl_var height>px; | ||||||||||||||||||||||||||||
| 176 | </tmpl_if> | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | /* title bar style. The width here will define a minimum width for | ||||||||||||||||||||||||||||
| 180 | the widget. */ | ||||||||||||||||||||||||||||
| 181 | .hpts-title { | ||||||||||||||||||||||||||||
| 182 | padding: 2px; | ||||||||||||||||||||||||||||
| 183 | margin-bottom: 4px; | ||||||||||||||||||||||||||||
| 184 | font-size: large; | ||||||||||||||||||||||||||||
| 185 | color: #ffffff; | ||||||||||||||||||||||||||||
| 186 | background-color: #666666; | ||||||||||||||||||||||||||||
| 187 | width: <tmpl_var width>px; | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | /* style of a block of child nodes - indents them under their parent | ||||||||||||||||||||||||||||
| 191 | and starts them hidden */ | ||||||||||||||||||||||||||||
| 192 | .hpts-block { | ||||||||||||||||||||||||||||
| 193 | margin-left: 24px; | ||||||||||||||||||||||||||||
| 194 | display: none; | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | /* style for the button bar at the bottom of the widget */ | ||||||||||||||||||||||||||||
| 198 | .hpts-bbar { | ||||||||||||||||||||||||||||
| 199 | padding: 3px; | ||||||||||||||||||||||||||||
| 200 | text-align: right; | ||||||||||||||||||||||||||||
| 201 | margin-top: 10px; | ||||||||||||||||||||||||||||
| 202 | background-color: #666666; | ||||||||||||||||||||||||||||
| 203 | width: <tmpl_var width>px; | ||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | /* style for the buttons at the bottom of the widget */ | ||||||||||||||||||||||||||||
| 207 | .hpts-button { | ||||||||||||||||||||||||||||
| 208 | margin-left: 15px; | ||||||||||||||||||||||||||||
| 209 | background-color: #ffffff; | ||||||||||||||||||||||||||||
| 210 | color: #000000; | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | /* style for selected labels */ | ||||||||||||||||||||||||||||
| 214 | .hpts-label-selected { | ||||||||||||||||||||||||||||
| 215 | background: #98ccfe; | ||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | /* style for labels after being unselected */ | ||||||||||||||||||||||||||||
| 219 | .hpts-label-unselected { | ||||||||||||||||||||||||||||
| 220 | background: #ffffff; | ||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | /* style for bottom bar used for resizing */ | ||||||||||||||||||||||||||||
| 224 | .hpts-botbar { | ||||||||||||||||||||||||||||
| 225 | background-color: #666666; | ||||||||||||||||||||||||||||
| 226 | width: <tmpl_var width>px; | ||||||||||||||||||||||||||||
| 227 | font-size: 7px; | ||||||||||||||||||||||||||||
| 228 | padding: 3px; | ||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | --></style></tmpl_if> | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | <script type="text/javascript"> | ||||||||||||||||||||||||||||
| 234 | <!-- | ||||||||||||||||||||||||||||
| 235 | /* record location of mouse on each click */ | ||||||||||||||||||||||||||||
| 236 | var hpts_mouseX; | ||||||||||||||||||||||||||||
| 237 | var hpts_mouseY; | ||||||||||||||||||||||||||||
| 238 | var hpts_offsetX; | ||||||||||||||||||||||||||||
| 239 | var hpts_offsetY; | ||||||||||||||||||||||||||||
| 240 | var hpts_locked_titlebar; /* for moving */ | ||||||||||||||||||||||||||||
| 241 | var hpts_locked_botbar; /* for resizing */ | ||||||||||||||||||||||||||||
| 242 | var hpts_curr_width = <tmpl_if width><tmpl_var width><tmpl_else>225</tmpl_if>; | ||||||||||||||||||||||||||||
| 243 | var hpts_curr_height = <tmpl_if height><tmpl_var height><tmpl_else>200</tmpl_if>; | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | hpts_lock = function(evt) { | ||||||||||||||||||||||||||||
| 246 | evt = (evt) ? evt : event; | ||||||||||||||||||||||||||||
| 247 | hpts_set_locked(evt); | ||||||||||||||||||||||||||||
| 248 | hpts_update_mouse(evt); | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | if (hpts_locked_titlebar) { | ||||||||||||||||||||||||||||
| 251 | if (evt.pageX) { | ||||||||||||||||||||||||||||
| 252 | hpts_offsetX = evt.pageX - ((hpts_locked_titlebar.offsetLeft) ? | ||||||||||||||||||||||||||||
| 253 | hpts_locked_titlebar.offsetLeft : hpts_locked_titlebar.left); | ||||||||||||||||||||||||||||
| 254 | hpts_offsetY = evt.pageY - ((hpts_locked_titlebar.offsetTop) ? | ||||||||||||||||||||||||||||
| 255 | hpts_locked_titlebar.offsetTop : hpts_locked_titlebar.top); | ||||||||||||||||||||||||||||
| 256 | } else if (evt.offsetX || evt.offsetY) { | ||||||||||||||||||||||||||||
| 257 | hpts_offsetX = evt.offsetX - ((evt.offsetX < -2) ? | ||||||||||||||||||||||||||||
| 258 | 0 : document.body.scrollLeft); | ||||||||||||||||||||||||||||
| 259 | hpts_offsetY = evt.offsetY - ((evt.offsetY < -2) ? | ||||||||||||||||||||||||||||
| 260 | 0 : document.body.scrollTop); | ||||||||||||||||||||||||||||
| 261 | } else if (evt.clientX) { | ||||||||||||||||||||||||||||
| 262 | hpts_offsetX = evt.clientX - ((hpts_locked_titlebar.offsetLeft) ? | ||||||||||||||||||||||||||||
| 263 | hpts_locked_titlebar.offsetLeft : 0); | ||||||||||||||||||||||||||||
| 264 | hpts_offsetY = evt.clientY - ((hpts_locked_titlebar.offsetTop) ? | ||||||||||||||||||||||||||||
| 265 | hpts_locked_titlebar.offsetTop : 0); | ||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | return false; | ||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | if (hpts_locked_botbar) { | ||||||||||||||||||||||||||||
| 271 | if (evt.pageX) { | ||||||||||||||||||||||||||||
| 272 | hpts_offsetX = evt.pageX; | ||||||||||||||||||||||||||||
| 273 | hpts_offsetY = evt.pageY; | ||||||||||||||||||||||||||||
| 274 | } else if (evt.clientX) { | ||||||||||||||||||||||||||||
| 275 | hpts_offsetX = evt.clientX; | ||||||||||||||||||||||||||||
| 276 | hpts_offsetY = evt.clientY; | ||||||||||||||||||||||||||||
| 277 | } else if (evt.offsetX || evt.offsetY) { | ||||||||||||||||||||||||||||
| 278 | hpts_offsetX = evt.offsetX - ((evt.offsetX < -2) ? | ||||||||||||||||||||||||||||
| 279 | 0 : document.body.scrollLeft); | ||||||||||||||||||||||||||||
| 280 | hpts_offsetY = evt.offsetY - ((evt.offsetY < -2) ? | ||||||||||||||||||||||||||||
| 281 | 0 : document.body.scrollTop); | ||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | return false; | ||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | return true; | ||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | hpts_update_mouse = function(evt) { | ||||||||||||||||||||||||||||
| 290 | if (evt.pageX) { | ||||||||||||||||||||||||||||
| 291 | hpts_mouseX = evt.pageX; | ||||||||||||||||||||||||||||
| 292 | hpts_mouseY = evt.pageY; | ||||||||||||||||||||||||||||
| 293 | } else { | ||||||||||||||||||||||||||||
| 294 | hpts_mouseX = evt.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; | ||||||||||||||||||||||||||||
| 295 | hpts_mouseY = evt.clientY + document.documentElement.scrollTop + document.body.scrollTop; | ||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | hpts_set_locked = function(evt) { | ||||||||||||||||||||||||||||
| 301 | var target = (evt.target) ? evt.target : evt.srcElement; | ||||||||||||||||||||||||||||
| 302 | if (target && target.className == "hpts-title") { | ||||||||||||||||||||||||||||
| 303 | hpts_locked_titlebar = target.parentNode; | ||||||||||||||||||||||||||||
| 304 | return; | ||||||||||||||||||||||||||||
| 305 | } else if (target && target.className == "hpts-botbar") { | ||||||||||||||||||||||||||||
| 306 | hpts_locked_botbar = target.parentNode; | ||||||||||||||||||||||||||||
| 307 | return; | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | hpts_locked_titlebar = null; | ||||||||||||||||||||||||||||
| 310 | hpts_locked_botbar = null; | ||||||||||||||||||||||||||||
| 311 | return; | ||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | hpts_drag = function(evt) { | ||||||||||||||||||||||||||||
| 315 | evt = (evt) ? evt : event; | ||||||||||||||||||||||||||||
| 316 | hpts_update_mouse(evt); | ||||||||||||||||||||||||||||
| 317 | var titleobj = document.getElementById("<tmpl_var name>-title"); | ||||||||||||||||||||||||||||
| 318 | var innerobj = document.getElementById("<tmpl_var name>-inner"); | ||||||||||||||||||||||||||||
| 319 | var bbarobj = document.getElementById("<tmpl_var name>-bbar"); | ||||||||||||||||||||||||||||
| 320 | var botbarobj = document.getElementById("<tmpl_var name>-botbar"); | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | if (hpts_locked_titlebar) { | ||||||||||||||||||||||||||||
| 323 | hpts_locked_titlebar.style.left = (hpts_mouseX - hpts_offsetX) + "px"; | ||||||||||||||||||||||||||||
| 324 | hpts_locked_titlebar.style.top = (hpts_mouseY - hpts_offsetY) + "px"; | ||||||||||||||||||||||||||||
| 325 | evt.cancelBubble = true; | ||||||||||||||||||||||||||||
| 326 | return false; | ||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | if (hpts_locked_botbar) { | ||||||||||||||||||||||||||||
| 330 | titleobj.style.width = (hpts_curr_width + hpts_mouseX - hpts_offsetX) + "px"; | ||||||||||||||||||||||||||||
| 331 | innerobj.style.width = (hpts_curr_width + hpts_mouseX - hpts_offsetX) + "px"; | ||||||||||||||||||||||||||||
| 332 | bbarobj.style.width = (hpts_curr_width + hpts_mouseX - hpts_offsetX) + "px"; | ||||||||||||||||||||||||||||
| 333 | botbarobj.style.width = (hpts_curr_width + hpts_mouseX - hpts_offsetX) + "px"; | ||||||||||||||||||||||||||||
| 334 | innerobj.style.height = (hpts_curr_height + hpts_mouseY - hpts_offsetY) + "px"; | ||||||||||||||||||||||||||||
| 335 | evt.cancelBubble = true; | ||||||||||||||||||||||||||||
| 336 | return false; | ||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | hpts_release = function(evt) { | ||||||||||||||||||||||||||||
| 341 | hpts_locked_titlebar = null; | ||||||||||||||||||||||||||||
| 342 | if (hpts_locked_botbar){ | ||||||||||||||||||||||||||||
| 343 | var widthstr = document.getElementById("<tmpl_var name>-inner").style.width; | ||||||||||||||||||||||||||||
| 344 | var heightstr = document.getElementById("<tmpl_var name>-inner").style.height; | ||||||||||||||||||||||||||||
| 345 | hpts_curr_width = parseFloat(widthstr.substr(0,widthstr.indexOf("px"))); | ||||||||||||||||||||||||||||
| 346 | hpts_curr_height = parseFloat(heightstr.substr(0,heightstr.indexOf("px"))); | ||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | hpts_locked_botbar = null; | ||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | document.onmousedown = hpts_lock; | ||||||||||||||||||||||||||||
| 352 | document.onmousemove = hpts_drag; | ||||||||||||||||||||||||||||
| 353 | document.onmouseup = hpts_release; | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | var <tmpl_var name>_selected_id = -1; | ||||||||||||||||||||||||||||
| 356 | var <tmpl_var name>_selected_val; | ||||||||||||||||||||||||||||
| 357 | var <tmpl_var name>_selected_elem; | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | /* expand or collapse a sub-tree */ | ||||||||||||||||||||||||||||
| 360 | <tmpl_var name>_toggle_expand = function(id) { | ||||||||||||||||||||||||||||
| 361 | var obj = document.getElementById("<tmpl_var name>-desc-" + id); | ||||||||||||||||||||||||||||
| 362 | var plus = document.getElementById("<tmpl_var name>-plus-" + id); | ||||||||||||||||||||||||||||
| 363 | var node = document.getElementById("<tmpl_var name>-node-" + id); | ||||||||||||||||||||||||||||
| 364 | if (obj.style.display != 'block') { | ||||||||||||||||||||||||||||
| 365 | obj.style.display = 'block'; | ||||||||||||||||||||||||||||
| 366 | plus.src = "<tmpl_var image_path>minus.png"; | ||||||||||||||||||||||||||||
| 367 | node.src = "<tmpl_var image_path>open_node.png"; | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | new Ajax.Updater("<tmpl_var name>-desc-" + id, <tmpl_var dynamic_url>, { method: 'get', parameters: "<tmpl_if dynamic_params><tmpl_var dynamic_params>&</tmpl_if>id=" + id, evalScripts: true }); | ||||||||||||||||||||||||||||
| 370 | } else { | ||||||||||||||||||||||||||||
| 371 | obj.style.display = 'none'; | ||||||||||||||||||||||||||||
| 372 | obj.innerHTTML = ''; | ||||||||||||||||||||||||||||
| 373 | plus.src = "<tmpl_var image_path>plus.png"; | ||||||||||||||||||||||||||||
| 374 | node.src = "<tmpl_var image_path>closed_node.png"; | ||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | /* select or unselect a node */ | ||||||||||||||||||||||||||||
| 379 | <tmpl_var name>_toggle_select = function(id, val) { | ||||||||||||||||||||||||||||
| 380 | if (<tmpl_var name>_selected_id != -1) { | ||||||||||||||||||||||||||||
| 381 | /* turn off old selected value */ | ||||||||||||||||||||||||||||
| 382 | var old = document.getElementById("<tmpl_var name>-line-" + <tmpl_var name>_selected_id); | ||||||||||||||||||||||||||||
| 383 | old.className = "hpts-label-unselected"; | ||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | if (id == <tmpl_var name>_selected_id) { | ||||||||||||||||||||||||||||
| 387 | /* clicked twice, turn it off and go back to nothing selected */ | ||||||||||||||||||||||||||||
| 388 | <tmpl_var name>_selected_id = -1; | ||||||||||||||||||||||||||||
| 389 | } else { | ||||||||||||||||||||||||||||
| 390 | /* turn on selected item */ | ||||||||||||||||||||||||||||
| 391 | var new_obj = document.getElementById("<tmpl_var name>-line-" + id); | ||||||||||||||||||||||||||||
| 392 | new_obj.className = "hpts-label-selected"; | ||||||||||||||||||||||||||||
| 393 | <tmpl_var name>_selected_id = id; | ||||||||||||||||||||||||||||
| 394 | <tmpl_var name>_selected_val = val; | ||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | /* it's showtime! */ | ||||||||||||||||||||||||||||
| 399 | <tmpl_var name>_show = function() { | ||||||||||||||||||||||||||||
| 400 | document.getElementById("<tmpl_var name>-inner").innerHTML = ''; | ||||||||||||||||||||||||||||
| 401 | new Ajax.Updater('<tmpl_var name>-inner', <tmpl_var dynamic_url>, { method: 'get', parameters: "<tmpl_var dynamic_params>", evalScripts: true }); | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | var obj = document.getElementById("<tmpl_var name>-outer"); | ||||||||||||||||||||||||||||
| 404 | var x = Math.floor(hpts_mouseX - (hpts_curr_width/2)); | ||||||||||||||||||||||||||||
| 405 | x = (x > 2 ? x : 2); | ||||||||||||||||||||||||||||
| 406 | var y = Math.floor(hpts_mouseY - (hpts_curr_height/5 * 4)); | ||||||||||||||||||||||||||||
| 407 | y = (y > 2 ? y : 2); | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | obj.style.left = x + "px"; | ||||||||||||||||||||||||||||
| 410 | obj.style.top = y + "px"; | ||||||||||||||||||||||||||||
| 411 | obj.style.visibility = "visible"; | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | <tmpl_if hide_selects> | ||||||||||||||||||||||||||||
| 414 | for(var f = 0; f < document.forms.length; f++) { | ||||||||||||||||||||||||||||
| 415 | for(var x = 0; x < document.forms[f].elements.length; x++) { | ||||||||||||||||||||||||||||
| 416 | var e = document.forms[f].elements[x]; | ||||||||||||||||||||||||||||
| 417 | if (e.options) { | ||||||||||||||||||||||||||||
| 418 | e.style.visibility = "hidden"; | ||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | </tmpl_if> | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | <tmpl_if hide_textareas> | ||||||||||||||||||||||||||||
| 425 | for(var f = 0; f < document.forms.length; f++) { | ||||||||||||||||||||||||||||
| 426 | for(var x = 0; x < document.forms[f].elements.length; x++) { | ||||||||||||||||||||||||||||
| 427 | var e = document.forms[f].elements[x]; | ||||||||||||||||||||||||||||
| 428 | if (e.rows) { | ||||||||||||||||||||||||||||
| 429 | e.style.visibility = "hidden"; | ||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | </tmpl_if> | ||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | /* user clicks the ok button */ | ||||||||||||||||||||||||||||
| 437 | <tmpl_var name>_ok = function() { | ||||||||||||||||||||||||||||
| 438 | if (<tmpl_var name>_selected_id == -1) { | ||||||||||||||||||||||||||||
| 439 | alert("Please select an item or click Cancel to cancel selection."); | ||||||||||||||||||||||||||||
| 440 | return; | ||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | /* fill in a form field if they spec'd one */ | ||||||||||||||||||||||||||||
| 444 | <tmpl_if form_field><tmpl_if form_field_form>document.forms["<tmpl_var form_field_form>"]<tmpl_else>document.forms[0]</tmpl_if>.elements["<tmpl_var form_field>"].value = <tmpl_var name>_selected_val;</tmpl_if> | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | /* trigger onselect */ | ||||||||||||||||||||||||||||
| 447 | <tmpl_if onselect><tmpl_var onselect>(<tmpl_var name>_selected_val)</tmpl_if> | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | <tmpl_var name>_close(); | ||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | <tmpl_var name>_cancel = function() { | ||||||||||||||||||||||||||||
| 453 | <tmpl_var name>_close(); | ||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | <tmpl_var name>_close = function() { | ||||||||||||||||||||||||||||
| 457 | /* hide window */ | ||||||||||||||||||||||||||||
| 458 | var obj = document.getElementById("<tmpl_var name>-outer"); | ||||||||||||||||||||||||||||
| 459 | obj.style.visibility = "hidden"; | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | /* clear selection */ | ||||||||||||||||||||||||||||
| 462 | if (<tmpl_var name>_selected_id != -1) { | ||||||||||||||||||||||||||||
| 463 | <tmpl_var name>_toggle_select(<tmpl_var name>_selected_id); | ||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | <tmpl_if hide_selects> | ||||||||||||||||||||||||||||
| 467 | for(var f = 0; f < document.forms.length; f++) { | ||||||||||||||||||||||||||||
| 468 | for(var x = 0; x < document.forms[f].elements.length; x++) { | ||||||||||||||||||||||||||||
| 469 | var e = document.forms[f].elements[x]; | ||||||||||||||||||||||||||||
| 470 | if (e.options) { | ||||||||||||||||||||||||||||
| 471 | e.style.visibility = "visible"; | ||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | </tmpl_if> | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | <tmpl_if hide_textareas> | ||||||||||||||||||||||||||||
| 478 | for(var f = 0; f < document.forms.length; f++) { | ||||||||||||||||||||||||||||
| 479 | for(var x = 0; x < document.forms[f].elements.length; x++) { | ||||||||||||||||||||||||||||
| 480 | var e = document.forms[f].elements[x]; | ||||||||||||||||||||||||||||
| 481 | if (e.rows) { | ||||||||||||||||||||||||||||
| 482 | e.style.visibility = "visible"; | ||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | </tmpl_if> | ||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | //--> | ||||||||||||||||||||||||||||
| 489 | </script> | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | <tmpl_var prototype_js> | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | <div id="<tmpl_var name>-outer" class="hpts-outer"> | ||||||||||||||||||||||||||||
| 494 | <div class="hpts-title" id="<tmpl_var name>-title"><tmpl_var title></div> | ||||||||||||||||||||||||||||
| 495 | <div class="hpts-inner" id="<tmpl_var name>-inner"></div> | ||||||||||||||||||||||||||||
| 496 | <div class="hpts-bbar" id="<tmpl_var name>-bbar" style="white-space:nowrap"> | ||||||||||||||||||||||||||||
| 497 | <input class="hpts-button" type="button" value=" Ok " onclick="<tmpl_var name>_ok()"> | ||||||||||||||||||||||||||||
| 498 | <input class="hpts-button" type="button" value="Cancel" onclick="<tmpl_var name>_cancel()"> | ||||||||||||||||||||||||||||
| 499 | </div> | ||||||||||||||||||||||||||||
| 500 | <tmpl_if resizable> <div id="<tmpl_var name>-botbar" class="hpts-botbar"> </div></tmpl_if> | ||||||||||||||||||||||||||||
| 501 | </div> | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | <input class="hpts-button" type="button" value="<tmpl_var button_label>" onmouseup="<tmpl_var name>_show()"> | ||||||||||||||||||||||||||||
| 504 | END | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 1 | $NODE_TEMPLATE_SRC = <<END; | |||||||||||||||||||||||||||
| 507 | <tmpl_loop node_loop> | ||||||||||||||||||||||||||||
| 508 | <div style="white-space:nowrap"> | ||||||||||||||||||||||||||||
| 509 | <tmpl_if has_children> | ||||||||||||||||||||||||||||
| 510 | <img alt="" id="<tmpl_var name>-plus-<tmpl_var id>" width=16 height=16 src="<tmpl_var image_path>plus.png" onclick="<tmpl_var name>_toggle_expand('<tmpl_var id>')"><span id="<tmpl_var name>-line-<tmpl_var id>" <tmpl_unless inactive>ondblclick="<tmpl_var name>_toggle_expand('<tmpl_var id>')" onclick="<tmpl_var name>_toggle_select('<tmpl_var id>', '<tmpl_var escape=html value>')"</tmpl_unless>> | ||||||||||||||||||||||||||||
| 511 | <tmpl_else> | ||||||||||||||||||||||||||||
| 512 | <img alt="" width=16 height=16 src="<tmpl_var image_path>L.png"><span id="<tmpl_var name>-line-<tmpl_var id>" <tmpl_unless inactive>onclick="<tmpl_var name>_toggle_select('<tmpl_var id>', '<tmpl_var escape=html value>')"</tmpl_unless>> | ||||||||||||||||||||||||||||
| 513 | </tmpl_if> | ||||||||||||||||||||||||||||
| 514 | <img id="<tmpl_var name>-node-<tmpl_var id>" width=16 height=16 src="<tmpl_var image_path>closed_node.png" alt=""> | ||||||||||||||||||||||||||||
| 515 | <tmpl_unless inactive><a href="javascript:void(0);"></tmpl_unless><tmpl_var label><tmpl_unless inactive></a></tmpl_unless> | ||||||||||||||||||||||||||||
| 516 | </span> | ||||||||||||||||||||||||||||
| 517 | </div> | ||||||||||||||||||||||||||||
| 518 | <tmpl_if has_children> | ||||||||||||||||||||||||||||
| 519 | <div id="<tmpl_var name>-desc-<tmpl_var id>" class="hpts-block" style="white-space: nowrap; display: none"></div> | ||||||||||||||||||||||||||||
| 520 | </tmpl_if> | ||||||||||||||||||||||||||||
| 521 | <tmpl_if open><script language="javascript"><tmpl_var name>_toggle_expand('<tmpl_var id>')</script></tmpl_if> | ||||||||||||||||||||||||||||
| 522 | </tmpl_loop> | ||||||||||||||||||||||||||||
| 523 | END | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 1 | 1; | |||||||||||||||||||||||||||
| 527 | __END__ | ||||||||||||||||||||||||||||