| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::Element::Web::Select - A select box on a form |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::Element::Web::Select; |
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
use base qw(Debconf::Element::Select); |
| 13 |
|
| 14 |
=head1 DESCRIPTION |
| 15 |
|
| 16 |
This element handles a select box on a web form. |
| 17 |
|
| 18 |
=head1 METHODS |
| 19 |
|
| 20 |
=over 4 |
| 21 |
|
| 22 |
=item show |
| 23 |
|
| 24 |
Generates and returns html representing the select box. |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
sub show { |
| 29 |
my $this=shift; |
| 30 |
|
| 31 |
$_=$this->question->extended_description; |
| 32 |
s/\n/\n<br>\n/g; |
| 33 |
$_.="\n<p>\n"; |
| 34 |
|
| 35 |
my $default=$this->translate_default; |
| 36 |
my $id=$this->id; |
| 37 |
$_.="<b>".$this->question->description."</b>\n<select name=\"$id\">\n"; |
| 38 |
my $c=0; |
| 39 |
foreach my $x ($this->question->choices_split) { |
| 40 |
if ($x ne $default) { |
| 41 |
$_.="<option value=".$c++.">$x\n"; |
| 42 |
} |
| 43 |
else { |
| 44 |
$_.="<option value=".$c++." selected>$x\n"; |
| 45 |
} |
| 46 |
} |
| 47 |
$_.="</select>\n"; |
| 48 |
|
| 49 |
return $_; |
| 50 |
} |
| 51 |
|
| 52 |
=item value |
| 53 |
|
| 54 |
Overridden to handle translating the value back to C locale when it is set. |
| 55 |
|
| 56 |
=cut |
| 57 |
|
| 58 |
sub value { |
| 59 |
my $this=shift; |
| 60 |
|
| 61 |
return $this->SUPER::value() unless @_; |
| 62 |
my $value=shift; |
| 63 |
|
| 64 |
# Get the choices in the C locale. |
| 65 |
$this->question->template->i18n(''); |
| 66 |
my @choices=$this->question->choices_split; |
| 67 |
$this->question->template->i18n(1); |
| 68 |
$this->SUPER::value($choices[$value]); |
| 69 |
} |
| 70 |
|
| 71 |
=back |
| 72 |
|
| 73 |
=head1 AUTHOR |
| 74 |
|
| 75 |
Joey Hess <[email protected]> |
| 76 |
|
| 77 |
=cut |
| 78 |
|
| 79 |
1 |