~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Configure/UIs/Section.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

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