################################################################################### # # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de # Embperl - Copyright (c) 2008-2014 Gerald Richter # # 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::mult ; use strict ; use base 'Embperl::Form::Control::grid' ; use vars qw{%fdat $epreq} ; use Embperl::Inline ; # --------------------------------------------------------------------------- # # new - create a new control # sub new { my ($class, $args) = @_ ; my $self = Embperl::Form::ControlMultValue -> new($args) ; bless $self, $class ; $self -> init ; return $self ; } # --------------------------------------------------------------------------- # # init - init the new control # sub init { my ($self) = @_ ; my $form = $self -> form ; $self -> {fields} ||= [$self -> {field}] ; $self -> {class} ||= 'ef-control-mult' ; my $options = $form -> {options} ; $form -> new_controls ($self -> {fields}, $options, undef, undef, $options -> {masks}, $options -> {defaults}, 1) ; return $self ; } # ------------------------------------------------------------------------------------------ # # init_data - daten aufteilen # sub init_data { my ($self, $req) = @_ ; my $fdat = $req -> {docdata} || \%fdat ; my $name = $self->{name} ; my @entries = ref $fdat->{$name} eq 'ARRAY'?@{$fdat->{$name}}:split("\t",$fdat->{$name}); my $field = $self -> {fields}[0] ; my $i = 0 ; foreach my $entry (@entries) { $fdat->{"__${name}__$i"} = $entry ; if ($field -> can ('init_data')) { local $field->{name} = "__${name}__$i" ; local $field -> {fullid} = "$self->{fullid}__$i" ; $field -> init_data ($req, $self) ; } $i++ ; } $fdat->{"__${name}_max"} = $i?$i:1; } # ------------------------------------------------------------------------------------------ # # prepare_fdat - daten zusammenfuehren # sub prepare_fdat { my ($self, $req) = @_ ; my $fdat = $req -> {form} || \%fdat ; my $name = $self->{name} ; my $max = $fdat->{"__${name}_max"} || 1 ; my $field = $self -> {fields}[0] ; my @rows; my $val ; for (my $i = 0; $i < $max; $i++) { if ((ref ($field) =~ /::/) && $field -> can ('prepare_fdat')) { local $field->{name} = "__${name}__$i" ; local $field -> {fullid} = "$self->{fullid}__$i" ; $field -> prepare_fdat ($req) ; } $val = $fdat->{"__${name}__$i"} ; push @rows, $val if ($val ne '') ; } $fdat->{$name} = \@rows if (@rows > 1 || defined ($rows[0]) || $fdat->{"__${name}_max"} > 0) ; foreach my $key (keys %$fdat) { delete $fdat->{$key} if ($key =~ /^__\Q$name\E__/) ; } } # ------------------------------------------------------------------------------------------ # # get_display_text - returns the text that should be displayed # sub get_display_text { my ($self, $req, $value) = @_ ; my $field = $self -> {fields}[0] ; return if (!$field) ; return $field -> get_display_text ($req, $value) ; } # ------------------------------------------------------------------------------------------ sub show { $_[0] -> {fullid} = $_[1] -> {uuid} . '_' . $_[0] -> {id} ; Embperl::Form::Control::show (@_) } #sub show_control_readonly { my $self = shift ; $self -> show_control (@_) } 1 ; __EMBPERL__ [# --------------------------------------------------------------------------- # # show - output the whole control including the label #] [$sub show ($self, $req) $fdat{$self -> {name}} = $self -> {default} if ($fdat{$self -> {name}} eq '' && exists ($self -> {default})) ; my $span = 0 ; $]