~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Configure/UIs/Value.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
package Foswiki::Configure::UIs::Value;
 
4
 
 
5
use strict;
 
6
use base 'Foswiki::Configure::UI';
 
7
 
 
8
# Generates the appropriate HTML for getting a value to configure the
 
9
# entry. The actual input field is decided by the type.
 
10
sub open_html {
 
11
    my ( $this, $value, $valuer, $expert ) = @_;
 
12
 
 
13
    my $type = $value->getType();
 
14
    return '' if $value->{hidden};
 
15
 
 
16
    my $info     = '';
 
17
    my $isExpert = 0;    # true if this is an EXPERT setting
 
18
    if ( $value->isExpertsOnly() ) {
 
19
        $isExpert = 1;
 
20
        $info     = CGI::h6('EXPERT') . $info;
 
21
    }
 
22
    $info .= $value->{desc};
 
23
    my $keys = $value->getKeys();
 
24
 
 
25
    my $checker  = Foswiki::Configure::UI::loadChecker( $keys, $value );
 
26
    my $isUnused = 0;
 
27
    my $isBroken = 0;
 
28
    if ($checker) {
 
29
        my $check = $checker->check($value);
 
30
        if ($check) {
 
31
 
 
32
            # something wrong
 
33
            $info .= $check;
 
34
            $isBroken = 1;
 
35
        }
 
36
        if ( $check && $check eq 'NOT USED IN THIS CONFIGURATION' ) {
 
37
            $isUnused = 1;
 
38
        }
 
39
    }
 
40
 
 
41
    # Hide rows if this is an EXPERT setting in non-experts mode, or
 
42
    # this is a hidden or unused value
 
43
    my $hiddenClass = '';
 
44
    if ( $isUnused
 
45
        || !$isBroken && ( $isExpert && !$expert || $value->{hidden} ) )
 
46
    {
 
47
        $hiddenClass = 'foswikiHidden';
 
48
    }
 
49
 
 
50
    # Generate the documentation row
 
51
    my $hiddenTypeOf = $this->hidden( 'TYPEOF:' . $keys, $value->{typename} );
 
52
    my $row1 = $hiddenTypeOf . $info;
 
53
 
 
54
    # Generate col1 of the prompter row
 
55
    my $row2col1 = $keys;
 
56
    $row2col1 = CGI::span( { class => 'mandatory' }, $row2col1 )
 
57
      if $value->{mandatory};
 
58
    if ( $value->needsSaving($valuer) ) {
 
59
        my $defaultValue = $valuer->defaultValue($value) || '';
 
60
 
 
61
      # special case are Perl data structures
 
62
      # in order to edit this in the browser, it must get translated to a string
 
63
        if ( $value->{typename} eq 'PERL' || $value->{typename} eq 'HASH' ) {
 
64
            use Data::Dumper;
 
65
            $Data::Dumper::Terse = 1;
 
66
            $defaultValue        = Dumper($defaultValue);
 
67
 
 
68
            # create stubs for special characters, put them back with javascript
 
69
            $defaultValue =~ s/'/#26;/go;
 
70
            $defaultValue =~ s/"/#22;/go;
 
71
            $defaultValue =~ s/\n/#13;/go;
 
72
        }
 
73
 
 
74
        $row2col1 .= CGI::span(
 
75
            {
 
76
                title => $defaultValue,
 
77
                class => $value->{typename} . ' delta foswikiAlert'
 
78
            },
 
79
            ' δ'
 
80
        );
 
81
 
 
82
        # prepare javascript call
 
83
        ( my $safeKeys = $keys ) =~ s/'/#26;/go;
 
84
        my @onClickParams = (
 
85
            'this',          "\'$value->{typename}\'",
 
86
            "\'$safeKeys\'", "\'$defaultValue\'"
 
87
        );
 
88
        my $onClickParamsString = join( ", ", @onClickParams );
 
89
 
 
90
        # first link CSS class name must be type
 
91
        # a bit of a hack but we need to pass the type of the field the link
 
92
        # will be changing
 
93
 
 
94
        $row2col1 .= ' '
 
95
          . CGI::a(
 
96
            {
 
97
                title => $defaultValue,
 
98
                class => $value->{typename} . ' defaultValueLink foswikiSmall',
 
99
                href  => '#',
 
100
                onclick => 'resetToDefaultValue('
 
101
                  . $onClickParamsString
 
102
                  . '); return false;',
 
103
            },
 
104
            ''
 
105
          );
 
106
    }
 
107
 
 
108
    # Generate col2 of the prompter row
 
109
    my $row2col2;
 
110
    if ( !$isUnused && ( $isBroken || !$isExpert || $expert ) ) {
 
111
 
 
112
        # Generate a prompter for the value.
 
113
        my $class = $value->{typename};
 
114
        $class .= ' mandatory' if ( $value->{mandatory} );
 
115
        $row2col2 = CGI::span(
 
116
            { class => $class },
 
117
            $type->prompt(
 
118
                $keys, $value->{opts}, $valuer->currentValue($value)
 
119
            )
 
120
        );
 
121
    }
 
122
    else {
 
123
 
 
124
        # Non-expert - just pass the value through a hidden
 
125
        $row2col2 = CGI::hidden( $keys, $valuer->currentValue($value) );
 
126
    }
 
127
 
 
128
    return CGI::Tr(
 
129
        { class => $hiddenClass },
 
130
        CGI::td( { class => 'firstCol' }, $row2col1 ) . "\n"
 
131
          . CGI::td( { class => 'secondCol' }, $row2col2 )
 
132
      )
 
133
      . "\n"
 
134
      . CGI::Tr( { class => $hiddenClass },
 
135
        CGI::td( { colspan => "2", class => 'docdata info' }, $row1 ) )
 
136
      . "\n";
 
137
}
 
138
 
 
139
sub close_html {
 
140
    my $this = shift;
 
141
    return '';
 
142
}
 
143
 
 
144
1;
 
145
__DATA__
 
146
#
 
147
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
148
#
 
149
# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.
 
150
# Foswiki Contributors are listed in the AUTHORS file in the root
 
151
# of this distribution. NOTE: Please extend that file, not this notice.
 
152
#
 
153
# Additional copyrights apply to some or all of the code in this
 
154
# file as follows:
 
155
#
 
156
# Copyright (C) 2000-2006 TWiki Contributors. All Rights Reserved.
 
157
# TWiki Contributors are listed in the AUTHORS file in the root
 
158
# of this distribution. NOTE: Please extend that file, not this notice.
 
159
#
 
160
# This program is free software; you can redistribute it and/or
 
161
# modify it under the terms of the GNU General Public License
 
162
# as published by the Free Software Foundation; either version 2
 
163
# of the License, or (at your option) any later version. For
 
164
# more details read LICENSE in the root of this distribution.
 
165
#
 
166
# This program is distributed in the hope that it will be useful,
 
167
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
168
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
169
#
 
170
# As per the GPL, removal of this notice is prohibited.
 
171
#
 
172
# UI generating package for simple values
 
173
#