| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Quiq::Html::Widget::CheckBox - Checkbox | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | L<Quiq::Html::Widget> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =over 4 | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =item class => $class (Default: undef) | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | CSS Klasse. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =item disabled => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Keine Eingabe möglich. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =item hidden => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Nicht sichtbar. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =item id => $id (Default: undef) | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | CSS-Id. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =item label => $html (Default: '') | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Label rechts neben der Checkbox. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =item name => $name (Default: undef) | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Name, unter dem die Checkbox kommuniziert wird. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =item onClick => $js (Default: undef) | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | OnClick-Handler. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =item option => $value -or- [$checkedValue,$uncheckedValue] (Default: undef) | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Wert, der gesendet wird, wenn die CheckBox aktiviert ist. Ist der Wert | ||||||||||||||||||||||||||||
| 48 | eine Arrayreferenz, wird der erste Wert des Arrays gesendet, wenn | ||||||||||||||||||||||||||||
| 49 | die Checkbox aktiviert ist, andernfalls der zweite Wert. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =item style => $style (Default: undef) | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | CSS Definition (inline). | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item title => $str (Default: undef) | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Tooltip-Text. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item undefIf => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Wenn wahr, liefere C<undef> als Widget-Code. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =item value => $value (Default: undef) | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Aktueller Wert. Stimmt dieser mit dem Wert des Attributs option | ||||||||||||||||||||||||||||
| 66 | überein, wird die Checkbox aktiviert. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =back | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | package Quiq::Html::Widget::CheckBox; | ||||||||||||||||||||||||||||
| 75 | 4 | ▶ | use base qw/Quiq::Html::Widget/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | ▶ | use Quiq::Html::Widget::Hidden; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | 4 | ▶ | use Quiq::JavaScript; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head1 METHODS | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head2 Konstruktor | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head3 new() - Konstruktor | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | $e = $class->new(@keyVal); | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 104 | # @_: @keyVal | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Defaultwerte | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 6 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||
| 109 | class => undef, | ||||||||||||||||||||||||||||
| 110 | disabled => 0, | ||||||||||||||||||||||||||||
| 111 | hidden => 0, | ||||||||||||||||||||||||||||
| 112 | id => undef, | ||||||||||||||||||||||||||||
| 113 | label => '', | ||||||||||||||||||||||||||||
| 114 | name => undef, | ||||||||||||||||||||||||||||
| 115 | onClick => undef, | ||||||||||||||||||||||||||||
| 116 | option => undef, | ||||||||||||||||||||||||||||
| 117 | style => undef, | ||||||||||||||||||||||||||||
| 118 | title => undef, | ||||||||||||||||||||||||||||
| 119 | undefIf => 0, | ||||||||||||||||||||||||||||
| 120 | value => undef, | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | 6 | $self->set(@_); | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 6 | return $self; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head2 Objektmethoden | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head3 html() - Generiere HTML-Code | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | $html = $e->html($h); | ||||||||||||||||||||||||||||
| 136 | $html = $class->html($h,@keyVal); | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 6 | ▶ | sub html { | ||||||||||||||||||||||||||
|
Subroutine
html: called CC=13 SCAR=34.9
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | 6 | my $this = shift; | |||||||||||||||||||||||||||
| 144 | 6 | my $h = shift; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 6 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # Attribute | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 6 | my ($class,$disabled,$hidden,$id,$label,$name,$onClick,$option,$style, | |||||||||||||||||||||||||||
| 151 | $title,$undefIf,$value) = $self->get(qw/class disabled hidden id | ||||||||||||||||||||||||||||
| 152 | label name onClick option style title undefIf value/); | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # Generierung | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 6 | ▶ | if ($undefIf) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | return undef; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 6 | ▶ | if ($hidden) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | return ''; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 6 | my $html; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 6 | ▶ | if (ref $option) { # option => [$checkedValue,$uncheckedValue] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $html .= Quiq::Html::Widget::Hidden->html($h, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and $value eq $option->[0]
MC/DC0%0/2
defined $value and $value eq $option->[0]
defined $value
$value eq $option->[0]
Truth table0%0/3
A and B
A= defined $valueB= $value eq $option->[0]
| |||||||||||||||||||||||||||||
| 168 | name => $name, | ||||||||||||||||||||||||||||
| 169 | value => defined($value) && $value eq $option->[0]? | ||||||||||||||||||||||||||||
| 170 | $option->[0]: $option->[1], | ||||||||||||||||||||||||||||
| 171 | disabled => $disabled, | ||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||
| 173 | 0 | chomp $html; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | my $js = 'this.previousElementSibling.value = this.checked?'. | |||||||||||||||||||||||||||
| 176 | " '$option->[0]': '$option->[1]'"; | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if (my $onClick = Quiq::JavaScript->line($onClick)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | $js .= "; $onClick"; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $html .= $h->tag('input', | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and $value eq $option->[0]
MC/DC0%0/2
defined $value and $value eq $option->[0]
defined $value
$value eq $option->[0]
Truth table0%0/3
A and B
A= defined $valueB= $value eq $option->[0]
| |||||||||||||||||||||||||||||
| 182 | -nl => 0, | ||||||||||||||||||||||||||||
| 183 | type => 'checkbox', | ||||||||||||||||||||||||||||
| 184 | id => $id, | ||||||||||||||||||||||||||||
| 185 | class => $class, | ||||||||||||||||||||||||||||
| 186 | style => $style, | ||||||||||||||||||||||||||||
| 187 | disabled => $disabled, | ||||||||||||||||||||||||||||
| 188 | checked => defined($value) && $value eq $option->[0]? 1: 0, | ||||||||||||||||||||||||||||
| 189 | title => $title, | ||||||||||||||||||||||||||||
| 190 | onclick => $js, | ||||||||||||||||||||||||||||
| 191 | ); | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||
| 194 | 6 | ▶ | $html .= $h->tag('input', | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and $value eq $option
MC/DC100%2/2
defined $value and $value eq $option
defined $value
$value eq $option
Truth table100%3/3
A and B
A= defined $valueB= $value eq $option
| |||||||||||||||||||||||||||||
| 195 | -nl => 0, | ||||||||||||||||||||||||||||
| 196 | type => 'checkbox', | ||||||||||||||||||||||||||||
| 197 | id => $id, | ||||||||||||||||||||||||||||
| 198 | name => $name, | ||||||||||||||||||||||||||||
| 199 | class => $class, | ||||||||||||||||||||||||||||
| 200 | style => $style, | ||||||||||||||||||||||||||||
| 201 | disabled => $disabled, | ||||||||||||||||||||||||||||
| 202 | value => $option, | ||||||||||||||||||||||||||||
| 203 | checked => defined($value) && $value eq $option? 1: 0, | ||||||||||||||||||||||||||||
| 204 | title => $title, | ||||||||||||||||||||||||||||
| 205 | onclick => Quiq::JavaScript->line($onClick), | ||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 6 | ▶ | if ($label ne '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 4 | $html .= $label; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 6 | return $html; | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =head1 VERSION | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 1.240 | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 233 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =cut | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 4 | 1; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # eof | ||||||||||||||||||||||||||||