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