Debian Codegraph @

Embperl/Form/Control/radio.pm

raw
1
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2014 Gerald Richter
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the Perl README file.
9 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 #
14 # $Id$
15 #
16 ###################################################################################
17
18 package Embperl::Form::Control::radio ;
19
20 use strict ;
21 use vars qw{%fdat} ;
22 use base 'Embperl::Form::ControlMultValue' ;
23
24 use Embperl::Inline ;
25
26
27 # ---------------------------------------------------------------------------
28
29 sub show_control_addons
30 {
31 my ($self, $req) = @_ ;
32
33 }
34
35 1 ;
36
37 __EMBPERL__
38
39 [# ---------------------------------------------------------------------------
40 #
41 # show_control - output the control
42 #]
43
44 [$ sub show_control ($self, $req, $filter, $values, $options)
45
46 ($values, $options) = $self -> get_values ($req) if (!$values) ;
47 my $name = $self -> {name} ;
48 my $ignorecase= $self -> {ignorecase} ;
49 my $max = @$values ;
50 my $set = !defined ($fdat{$name})?1:0 ;
51 my $nsprefix = $self -> form -> {jsnamespace} ;
52 my $ctrlid = ($req -> {uuid} . '_' . $name) ;
53 my $val ;
54 my $i = 0 ;
55
56 if ($self -> {vert})
57 {
58 $tr = '<tr>' ;
59 $trend = '</tr>' ;
60 $trglob = '' ;
61 $trendglob = '' ;
62 }
63 else
64 {
65 $tr = '' ;
66 $trend = '' ;
67 $trglob = '<tr>' ;
68 $trendglob = '</tr>' ;
69 }
70
71 $]
72 <table class="ef-control-radiotab [+ $self -> {state} +]"
73 [$if ($self -> {trigger}) $]_ef_attach="ef_radio" name="[+ $self -> {force_name} || $self -> {name} +]"[$endif$]
74 >[+ do { local $escmode = 0 ; $trglob }+]
75 [$ foreach $val (@$values) $][- $x = ($val =~ /$filter/i) -]
76 [- $fdat{$name} = $val, $set = 0 if ($set) ;
77 $fdat{$name} = $val if ($ignorecase && lc($fdat{$name}) eq lc($val)) ; -]
78 [+ do { local $escmode = 0 ; $tr }+]<td><input type="radio" name="[+ $self -> {force_name} || $self -> {name} +]" [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, "$ctlid-_-$val") } +] value="[+ $val +]"
79 ></td><td>[+ $options ->[$i] || $val +]</td>[+ do { local $escmode = 0 ; $trend }+]
80 [* $i++ ; *]
81 [$endforeach$]
82 [+ do { local $escmode = 0 ; $trendglob }+]</table>
83 [$endsub$]
84
85
86
87 __END__
88
89 =pod
90
91 =head1 NAME
92
93 Embperl::Form::Control::radio - A radio control inside an Embperl Form
94
95
96 =head1 SYNOPSIS
97
98 {
99 type => 'radio',
100 text => 'blabla',
101 name => 'foo',
102 values => [1,2,3],
103 options => ['foo', 'bar', 'none'],
104 }
105
106 =head1 DESCRIPTION
107
108 Used to create an radio control inside an Embperl Form.
109 See Embperl::Form on how to specify parameters.
110
111 =head2 PARAMETER
112
113 =head3 type
114
115 Needs to be 'radio'
116
117 =head3 name
118
119 Specifies the name of the radio control
120
121 =head3 text
122
123 Will be used as label for the radio control
124
125 =head3 values
126
127 Gives the values as an array ref of the radio control.
128
129 =head3 options
130
131 Gives the options as an array ref that should be displayed to the user.
132 If no options are given, the values from values are used.
133
134 =head3 vert
135
136 If specified arranges the radio button vertically. The number given specifies
137 the number of <br>'s used the separate the radio buttons.
138
139 =head3 ignorecase
140
141 If given, ignore the case of the posted values in %fdat, when selecting
142 a radio button.
143
144 =head3 addtop
145
146 Array ref which contains items that should be added at the left or top
147 of the radio buttons. Each item consists of an array ref with two
148 entries, the first is the value and the second is the option
149 that is displayed on the page. If the second is missing the
150 value (first entry)is displayed. Example:
151
152 addtop => [ [1 => 'first item'], [2 => 'second item']]
153
154 =head3 addbottom
155
156 Array ref which contains items that should be added at the right or bottom
157 of the radio buttons. Each item consists of an array ref with two
158 entries, the first is the value and the second is the option
159 that is displayed on the page. If the second is missing the
160 value (first entry)is displayed. Example:
161
162 addbottom => [ [9999 => 'last item'], [9999 => 'very last item']]
163
164 =head3 filter
165
166 If given, only items where the value matches the regex given in
167 C<filter> are displayed.
168
169 =head1 Author
170
171 G. Richter (richter at embperl dot org)
172
173 =head1 See Also
174
175 perl(1), Embperl, Embperl::Form
176
177