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