lib/TWiki/Configure/UIs/Section.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/TWiki/Configure/UIs/Section.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +#
     1.5 +# TWiki Enterprise Collaboration Platform, http://TWiki.org/
     1.6 +#
     1.7 +# Copyright (C) 2000-2006 TWiki Contributors.
     1.8 +#
     1.9 +# This program is free software; you can redistribute it and/or
    1.10 +# modify it under the terms of the GNU General Public License
    1.11 +# as published by the Free Software Foundation; either version 2
    1.12 +# of the License, or (at your option) any later version. For
    1.13 +# more details read LICENSE in the root of this distribution.
    1.14 +#
    1.15 +# This program is distributed in the hope that it will be useful,
    1.16 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1.18 +#
    1.19 +# As per the GPL, removal of this notice is prohibited.
    1.20 +#
    1.21 +# A UI for a collection object, designed so the objects can be twisted.
    1.22 +# The UI is implemented by visiting the nodes of the configuration and
    1.23 +# invoking the open-html and close_html methods for each node. The
    1.24 +# layout of a configuration page is depth-sensitive, so we have slightly
    1.25 +# different behaviours for each of level 0 (the root), level 1 (twisty
    1.26 +# sections) and level > 1 (subsection).
    1.27 +package TWiki::Configure::UIs::Section;
    1.28 +use base 'TWiki::Configure::UI';
    1.29 +
    1.30 +use strict;
    1.31 +
    1.32 +# depth == 1 is the root
    1.33 +# depth == 2 are twisty sections
    1.34 +# depth > 2 are subsections
    1.35 +sub open_html {
    1.36 +    my ($this, $section, $valuer, $expert) = @_;
    1.37 +
    1.38 +    my $depth = $section->getDepth();
    1.39 +
    1.40 +    if ($depth > 2) {
    1.41 +        # A running section has no subtable, just a header row
    1.42 +        if (!$expert && $section->isExpertsOnly()) {
    1.43 +            return '';
    1.44 +        } else {
    1.45 +            my $fn = 'CGI::h'.$depth;
    1.46 +            no strict 'refs';
    1.47 +            my $head = &$fn($section->{headline});
    1.48 +            use strict 'refs';
    1.49 +            $head .= $section->{desc} if $section->{desc};
    1.50 +            return '<tr><td colspan=2>'.$head.'</td></tr>';
    1.51 +        }
    1.52 +    }
    1.53 +
    1.54 +    my $id = $this->_makeAnchor( $section->{headline} );
    1.55 +    my $linkId = 'blockLink'.$id;
    1.56 +    my $linkAnchor = $id.'link';
    1.57 +
    1.58 +    my $mess = $this->collectMessages($section);
    1.59 +
    1.60 +    my $guts = "<!-- $depth $section->{headline} -->";
    1.61 +    if ($depth == 2) {
    1.62 +        # Open row
    1.63 +        $guts .= '<tr><td colspan=2>';
    1.64 +        $guts .= CGI::a({ name => $linkAnchor });
    1.65 +
    1.66 +        # Open twisty div
    1.67 +        $guts .= CGI::a(
    1.68 +            {id => $linkId,
    1.69 +             class => 'blockLink blockLinkOff',
    1.70 +             href => '#'.$linkAnchor,
    1.71 +             rel => 'nofollow',
    1.72 +             onclick => 'foldBlock("' . $id . '"); return false;'},
    1.73 +            $section->{headline}.$mess);
    1.74 +
    1.75 +        $guts .= "<div id='$id' class='foldableBlock foldableBlockClosed'>";
    1.76 +    }
    1.77 +
    1.78 +    # Open subtable
    1.79 +    $guts .=
    1.80 +      CGI::start_table(
    1.81 +          { width => '100%', -border => 0, -cellspacing => 0,
    1.82 +            -cellpadding => 0, -cols => 2})."\n";
    1.83 +
    1.84 +    # Put info text inside table row for visual consistency
    1.85 +	if ($depth == 2) {
    1.86 +		$guts .= CGI::Tr(
    1.87 +        	CGI::td(
    1.88 +        		{ colspan => 2, class=>'docdata firstInfo' },
    1.89 +        			$section->{desc} )) if $section->{desc};
    1.90 +	}
    1.91 +	
    1.92 +    return $guts;
    1.93 +}
    1.94 +
    1.95 +sub close_html {
    1.96 +    my ($this, $section, $expert) = @_;
    1.97 +    my $depth = $section->getDepth();
    1.98 +    my $end = '';
    1.99 +    if ($depth <= 2) {
   1.100 +        # Close subtable
   1.101 +        $end = "</table>";
   1.102 +        if ($depth == 2) {
   1.103 +            # Close twisty div
   1.104 +            $end .= '</div>';
   1.105 +            # Close row
   1.106 +            $end .= '</td></tr>';
   1.107 +        }
   1.108 +    }
   1.109 +    return "$end<!-- /$depth $section->{headline} -->\n";
   1.110 +}
   1.111 +
   1.112 +1;
   1.113 +