| 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::checkboxes ; | ||
| 20 | |||
| 21 | use strict ; | ||
| 22 | use vars qw{%fdat} ; | ||
| 23 | use base 'Embperl::Form::ControlMultValue' ; | ||
| 24 | |||
| 25 | use Embperl::Inline ; | ||
| 26 | use URI::Escape ; | ||
| 27 | |||
| 28 | # --------------------------------------------------------------------------- | ||
| 29 | # | ||
| 30 | # show_control_readonly - output readonly control | ||
| 31 | # | ||
| 32 | |||
| 33 | sub xshow_control_readonly | ||
| 34 | { | ||
| 35 | my ($self, $req) = @_ ; | ||
| 36 | |||
| 37 | my $name = $self -> {name} ; | ||
| 38 | my @values = split (/\t/, $fdat{$name}) ; | ||
| 39 | $self -> show_control ($req, "^(?:" . join ('|', map { "\Q$_\E" } @values) . ")\$") ; | ||
| 40 | } | ||
| 41 | |||
| 42 | # --------------------------------------------------------------------------- | ||
| 43 | |||
| 44 | sub show_control_addons | ||
| 45 | { | ||
| 46 | my ($self, $req) = @_ ; | ||
| 47 | |||
| 48 | } | ||
| 49 | |||
| 50 | # ------------------------------------------------------------------------------------------ | ||
| 51 | # | ||
| 52 | # init_data - daten aufteilen | ||
| 53 | # | ||
| 54 | |||
| 55 | sub init_data | ||
| 56 | { | ||
| 57 | my ($self, $req) = @_ ; | ||
| 58 | |||
| 59 | my $fdat = $req -> {docdata} || \%fdat ; | ||
| 60 | my $name = $self->{name} ; | ||
| 61 | if (ref $fdat -> {$name}) | ||
| 62 | { | ||
| 63 | $fdat -> {$name} = join ("\t", @{$fdat -> {$name}}) ; | ||
| 64 | } | ||
| 65 | |||
| 66 | } | ||
| 67 | |||
| 68 | # ------------------------------------------------------------------------------------------ | ||
| 69 | # | ||
| 70 | # prepare_fdat - daten zusammenfuehren | ||
| 71 | # | ||
| 72 | |||
| 73 | sub prepare_fdat | ||
| 74 | { | ||
| 75 | my ($self, $req) = @_ ; | ||
| 76 | |||
| 77 | return if ($self -> is_readonly ($req)) ; | ||
| 78 | |||
| 79 | my $fdat = $req -> {form} || \%fdat ; | ||
| 80 | my $name = $self->{name} ; | ||
| 81 | if (exists $req -> {body}) | ||
| 82 | { | ||
| 83 | # handle multiple checkboxes inside a grid | ||
| 84 | my $postdata = $req -> {body} ; | ||
| 85 | $name = uri_escape($name) ; | ||
| 86 | my $data = [ map { uri_unescape($_) } ($postdata =~ /\Q$name\E=(.*?)&/g) ] ; | ||
| 87 | |||
| 88 | my %attrs = map { ($_ => 1) } split /\s+/, $fdat -> {-fields2empty} ; | ||
| 89 | $fdat -> {$name} = $data if ($attrs{$name} || @$data > 0) ; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | } | ||
| 94 | 1 ; | ||
| 95 | |||
| 96 | __EMBPERL__ | ||
| 97 | |||
| 98 | [# --------------------------------------------------------------------------- | ||
| 99 | # | ||
| 100 | # show_control - output the control | ||
| 101 | #] | ||
| 102 | |||
| 103 | [$ sub show_control ($self, $req, $filter) | ||
| 104 | |||
| 105 | my $name = $self -> {name} ; | ||
| 106 | $filter ||= $self -> {filter} ; | ||
| 107 | my $val ; | ||
| 108 | my $i = 0 ; | ||
| 109 | my ($values, $options) = $self -> get_all_values ($req) ; | ||
| 110 | my ($ctlattrs, $ctlid, $ctlname) = $self -> get_std_control_attr($req) ; | ||
| 111 | my $tab = $self -> {tab} ; | ||
| 112 | push @{$self -> form -> {fields2empty}}, $name ; | ||
| 113 | |||
| 114 | $] | ||
| 115 | [$if $tab $]<[# #]table style="width: 100%">[$ endif $] | ||
| 116 | [* $i = 0 ; *] | ||
| 117 | [$ foreach $val (@$values) $] | ||
| 118 | [$if !defined ($filter) || ($val =~ /$filter/i) $] | ||
| 119 | [$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td style="width: 3%">[$endif$] | ||
| 120 | <input type="checkbox" name="[+ $name +]" value="[+ $val +]" [+ do { local $escmode = 0 ; $ctlattrs } +] | ||
| 121 | [$if ($self -> {trigger}) $]_ef_attach="ef_checkbox"[$endif$] > | ||
| 122 | [$ if $tab $]</td><td style="width: [+ int((100 - ($tab * 3)) / $tab) +]%">[$endif$] | ||
| 123 | <span class="ef-control-checkboxes-text">[+ $options ->[$i] || $val +]</span> | ||
| 124 | [- $vert = $self -> {vert} -][$while $vert-- > 0 $]<br/>[$endwhile$] | ||
| 125 | [$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] | ||
| 126 | [$endif$] | ||
| 127 | [* $i++ ; *] | ||
| 128 | [$endforeach$] | ||
| 129 | [$if $tab $]<[# #]/table>[$ endif $] | ||
| 130 | [$endsub$] | ||
| 131 | |||
| 132 | |||
| 133 | [$ sub xxshow_control ($self, $req, $filter) | ||
| 134 | |||
| 135 | my ($values, $options) = $self -> get_values ($req) ; | ||
| 136 | my $name = $self -> {name} ; | ||
| 137 | $filter ||= $self -> {filter} ; | ||
| 138 | my $addtop = $self -> {addtop} || [] ; | ||
| 139 | my $addbottom= $self -> {addbottom} || [] ; | ||
| 140 | my $max = @$values ; | ||
| 141 | my $set = !defined ($fdat{$name})?1:0 ; | ||
| 142 | my $tab = $self -> {tab} ; | ||
| 143 | my $colcnt = 0 ; | ||
| 144 | push @{$self -> form -> {fields2empty}}, $name ; | ||
| 145 | |||
| 146 | my $val ; | ||
| 147 | my $i = 0 ; | ||
| 148 | $] | ||
| 149 | [$if $tab $]<[# #]table width=100% style="width: 100%" >[$ endif $] | ||
| 150 | [$ foreach $val (@$addtop) $] | ||
| 151 | [$if !defined ($filter) || ($val->[0] =~ /$filter/i) $] | ||
| 152 | [$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td>[$endif$] | ||
| 153 | [#- $fdat{$name} = $val -> [0], $set = 0 if ($set) ; -#] | ||
| 154 | <input type="checkbox" name="[+ $name +]" value="[+ $val -> [0] +]" | ||
| 155 | > | ||
| 156 | [$ if $tab $]</td><td>[$endif$] | ||
| 157 | [+ $val ->[1] || $val -> [0] +] | ||
| 158 | [$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] | ||
| 159 | [$endif$] | ||
| 160 | [$endforeach$] | ||
| 161 | [$ foreach $val (@$values) $] | ||
| 162 | [$if !defined ($filter) || ($val =~ /$filter/i) $] | ||
| 163 | [$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td>[$endif$] | ||
| 164 | [#- $fdat{$name} = $val, $set = 0 if ($set) ; -#] | ||
| 165 | <input type="checkbox" name="[+ $name +]" value="[+ $val +]" | ||
| 166 | [$if ($self -> {sublines} || $self -> {subobjects}) $] OnClick="show_checkboxes_checked(this,[+ $i +],[+ $max +])" [$endif$] | ||
| 167 | > | ||
| 168 | [$ if $tab $]</td><td>[$endif$] | ||
| 169 | [+ $options ->[$i] || $val +] | ||
| 170 | [- $vert = $self -> {vert} -][$while $vert-- > 0 $]<br/>[$endwhile$] | ||
| 171 | [$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] | ||
| 172 | [$endif$] | ||
| 173 | [* $i++ ; *] | ||
| 174 | [$endforeach$] | ||
| 175 | [$ foreach $val (@$addbottom) $] | ||
| 176 | [$if !defined ($filter) || ($val->[0] =~ /$filter/i) $] | ||
| 177 | [$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td>[$endif$] | ||
| 178 | [#- $fdat{$name} = $val -> [0], $set = 0 if ($set) ; -#] | ||
| 179 | <input type="checkbox" name="[+ $name +]" value="[+ $val -> [0] +]" | ||
| 180 | > | ||
| 181 | [$ if $tab $]</td><td>[$endif$] | ||
| 182 | [+ $val ->[1] || $val -> [0] +] | ||
| 183 | [$ if $tab $]</td>[$ if $colcnt-- < 1 $]<[# #]/tr>[$endif$][$endif$] | ||
| 184 | [$endif$] | ||
| 185 | [$endforeach$] | ||
| 186 | [$if $tab $]<[# #]/table>[$ endif $] | ||
| 187 | |||
| 188 | [$endsub$] | ||
| 189 | |||
| 190 | |||
| 191 | |||
| 192 | __END__ |