lib/TWiki/Configure/UIs/Section.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rw-r--r--
RELEASE 4.2.0 freetown
     1 #
     2 # TWiki Enterprise Collaboration Platform, http://TWiki.org/
     3 #
     4 # Copyright (C) 2000-2006 TWiki Contributors.
     5 #
     6 # This program is free software; you can redistribute it and/or
     7 # modify it under the terms of the GNU General Public License
     8 # as published by the Free Software Foundation; either version 2
     9 # of the License, or (at your option) any later version. For
    10 # more details read LICENSE in the root of this distribution.
    11 #
    12 # This program is distributed in the hope that it will be useful,
    13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    15 #
    16 # As per the GPL, removal of this notice is prohibited.
    17 #
    18 # A UI for a collection object, designed so the objects can be twisted.
    19 # The UI is implemented by visiting the nodes of the configuration and
    20 # invoking the open-html and close_html methods for each node. The
    21 # layout of a configuration page is depth-sensitive, so we have slightly
    22 # different behaviours for each of level 0 (the root), level 1 (twisty
    23 # sections) and level > 1 (subsection).
    24 package TWiki::Configure::UIs::Section;
    25 use base 'TWiki::Configure::UI';
    26 
    27 use strict;
    28 
    29 # depth == 1 is the root
    30 # depth == 2 are twisty sections
    31 # depth > 2 are subsections
    32 sub open_html {
    33     my ($this, $section, $valuer, $expert) = @_;
    34 
    35     my $depth = $section->getDepth();
    36 
    37     if ($depth > 2) {
    38         # A running section has no subtable, just a header row
    39         if (!$expert && $section->isExpertsOnly()) {
    40             return '';
    41         } else {
    42             my $fn = 'CGI::h'.$depth;
    43             no strict 'refs';
    44             my $head = &$fn($section->{headline});
    45             use strict 'refs';
    46             $head .= $section->{desc} if $section->{desc};
    47             return '<tr><td colspan=2>'.$head.'</td></tr>';
    48         }
    49     }
    50 
    51     my $id = $this->_makeAnchor( $section->{headline} );
    52     my $linkId = 'blockLink'.$id;
    53     my $linkAnchor = $id.'link';
    54 
    55     my $mess = $this->collectMessages($section);
    56 
    57     my $guts = "<!-- $depth $section->{headline} -->";
    58     if ($depth == 2) {
    59         # Open row
    60         $guts .= '<tr><td colspan=2>';
    61         $guts .= CGI::a({ name => $linkAnchor });
    62 
    63         # Open twisty div
    64         $guts .= CGI::a(
    65             {id => $linkId,
    66              class => 'blockLink blockLinkOff',
    67              href => '#'.$linkAnchor,
    68              rel => 'nofollow',
    69              onclick => 'foldBlock("' . $id . '"); return false;'},
    70             $section->{headline}.$mess);
    71 
    72         $guts .= "<div id='$id' class='foldableBlock foldableBlockClosed'>";
    73     }
    74 
    75     # Open subtable
    76     $guts .=
    77       CGI::start_table(
    78           { width => '100%', -border => 0, -cellspacing => 0,
    79             -cellpadding => 0, -cols => 2})."\n";
    80 
    81     # Put info text inside table row for visual consistency
    82 	if ($depth == 2) {
    83 		$guts .= CGI::Tr(
    84         	CGI::td(
    85         		{ colspan => 2, class=>'docdata firstInfo' },
    86         			$section->{desc} )) if $section->{desc};
    87 	}
    88 	
    89     return $guts;
    90 }
    91 
    92 sub close_html {
    93     my ($this, $section, $expert) = @_;
    94     my $depth = $section->getDepth();
    95     my $end = '';
    96     if ($depth <= 2) {
    97         # Close subtable
    98         $end = "</table>";
    99         if ($depth == 2) {
   100             # Close twisty div
   101             $end .= '</div>';
   102             # Close row
   103             $end .= '</td></tr>';
   104         }
   105     }
   106     return "$end<!-- /$depth $section->{headline} -->\n";
   107 }
   108 
   109 1;
   110