lib/TWiki/Configure/UIs/Value.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/TWiki/Configure/UIs/Value.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,108 @@
     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 +# UI generating package for simple values
    1.22 +#
    1.23 +package TWiki::Configure::UIs::Value;
    1.24 +
    1.25 +use strict;
    1.26 +use base 'TWiki::Configure::UI';
    1.27 +
    1.28 +# Generates the appropriate HTML for getting a value to configure the
    1.29 +# entry. The actual input field is decided by the type.
    1.30 +sub open_html {
    1.31 +    my ($this, $value, $valuer, $expert) = @_;
    1.32 +
    1.33 +    my $type = $value->getType();
    1.34 +    return '' if $value->{hidden};
    1.35 +
    1.36 +    my $info = '';
    1.37 +    my $isExpert = 0; # true if this is an EXPERT setting
    1.38 +    if ($value->isExpertsOnly()) {
    1.39 +        $isExpert = 1;
    1.40 +        $info = CGI::h6('EXPERT') . $info;
    1.41 +    }
    1.42 +    $info .= $value->{desc};
    1.43 +    my $keys = $value->getKeys();
    1.44 +
    1.45 +    my $checker = TWiki::Configure::UI::loadChecker($keys, $value);
    1.46 +    my $isUnused = 0;
    1.47 +    my $isBroken = 0;
    1.48 +    if ($checker) {
    1.49 +        my $check = $checker->check($value);
    1.50 +        if ($check) {
    1.51 +            # something wrong
    1.52 +            $info .= $check;
    1.53 +            $isBroken = 1;
    1.54 +        }
    1.55 +        if ($check && $check eq 'NOT USED IN THIS CONFIGURATION') {
    1.56 +            $isUnused = 1;
    1.57 +        }
    1.58 +    }
    1.59 +
    1.60 +	# Hide rows if this is an EXPERT setting in non-experts mode, or
    1.61 +    # this is a hidden or unused value
    1.62 +	my $hiddenClass = '';
    1.63 +    if ($isUnused ||
    1.64 +          !$isBroken && ($isExpert && !$expert || $value->{hidden})) {
    1.65 +        $hiddenClass = ' twikiHidden';
    1.66 +    }
    1.67 +
    1.68 +    # Generate the documentation row
    1.69 +	my $hiddenInput = $this->hidden( 'TYPEOF:'.$keys, $value->{typename} );
    1.70 +    my $row1 = $hiddenInput.$info;
    1.71 +
    1.72 +    # Generate col1 of the prompter row
    1.73 +    my $row2col1 = $keys;
    1.74 +    $row2col1 = CGI::span({class=>'mandatory'}, $row2col1)
    1.75 +      if $value->{mandatory};
    1.76 +    if ($value->needsSaving($valuer)) {
    1.77 +        my $v = $valuer->defaultValue($value) || '';
    1.78 +        $row2col1 .= CGI::span({title => 'default = '.$v,
    1.79 +                                class => 'twikiAlert'}, 'δ');
    1.80 +    }
    1.81 +
    1.82 +    # Generate col2 of the prompter row
    1.83 +    my $row2col2;
    1.84 +    if (!$isUnused && ($isBroken || !$isExpert || $expert)) {
    1.85 +        # Generate a prompter for the value.
    1.86 +        my $class = $value->{typename};
    1.87 +        $class .= ' mandatory' if ($value->{mandatory});
    1.88 +        $row2col2 = CGI::span(
    1.89 +            { class=>$class },
    1.90 +            $type->prompt(
    1.91 +                $keys, $value->{opts}, $valuer->currentValue($value)));
    1.92 +    } else {
    1.93 +        # Non-expert - just pass the value through a hidden
    1.94 +        $row2col2 = CGI::hidden($keys, $valuer->currentValue($value));
    1.95 +    }
    1.96 +
    1.97 +    return CGI::Tr(
    1.98 +        { class => $hiddenClass },
    1.99 +        CGI::td( { colspan => 2, class=>'docdata info' }, $row1))."\n"
   1.100 +        . CGI::Tr(
   1.101 +            { class => $hiddenClass },
   1.102 +            CGI::td({class=>'firstCol'}, $row2col1)."\n"
   1.103 +                . CGI::td({class=>'secondCol'}, $row2col2))."\n";
   1.104 +}
   1.105 +
   1.106 +sub close_html {
   1.107 +    my $this = shift;
   1.108 +    return '';
   1.109 +}
   1.110 +
   1.111 +1;