lib/TWiki/Configure/UIs/Value.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 # UI generating package for simple values
    19 #
    20 package TWiki::Configure::UIs::Value;
    21 
    22 use strict;
    23 use base 'TWiki::Configure::UI';
    24 
    25 # Generates the appropriate HTML for getting a value to configure the
    26 # entry. The actual input field is decided by the type.
    27 sub open_html {
    28     my ($this, $value, $valuer, $expert) = @_;
    29 
    30     my $type = $value->getType();
    31     return '' if $value->{hidden};
    32 
    33     my $info = '';
    34     my $isExpert = 0; # true if this is an EXPERT setting
    35     if ($value->isExpertsOnly()) {
    36         $isExpert = 1;
    37         $info = CGI::h6('EXPERT') . $info;
    38     }
    39     $info .= $value->{desc};
    40     my $keys = $value->getKeys();
    41 
    42     my $checker = TWiki::Configure::UI::loadChecker($keys, $value);
    43     my $isUnused = 0;
    44     my $isBroken = 0;
    45     if ($checker) {
    46         my $check = $checker->check($value);
    47         if ($check) {
    48             # something wrong
    49             $info .= $check;
    50             $isBroken = 1;
    51         }
    52         if ($check && $check eq 'NOT USED IN THIS CONFIGURATION') {
    53             $isUnused = 1;
    54         }
    55     }
    56 
    57 	# Hide rows if this is an EXPERT setting in non-experts mode, or
    58     # this is a hidden or unused value
    59 	my $hiddenClass = '';
    60     if ($isUnused ||
    61           !$isBroken && ($isExpert && !$expert || $value->{hidden})) {
    62         $hiddenClass = ' twikiHidden';
    63     }
    64 
    65     # Generate the documentation row
    66 	my $hiddenInput = $this->hidden( 'TYPEOF:'.$keys, $value->{typename} );
    67     my $row1 = $hiddenInput.$info;
    68 
    69     # Generate col1 of the prompter row
    70     my $row2col1 = $keys;
    71     $row2col1 = CGI::span({class=>'mandatory'}, $row2col1)
    72       if $value->{mandatory};
    73     if ($value->needsSaving($valuer)) {
    74         my $v = $valuer->defaultValue($value) || '';
    75         $row2col1 .= CGI::span({title => 'default = '.$v,
    76                                 class => 'twikiAlert'}, '&delta;');
    77     }
    78 
    79     # Generate col2 of the prompter row
    80     my $row2col2;
    81     if (!$isUnused && ($isBroken || !$isExpert || $expert)) {
    82         # Generate a prompter for the value.
    83         my $class = $value->{typename};
    84         $class .= ' mandatory' if ($value->{mandatory});
    85         $row2col2 = CGI::span(
    86             { class=>$class },
    87             $type->prompt(
    88                 $keys, $value->{opts}, $valuer->currentValue($value)));
    89     } else {
    90         # Non-expert - just pass the value through a hidden
    91         $row2col2 = CGI::hidden($keys, $valuer->currentValue($value));
    92     }
    93 
    94     return CGI::Tr(
    95         { class => $hiddenClass },
    96         CGI::td( { colspan => 2, class=>'docdata info' }, $row1))."\n"
    97         . CGI::Tr(
    98             { class => $hiddenClass },
    99             CGI::td({class=>'firstCol'}, $row2col1)."\n"
   100                 . CGI::td({class=>'secondCol'}, $row2col2))."\n";
   101 }
   102 
   103 sub close_html {
   104     my $this = shift;
   105     return '';
   106 }
   107 
   108 1;