| 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::checkboxes ; |
| 19 |
|
| 20 |
use strict ; |
| 21 |
use vars qw{%fdat} ; |
| 22 |
use base 'Embperl::Form::ControlMultValue' ; |
| 23 |
|
| 24 |
use Embperl::Inline ; |
| 25 |
|
| 26 |
# --------------------------------------------------------------------------- |
| 27 |
# |
| 28 |
# show_control_readonly - output readonly control |
| 29 |
# |
| 30 |
|
| 31 |
sub show_control_readonly |
| 32 |
{ |
| 33 |
my ($self, $req) = @_ ; |
| 34 |
|
| 35 |
my $name = $self -> {name} ; |
| 36 |
my @values = split (/\t/, $fdat{$name}) ; |
| 37 |
$self -> show_control ($req, "^(?:" . join ('|', map { "\Q$_\E" } @values) . ")\$") ; |
| 38 |
} |
| 39 |
|
| 40 |
# --------------------------------------------------------------------------- |
| 41 |
|
| 42 |
sub show_control_addons |
| 43 |
{ |
| 44 |
my ($self, $req) = @_ ; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
# ------------------------------------------------------------------------------------------ |
| 49 |
# |
| 50 |
# init_data - daten aufteilen |
| 51 |
# |
| 52 |
|
| 53 |
sub init_data |
| 54 |
{ |
| 55 |
my ($self, $req) = @_ ; |
| 56 |
|
| 57 |
my $fdat = $req -> {docdata} || \%fdat ; |
| 58 |
my $name = $self->{name} ; |
| 59 |
if (ref $fdat -> {$name}) |
| 60 |
{ |
| 61 |
$fdat -> {$name} = join ("\t", @{$fdat -> {$name}}) ; |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
1 ; |
| 66 |
|
| 67 |
__EMBPERL__ |
| 68 |
|
| 69 |
[# --------------------------------------------------------------------------- |
| 70 |
# |
| 71 |
# show_control - output the control |
| 72 |
#] |
| 73 |
|
| 74 |
[$ sub show_control ($self, $req, $filter) |
| 75 |
|
| 76 |
my $name = $self -> {name} ; |
| 77 |
$filter ||= $self -> {filter} ; |
| 78 |
my $val ; |
| 79 |
my $i = 0 ; |
| 80 |
my ($values, $options) = $self -> get_all_values ($req) ; |
| 81 |
my ($ctlattrs, $ctlid, $ctlname) = $self -> get_std_control_attr($req) ; |
| 82 |
my $tab = $self -> {tab} ; |
| 83 |
|
| 84 |
$] |
| 85 |
[$if $tab $]<[# #]table style="width: 100%">[$ endif $] |
| 86 |
[* $i = 0 ; *] |
| 87 |
[$ foreach $val (@$values) $] |
| 88 |
[$if !defined ($filter) || ($val =~ /$filter/i) $] |
| 89 |
[$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td style="width: 3%">[$endif$] |
| 90 |
<input type="checkbox" name="[+ $name +]" value="[+ $val +]" [+ do { local $escmode = 0 ; $ctlattrs } +] |
| 91 |
[$if ($self -> {trigger}) $]_ef_attach="ef_checkbox"[$endif$] > |
| 92 |
[$ if $tab $]</td><td style="width: [+ int((100 - ($tab * 3)) / $tab) +]%">[$endif$] |
| 93 |
[+ $options ->[$i] || $val +] |
| 94 |
[- $vert = $self -> {vert} -][$while $vert-- > 0 $]<br/>[$endwhile$] |
| 95 |
[$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] |
| 96 |
[$endif$] |
| 97 |
[* $i++ ; *] |
| 98 |
[$endforeach$] |
| 99 |
[$if $tab $]<[# #]/table>[$ endif $] |
| 100 |
[$endsub$] |
| 101 |
|
| 102 |
|
| 103 |
[$ sub xxshow_control ($self, $req, $filter) |
| 104 |
|
| 105 |
my ($values, $options) = $self -> get_values ($req) ; |
| 106 |
my $name = $self -> {name} ; |
| 107 |
$filter ||= $self -> {filter} ; |
| 108 |
my $addtop = $self -> {addtop} || [] ; |
| 109 |
my $addbottom= $self -> {addbottom} || [] ; |
| 110 |
my $max = @$values ; |
| 111 |
my $set = !defined ($fdat{$name})?1:0 ; |
| 112 |
my $tab = $self -> {tab} ; |
| 113 |
my $colcnt = 0 ; |
| 114 |
push @{$self -> form -> {fields2empty}}, $name ; |
| 115 |
|
| 116 |
my $val ; |
| 117 |
my $i = 0 ; |
| 118 |
$] |
| 119 |
[$if $tab $]<[# #]table width=100% style="width: 100%" >[$ endif $] |
| 120 |
[$ foreach $val (@$addtop) $] |
| 121 |
[$if !defined ($filter) || ($val->[0] =~ /$filter/i) $] |
| 122 |
[$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td>[$endif$] |
| 123 |
[#- $fdat{$name} = $val -> [0], $set = 0 if ($set) ; -#] |
| 124 |
<input type="checkbox" name="[+ $name +]" value="[+ $val -> [0] +]" |
| 125 |
> |
| 126 |
[$ if $tab $]</td><td>[$endif$] |
| 127 |
[+ $val ->[1] || $val -> [0] +] |
| 128 |
[$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] |
| 129 |
[$endif$] |
| 130 |
[$endforeach$] |
| 131 |
[$ foreach $val (@$values) $] |
| 132 |
[$if !defined ($filter) || ($val =~ /$filter/i) $] |
| 133 |
[$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td>[$endif$] |
| 134 |
[#- $fdat{$name} = $val, $set = 0 if ($set) ; -#] |
| 135 |
<input type="checkbox" name="[+ $name +]" value="[+ $val +]" |
| 136 |
[$if ($self -> {sublines} || $self -> {subobjects}) $] OnClick="show_checkboxes_checked(this,[+ $i +],[+ $max +])" [$endif$] |
| 137 |
> |
| 138 |
[$ if $tab $]</td><td>[$endif$] |
| 139 |
[+ $options ->[$i] || $val +] |
| 140 |
[- $vert = $self -> {vert} -][$while $vert-- > 0 $]<br/>[$endwhile$] |
| 141 |
[$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] |
| 142 |
[$endif$] |
| 143 |
[* $i++ ; *] |
| 144 |
[$endforeach$] |
| 145 |
[$ foreach $val (@$addbottom) $] |
| 146 |
[$if !defined ($filter) || ($val->[0] =~ /$filter/i) $] |
| 147 |
[$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td>[$endif$] |
| 148 |
[#- $fdat{$name} = $val -> [0], $set = 0 if ($set) ; -#] |
| 149 |
<input type="checkbox" name="[+ $name +]" value="[+ $val -> [0] +]" |
| 150 |
> |
| 151 |
[$ if $tab $]</td><td>[$endif$] |
| 152 |
[+ $val ->[1] || $val -> [0] +] |
| 153 |
[$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] |
| 154 |
[$endif$] |
| 155 |
[$endforeach$] |
| 156 |
[$if $tab $]<[# #]/table>[$ endif $] |
| 157 |
|
| 158 |
[$endsub$] |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
__END__ |
| 163 |
|
| 164 |
=pod |
| 165 |
|
| 166 |
=head1 NAME |
| 167 |
|
| 168 |
Embperl::Form::Control::checkboxes - A multiple checkbox control inside an Embperl Form |
| 169 |
|
| 170 |
|
| 171 |
=head1 SYNOPSIS |
| 172 |
|
| 173 |
{ |
| 174 |
type => 'checkboxes', |
| 175 |
text => 'blabla', |
| 176 |
name => 'foo', |
| 177 |
values => [1,2,3], |
| 178 |
options => ['foo', 'bar', 'none'], |
| 179 |
} |
| 180 |
|
| 181 |
=head1 DESCRIPTION |
| 182 |
|
| 183 |
Used to create an checkboxes control inside an Embperl Form. |
| 184 |
See Embperl::Form on how to specify parameters. |
| 185 |
|
| 186 |
=head2 PARAMETER |
| 187 |
|
| 188 |
=head3 type |
| 189 |
|
| 190 |
Needs to be 'checkboxes' |
| 191 |
|
| 192 |
=head3 name |
| 193 |
|
| 194 |
Specifies the name of the checkboxes control |
| 195 |
|
| 196 |
=head3 text |
| 197 |
|
| 198 |
Will be used as label for the checkboxes control |
| 199 |
|
| 200 |
=head3 values |
| 201 |
|
| 202 |
Gives the values as an array ref of the checkboxes control. |
| 203 |
|
| 204 |
=head3 options |
| 205 |
|
| 206 |
Gives the options as an array ref that should be displayed to the user. |
| 207 |
If no options are given, the values from values are used. |
| 208 |
|
| 209 |
=head3 vert |
| 210 |
|
| 211 |
If specified arranges the checkboxes button vertically. The number given specifies |
| 212 |
the number of <br>'s used the separate the checkboxes buttons. |
| 213 |
|
| 214 |
=head3 tab |
| 215 |
|
| 216 |
if specified arranges the checkboxes in a table. The number given |
| 217 |
specifies the number of columns in one table row. |
| 218 |
|
| 219 |
=head3 addtop |
| 220 |
|
| 221 |
Array ref which contains items that should be added at the left or top |
| 222 |
of the checkboxes buttons. Each item consists of an array ref with two |
| 223 |
entries, the first is the value and the second is the option |
| 224 |
that is displayed on the page. If the second is missing the |
| 225 |
value (first entry)is displayed. Example: |
| 226 |
|
| 227 |
addtop => [ [1 => 'first item'], [2 => 'second item']] |
| 228 |
|
| 229 |
=head3 addbottom |
| 230 |
|
| 231 |
Array ref which contains items that should be added at the right or bottom |
| 232 |
of the checkboxes buttons. Each item consists of an array ref with two |
| 233 |
entries, the first is the value and the second is the option |
| 234 |
that is displayed on the page. If the second is missing the |
| 235 |
value (first entry)is displayed. Example: |
| 236 |
|
| 237 |
addbottom => [ [9999 => 'last item'], [9999 => 'very last item']] |
| 238 |
|
| 239 |
=head3 filter |
| 240 |
|
| 241 |
If given, only items where the value matches the regex given in |
| 242 |
C<filter> are displayed. |
| 243 |
|
| 244 |
=head1 Author |
| 245 |
|
| 246 |
G. Richter (richter at embperl dot org) |
| 247 |
|
| 248 |
=head1 See Also |
| 249 |
|
| 250 |
perl(1), Embperl, Embperl::Form |
| 251 |
|
| 252 |
|