Handle hostnames with upper-case letters
[webmin.git] / Webmin / Radios.pm
1 package Webmin::Radios;
2 use Webmin::Input;
3 use WebminCore;
4 @ISA = ( "Webmin::Input" );
5
6 =head2 new Webmin::Radios(name, value, &options, [disabled])
7 Create a list of radio buttons, of which one may be selected
8 =cut
9 sub new
10 {
11 if (defined(&Webmin::Theme::Radios::new)) {
12         return new Webmin::Theme::Radios(@_[1..$#_]);
13         }
14 my ($self, $name, $value, $options, $disabled) = @_;
15 $self = { };
16 bless($self);
17 $self->set_name($name);
18 $self->set_value($value);
19 $self->set_options($options);
20 $self->set_disabled($disabled);
21 return $self;
22 }
23
24 =head2 add_option(name, [label])
25 =cut
26 sub add_option
27 {
28 my ($self, $name, $label) = @_;
29 push(@{$self->{'options'}}, [ $name, $label ]);
30 }
31
32 =head2 html()
33 Returns the HTML for all the radio buttons, one after the other
34 =cut
35 sub html
36 {
37 my ($self) = @_;
38 my $dis = $self->{'form'}->get_changefunc($self);
39 my $opts = $self->get_options();
40 if ($dis) {
41         foreach my $o (@$opts) {
42                 $o->[2] = "onClick='$dis'";
43                 }
44         }
45 return &ui_radio($self->get_name(), $self->get_value(),
46                        $opts, $self->get_disabled());
47 }
48
49 =head2 one_html(number)
50 Returns the HTML for a single one of the radio buttons
51 =cut
52 sub one_html
53 {
54 my ($self, $num) = @_;
55 my $opt = $self->{'options'}->[$num];
56 my $dis = $self->{'form'}->get_changefunc($self);
57 return &ui_oneradio($self->get_name(), $opt->[0],
58                           defined($opt->[1]) ? $opt->[1] : $opt->[0],
59                           $self->get_value() eq $opt->[0],
60                           $dis ? "onClick='$dis'" : undef,
61                           $self->get_disabled());
62 }
63
64 sub set_options
65 {
66 my ($self, $options) = @_;
67 $self->{'options'} = $options;
68 }
69
70 sub get_options
71 {
72 my ($self) = @_;
73 return $self->{'options'};
74 }
75
76 1;
77