blib/lib/Embperl/Form/Control/checkbox.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 186 CC 15 SCAR 27.2
CC
15
Cov
0%
get_display_text
30.0
init_data
20.0
init_markup
20.0
CRAP 15.2
1  
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2015 Gerald Richter
6 # Embperl - Copyright (c) 2015-2023 actevy.io
7 #
8 # You may distribute under the terms of either the GNU General Public
9 # License or the Artistic License, as specified in the Perl README file.
10 #
11 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
12 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
13 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 #
15 # $Id$
16 #
17 ###################################################################################
18  
19 package Embperl::Form::Control::checkbox ;
20  
21 use strict ;
22 use vars qw{%fdat} ;
23  
24 use base 'Embperl::Form::Control' ;
25  
26 use Embperl::Inline ;
27  
28  
29 # ---------------------------------------------------------------------------
30 #
31 # get_active_id - get the id of the value which is currently active
32 #
33  
34 sub get_active_id
35  
36 {
37 my ($self) = @_ ;
38  
39 my $name = $self -> {name} ;
40 my $val = $self -> {value} || 1 ;
41  
42 return $val eq $fdat{$name}?"$name-0":"$name-1" ;
43 }
44  
45  
46 # ---------------------------------------------------------------------------
47 #
48 # has_auto_label_size - returns true if label should be auto sized for this control
49 #
50  
51 sub has_auto_label_size
52 {
53 return 0 ;
54 }
55  
56 # ------------------------------------------------------------------------------------------
57 #
58 # init_data - daten aufteilen
59 #
60  
61 sub init_data
62 {
63 my ($self, $req, $grid) = @_ ;
64
65 return if (!$self -> is_readonly() && (!$grid || !$grid -> is_readonly())) ;
66
67 my $val = $self -> get_value ($req) ;
68 my $value = $self -> {value} ;
69 $value = 1 if ($value eq '') ;
70 my $fdat = $req -> {docdata} || \%Embperl::fdat ;
71 $fdat -> {"_opt_$self->{name}"} = $value eq $val?'X':'-' ;
72 }
73  
74 # ---------------------------------------------------------------------------
75 #
76 # show_control_readonly - output readonly control
77 #
78  
79 sub xshow_control_readonly
80 {
81 my ($self, $req) = @_ ;
82  
83 my $name = $self -> {name} ;
84 my $val = $self -> {value} ;
85 $val = 1 if ($val eq '') ;
86  
87 local $self -> {force_name} = '_opt_' . $self -> {name} ;
88 $self -> SUPER::show_control_readonly ($req, $fdat{$name} eq $val?'X':'-') ;
89 }
90  
91 # ------------------------------------------------------------------------------------------
92 #
93 # get_display_text - returns the text that should be displayed
94 #
95  
96 sub get_display_text
97 {
98 my ($self, $req, $value) = @_ ;
99  
100 my $fdat = $req -> {docdata} || \%fdat ;
101 my $name = $self -> {name} ;
102 my $val = $self -> {value} ;
103 $val = 1 if ($val eq '') ;
104
105 return $value eq $val?'X':'-' if (defined ($value)) ;
106 return $fdat->{$name} eq $val?'X':'-' ;
107 }
108  
109 # ---------------------------------------------------------------------------
110 #
111 # init_markup - add any dynamic markup to the form data
112 #
113  
114 sub init_markup
115  
116 {
117 my ($self, $req, $parentctl, $method) = @_ ;
118  
119 return if (!$self -> is_readonly($req) && (! $parentctl || ! $parentctl -> is_readonly($req))) ;
120
121 my $val = $self -> get_value ($req) ;
122 if ($val ne '')
123 {
124 my $name = $self -> {name} ;
125 my $fdat = $req -> {docdata} || \%Embperl::fdat ;
126 my $opt = $self -> get_display_text ($req, $val) ;
127 $fdat -> {'_opt_' . $name} = $opt if ($opt ne '') ;
128 }
129 }
130  
131 # ---------------------------------------------------------------------------
132 #
133 # label_text - return text of label
134 #
135  
136 sub label_text
137 {
138 my ($self, $req) = @_ ;
139  
140 if ($self -> {button} && !$self -> is_readonly)
141 {
142 $self->{controlclass} ||= 'ef-control-checkbox-button' ;
143 return '' ;
144 }
145 return $self -> SUPER::label_text ($req) ;
146 }
147  
148 1 ;
149  
150 __EMBPERL__
151  
152 [# ---------------------------------------------------------------------------
153 #
154 # show_control_readonly - output the control as readonly
155 #]
156  
157 [$ sub show_control_readonly ($self, $req, $value)
158  
159 my $text = $self -> get_display_text ($req, $value) ;
160 my $name = $self -> {force_name} || $self -> {name} ;
161 $]
162 <div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, '', 'readonly', 'ef-control-with-id') } +] _ef_divname="_opt_[+ $name +]">[+ $text +]</div>
163 [$ if $self->{hidden} $]
164 <input type="hidden" name="[+ $name +]" value="[+ $value +]">
165 [$endif$]
166 [$endsub$]
167  
168 [# ---------------------------------------------------------------------------
169 #
170 # show_control - output the control
171 #]
172  
173 [$ sub show_control ($self, $req)
174  
175 my $name = $self -> {name} ;
176 my $val = $self -> {value} || 1 ;
177 my $nsprefix = $self -> form -> {jsnamespace} ;
178  
179 $val =~ s/%%%name%%%/$fdat{$name}/g ;
180 $val =~ s/%%(.+?)%%/$fdat{$1}/g ;
181  
182 my ($ctlattrs, $ctlid, $ctlname) = $self -> get_std_control_attr($req) ;
183 push @{$self -> form -> {fields2empty}}, $name ;
184  
185 my $buttontext ;
186 if (ref $self -> {button})
187 {
188 if ($self -> {showtext})
189 {
190 $buttontext = join(',', @{$self -> {button}}) ;
191 }
192 else
193 {
194 $buttontext = join(',', map { $self -> form -> convert_text ($self, $_, undef, $req) } @{$self -> {button}}) ;
195 }
196 }
197 $]
198 <input type="checkbox" name="[+ $ctlname +]" [+ do { local $escmode = 0 ; $ctlattrs } +] value="[+ $val +]"
199 [$if ($self -> {trigger} || $self -> {button} || $self -> {timer}) $]_ef_attach="ef_checkbox"[$endif$]
200 [$if ($self -> {button}) $]_ef_button="1"[$endif$]
201 [$if ($buttontext) $]_ef_buttonlabels="[+ $buttontext +]"[$endif$]
202 >[$if ($self -> {button}) $]<label for="[+ $ctlid +]"></label>[$endif$]
203 [$endsub$]
204  
205 [# ---------------------------------------------------------------------------
206 #
207 # show_control_addons - output additional things after the control
208 #]
209  
210 [$ sub show_control_addons ($self, $req) $][$if ($self -> {timer}) $]<span class='ui-icon ui-icon-clock ef-icon'></span>[$endif$][$endsub$]
211  
212  
213 __END__