Embperl
view release on metacpan or search on metacpan
Embperl/Form/Control/checkboxes.pm view on Meta::CPAN
###################################################################################
#
# Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
# Embperl - Copyright (c) 2008-2015 Gerald Richter
# Embperl - Copyright (c) 2015-2023 actevy.io
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the Perl README file.
#
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# $Id$
#
###################################################################################
package Embperl::Form::Control::checkboxes ;
use strict ;
use vars qw{%fdat} ;
use base 'Embperl::Form::ControlMultValue' ;
use Embperl::Inline ;
use URI::Escape ;
# ---------------------------------------------------------------------------
#
# show_control_readonly - output readonly control
#
sub xshow_control_readonly
{
my ($self, $req) = @_ ;
my $name = $self -> {name} ;
my @values = split (/\t/, $fdat{$name}) ;
$self -> show_control ($req, "^(?:" . join ('|', map { "\Q$_\E" } @values) . ")\$") ;
}
# ---------------------------------------------------------------------------
sub show_control_addons
{
my ($self, $req) = @_ ;
}
# ------------------------------------------------------------------------------------------
#
# init_data - daten aufteilen
#
sub init_data
{
my ($self, $req) = @_ ;
my $fdat = $req -> {docdata} || \%fdat ;
my $name = $self->{name} ;
if (ref $fdat -> {$name})
{
$fdat -> {$name} = join ("\t", @{$fdat -> {$name}}) ;
}
}
# ------------------------------------------------------------------------------------------
#
# prepare_fdat - daten zusammenfuehren
#
sub prepare_fdat
{
my ($self, $req) = @_ ;
return if ($self -> is_readonly ($req)) ;
my $fdat = $req -> {form} || \%fdat ;
my $name = $self->{name} ;
if (exists $req -> {body})
{
# handle multiple checkboxes inside a grid
my $postdata = $req -> {body} ;
$name = uri_escape($name) ;
my $data = [ map { uri_unescape($_) } ($postdata =~ /\Q$name\E=(.*?)&/g) ] ;
my %attrs = map { ($_ => 1) } split /\s+/, $fdat -> {-fields2empty} ;
$fdat -> {$name} = $data if ($attrs{$name} || @$data > 0) ;
}
}
1 ;
__EMBPERL__
[# ---------------------------------------------------------------------------
#
# show_control - output the control
#]
[$ sub show_control ($self, $req, $filter)
my $name = $self -> {name} ;
$filter ||= $self -> {filter} ;
my $val ;
my $i = 0 ;
my ($values, $options) = $self -> get_all_values ($req) ;
my ($ctlattrs, $ctlid, $ctlname) = $self -> get_std_control_attr($req) ;
my $tab = $self -> {tab} ;
push @{$self -> form -> {fields2empty}}, $name ;
$]
[$if $tab $]<[# #]table style="width: 100%">[$ endif $]
[* $i = 0 ; *]
[$ foreach $val (@$values) $]
[$if !defined ($filter) || ($val =~ /$filter/i) $]
[$ if $tab $][$ if $colcnt == 0 $]<[# #]tr>[- $colcnt = $tab -][$endif$]<td style="width: 3%">[$endif$]
( run in 0.493 second using v1.01-cache-2.11-cpan-39bf76dae61 )