128 |
my $tree = new WebPAC::Tree( |
my $tree = new WebPAC::Tree( |
129 |
tree => \@tree, |
tree => \@tree, |
130 |
log => 'log4perl.conf', |
log => 'log4perl.conf', |
131 |
|
detail_url => sub { |
132 |
|
my $mfn = shift; |
133 |
|
my $path = "thes/${mfn}.html"; |
134 |
|
return $path if (-e "./out/$path"); |
135 |
|
}, |
136 |
|
iframe_base => '../', |
137 |
); |
); |
138 |
|
|
139 |
C<tree> is tree array with levels of tree described above. |
C<tree> is tree array with levels of tree described above. |
141 |
C<log> is optional parametar which specify filename of L<Log::Log4Perl> |
C<log> is optional parametar which specify filename of L<Log::Log4Perl> |
142 |
config file. Default is C<log.conf>. |
config file. Default is C<log.conf>. |
143 |
|
|
144 |
|
C<detail_url> code ref to check if detail html exists (and return URL if |
145 |
|
it does). |
146 |
|
|
147 |
|
C<iframe_base> is relative path from C<dir> defiend in C<output> to root |
148 |
|
(which is inserted in all html). |
149 |
|
|
150 |
=cut |
=cut |
151 |
|
|
152 |
sub new { |
sub new { |
184 |
template_dir => './output_template/', |
template_dir => './output_template/', |
185 |
template_tree => 'tree.tt', |
template_tree => 'tree.tt', |
186 |
template_node => 'node.tt', |
template_node => 'node.tt', |
187 |
|
nodes => 'nodes', |
188 |
js => 'tree-ids.js', |
js => 'tree-ids.js', |
189 |
); |
); |
190 |
|
|
200 |
C<template_node> is (optional) name of template for node (if C<iframe> |
C<template_node> is (optional) name of template for node (if C<iframe> |
201 |
options is used within tree definition). |
options is used within tree definition). |
202 |
|
|
203 |
|
C<nodes> is directory in C<dir> in which html for iframes will be located. |
204 |
|
See also C<iframe_base> for relative dir out of this directory. |
205 |
|
|
206 |
C<js> is name of JavaScript file with shown and hidden ids. |
C<js> is name of JavaScript file with shown and hidden ids. |
207 |
|
|
208 |
=cut |
=cut |
279 |
sub unroll { |
sub unroll { |
280 |
my $self = shift; |
my $self = shift; |
281 |
|
|
282 |
my ($level,$data_arr) = @_; |
my ($level,$data_arr, $base_path) = @_; |
283 |
|
|
284 |
|
$base_path ||= ''; |
285 |
|
|
286 |
my $log = $self->_get_logger(); |
my $log = $self->_get_logger(); |
287 |
|
|
336 |
|
|
337 |
($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>}) if ($have_children); |
($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>}) if ($have_children); |
338 |
|
|
339 |
my $mfn_link = "thes/$mfn.html"; |
my $mfn_link; |
340 |
if (-e "out/$mfn_link") { |
$mfn_link = $self->{'detail_url'}->($mfn) if ($self->{'detail_url'}); |
341 |
$term =~ s# *\* *# <img src="img/crovoc.png" border="0">#; |
|
342 |
|
if ($mfn_link) { |
343 |
|
$term =~ s/ *#C# */ <img src="${base_path}img\/crovoc.png" border="0">/; |
344 |
$html .= " " x $level . |
$html .= " " x $level . |
345 |
qq{<li>${link_start}<span id="o$mfn">${term}</span>${link_end}}. |
qq{<li>${link_start}<span id="o$mfn">${term}</span>${link_end}}. |
346 |
qq{ <a href="$mfn_link" onClick="javascript:return popup(this);"><img src="img/listic.png" border="0"></a></li>\n}; |
qq{ <a href="${base_path}${mfn_link}" onClick="javascript:return popup(this);"><img src="${base_path}img/listic.png" border="0"></a></li>\n}; |
347 |
|
$log->debug("linked details to $mfn_link"); |
348 |
} else { |
} else { |
349 |
$log->warn("file 'out/$mfn_link' doesn't exist, skipping"); |
$log->warn("file 'out/$mfn_link' doesn't exist, skipping"); |
350 |
} |
} |
351 |
|
|
352 |
|
# save mfn for iframe |
353 |
|
push @{$self->{'mfn_arr'}}, $mfn; |
354 |
|
|
355 |
unless ($have_children) { |
unless ($have_children) { |
356 |
next; |
next; |
357 |
} |
} |
373 |
push @{$self->{'show_ids'}}, "id$mfn"; |
push @{$self->{'show_ids'}}, "id$mfn"; |
374 |
} |
} |
375 |
|
|
376 |
|
|
377 |
if ($tree->[$level]->{'iframe'}) { |
if ($tree->[$level]->{'iframe'}) { |
378 |
|
|
379 |
|
# reset list of current mfns |
380 |
|
$self->{'mfn_arr'} = (); |
381 |
|
|
382 |
# unroll to separate file |
# unroll to separate file |
383 |
$self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children); |
$self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children, $self->{'iframe_base'}); |
384 |
|
$html .= " " x $level . |
385 |
|
qq{<iframe id="i$mfn" name="i$mfn" width="100%" height="10" frameborder="0" border="0"></iframe>}; |
386 |
|
@{$self->{'iframe_mfn'}->{$mfn}} = @{$self->{'mfn_arr'}}; |
387 |
|
$log->debug("in this iframe: ", sub { Dump($self->{'iframe_mfn'}->{$mfn}) }); |
388 |
|
|
389 |
} else { |
} else { |
390 |
# unroll at base HTML |
# unroll at base HTML |
391 |
$html .= $self->unroll($next_level, $have_children); |
$html .= $self->unroll($next_level, $have_children, $base_path); |
392 |
} |
} |
393 |
|
|
394 |
$html .= " " x $level . qq{</ul>\n}; |
$html .= " " x $level . qq{</ul>\n}; |
424 |
open(JS, ">", $js_file) || $log->logdie("can't open '$js_file': $!"); |
open(JS, ">", $js_file) || $log->logdie("can't open '$js_file': $!"); |
425 |
print JS "var show = ['",join("','",@{$self->{'show_ids'}}),"'];\n"; |
print JS "var show = ['",join("','",@{$self->{'show_ids'}}),"'];\n"; |
426 |
print JS "var hide = ['",join("','",@{$self->{'hide_ids'}}),"'];\n"; |
print JS "var hide = ['",join("','",@{$self->{'hide_ids'}}),"'];\n"; |
427 |
|
|
428 |
|
print JS "var mfn_iframe = [\n"; |
429 |
|
foreach my $if (keys %{$self->{'iframe_mfn'}}) { |
430 |
|
print JS " ",join(",",map { "[$_:$if]" } @{$self->{'iframe_mfn'}->{$if}}),",\n"; |
431 |
|
} |
432 |
|
print JS " null\n]\n"; |
433 |
|
|
434 |
close(JS); |
close(JS); |
435 |
|
|
436 |
$log->debug("stored ",scalar @{$self->{'show_ids'}}," shown and ",scalar @{$self->{'hide_ids'}}," hidden elements"); |
$log->debug("stored ",scalar @{$self->{'show_ids'}}," shown and ",scalar @{$self->{'hide_ids'}}," hidden elements"); |