Debian Codegraph @

Debconf/Element/Web/Multiselect.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::Element::Web::Multiselect - A multi select box on a form
6
7 =cut
8
9 package Debconf::Element::Web::Multiselect;
10 use warnings;
11 use strict;
12 use base qw(Debconf::Element::Multiselect);
13
14 =head1 DESCRIPTION
15
16 This element handles a multi 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 multi 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 %value = map { $_ => 1 } $this->translate_default;
36
37 my $id=$this->id;
38 $_.="<b>".$this->question->description."</b>\n<select multiple name=\"$id\">\n";
39 my $c=0;
40 foreach my $x ($this->question->choices_split) {
41 if (! $value{$x}) {
42 $_.="<option value=".$c++.">$x\n";
43 }
44 else {
45 $_.="<option value=".$c++." selected>$x\n";
46 }
47 }
48 $_.="</select>\n";
49
50 return $_;
51 }
52
53 =item value
54
55 When setting a value, this expects to be passed all the values they
56 selected. It processes these into the form used internally.
57
58 =cut
59
60 sub value {
61 my $this=shift;
62
63 return $this->SUPER::value() unless @_;
64
65 # This forces the function that provides values to this method
66 # to be called in scalar context, so we are passed a list of
67 # the selected values.
68 my @values=@_;
69
70 # Get the choices in the C locale.
71 $this->question->template->i18n('');
72 my @choices=$this->question->choices_split;
73 $this->question->template->i18n(1);
74
75 $this->SUPER::value(join(', ', $this->order_values(map { $choices[$_] } @values)));
76 }
77
78 =back
79
80 =head1 AUTHOR
81
82 Joey Hess <[email protected]>
83
84 =cut
85
86 1