################################################################################### # # Embperl - Copyright (c) 1997-2010 Gerald Richter / ecos gmbh www.ecos.de # # 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::tabs ; use strict ; use vars qw{%fdat} ; use Embperl::Form::ControlMultValue ; use base 'Embperl::Form::ControlMultValue' ; use Embperl::Inline ; # --------------------------------------------------------------------------- # # new - create a new control # sub new { my ($class, $args) = @_ ; my $self = Embperl::Form::ControlMultValue -> new($args) ; bless $self, $class ; $self -> {width} = 1 ; $self -> {nameprefix} ||= 'tab:' ; return $self ; } # --------------------------------------------------------------------------- # # noframe - do not draw frame border if this is the first control # sub noframe { return 1 ; } # --------------------------------------------------------------------------- # # get_active_id - get the id of the value which is currently active # sub get_active_id { my ($self, $req) = @_ ; my ($values, $options) = $self -> get_values ($req) ; my $name = $self -> {name} ; my $dataval = $fdat{$name} || $values -> [0] ; my $activeid ; my $i = 0 ; foreach my $val (@$values) { if ($val eq $dataval || $self -> {subids}[$i] eq $dataval) { $activeid = $self -> {subids}[$i] ; last ; } $i++ ; } return $activeid || $self -> {subids}[0]; } 1 ; __EMBPERL__ [# --------------------------------------------------------------------------- # # show - output the control #] [$ sub show ($self) my ($values, $options) = $self -> get_values ; my $span = ($self->{width_percent}) ; my $name = $self -> {name} ; my $dataval = $fdat{$name} || $values -> [0] ; my $activeid = $self -> get_active_id ; my $nsprefix = $self -> form -> {jsnamespace} ; my $tabs_per_line = $self -> {'tabs_per_line'} || 99; $tabs_per_line = [$tabs_per_line, $tabs_per_line, $tabs_per_line, $tabs_per_line] if (!ref $tabs_per_line) ; my $val ; my $i = 0 ; my $more = 1 ; my $start_i = 0 ; my $line = 0 ; $]
| [* $i++ ; if ($i - $start_i >= $tabs && @$values > $i) { $more = 1 ; $start_i = $i ; last ; } *] [$endwhile $] [$if ($i == @$values) $] | [$endif$] |