| 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::display ; |
| 19 |
|
| 20 |
use strict ; |
| 21 |
use base 'Embperl::Form::Control' ; |
| 22 |
|
| 23 |
use Embperl::Inline ; |
| 24 |
|
| 25 |
use vars qw{%fdat} ; |
| 26 |
|
| 27 |
|
| 28 |
# ------------------------------------------------------------------------------------------ |
| 29 |
# |
| 30 |
# init_data - daten aufteilen |
| 31 |
# |
| 32 |
|
| 33 |
sub init_data |
| 34 |
{ |
| 35 |
my ($self, $req, $parentctrl) = @_ ; |
| 36 |
|
| 37 |
return if (!$self -> {value2text}) ; |
| 38 |
|
| 39 |
|
| 40 |
my $fdat = $req -> {docdata} || \%fdat ; |
| 41 |
my $name = $self->{name} ; |
| 42 |
my $value = $fdat->{$name} ; |
| 43 |
|
| 44 |
my $val ; |
| 45 |
my $txt ; |
| 46 |
if (ref $value eq 'ARRAY') |
| 47 |
{ |
| 48 |
foreach (@$value) |
| 49 |
{ |
| 50 |
$val = $self -> {value2text} . $_ ; |
| 51 |
$txt = $self -> form -> convert_text ($self, $val, undef, $req) ; |
| 52 |
$_ = $txt if ($txt ne $val) ; |
| 53 |
} |
| 54 |
} |
| 55 |
else |
| 56 |
{ |
| 57 |
$val = $self -> {value2text} . $value ; |
| 58 |
$txt = $self -> form -> convert_text ($self, $val, undef, $req) ; |
| 59 |
$fdat->{$name} = $txt if ($txt ne $val) ; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
# ------------------------------------------------------------------------------------------ |
| 64 |
|
| 65 |
|
| 66 |
sub show_control_readonly { $_[0] -> show_control ($_[1], $_[2]) } |
| 67 |
|
| 68 |
|
| 69 |
1 ; |
| 70 |
|
| 71 |
__EMBPERL__ |
| 72 |
|
| 73 |
[# --------------------------------------------------------------------------- |
| 74 |
# |
| 75 |
# show_control - output the control |
| 76 |
#] |
| 77 |
|
| 78 |
[$ sub show_control ($self, $req, $value) |
| 79 |
my $name = $self->{name}; |
| 80 |
my $id = $self->{id}; |
| 81 |
$value = exists $self->{value} ? $self->{value} : $fdat{$name} if (!defined ($value)) ; |
| 82 |
$value = [ split /\t/, $value ] if $self->{split}; |
| 83 |
$value = [ split /\n/, $value ] if $self->{splitlines}; |
| 84 |
|
| 85 |
$]<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, '', 'readonly') } +] _ef_divname="[+$name+]">[$ if ref $value eq 'ARRAY' $][$ foreach $v (@$value) $][+ $v +]<br />[$ endforeach |
| 86 |
$][$ elsif ref $value eq 'HASH' $][$ foreach $k (keys %$value) $][+ $k +]: [+ $value->{$k} +]<br />[$ endforeach |
| 87 |
$][$ elsif ref $value $]<em>[+ ref $value +]</em>[$ |
| 88 |
else $][+ $value +][$ endif $]</div> |
| 89 |
|
| 90 |
[$ if $self->{hidden} $] |
| 91 |
<input type="hidden" name="[+ $name +]" value="[+ $value +]"> |
| 92 |
[$endif$] |
| 93 |
[$endsub$] |
| 94 |
|
| 95 |
__END__ |
| 96 |
|
| 97 |
=pod |
| 98 |
|
| 99 |
=head1 NAME |
| 100 |
|
| 101 |
Embperl::Form::Control::display - A text display control inside an Embperl Form |
| 102 |
|
| 103 |
|
| 104 |
=head1 SYNOPSIS |
| 105 |
|
| 106 |
{ |
| 107 |
type => 'display', |
| 108 |
text => 'blabla', |
| 109 |
hidden => 1, |
| 110 |
name => 'foo', |
| 111 |
split => 1 |
| 112 |
} |
| 113 |
|
| 114 |
=head1 DESCRIPTION |
| 115 |
|
| 116 |
Used to create a display only control inside an Embperl Form. |
| 117 |
See Embperl::Form on how to specify parameters. |
| 118 |
|
| 119 |
=head2 PARAMETER |
| 120 |
|
| 121 |
=head3 type |
| 122 |
|
| 123 |
Needs to be set to 'display'. |
| 124 |
|
| 125 |
=head3 text |
| 126 |
|
| 127 |
Will be used as label for the text display control. |
| 128 |
|
| 129 |
=head3 value |
| 130 |
|
| 131 |
value to display. If not given $fdat{<name>} will be used. |
| 132 |
If the data given within value is an arrayref, every element will be displayed |
| 133 |
on a separate line. |
| 134 |
|
| 135 |
=head3 hidden |
| 136 |
|
| 137 |
If set, an appropriate hidden input field will be created |
| 138 |
automatically. |
| 139 |
|
| 140 |
=head3 name |
| 141 |
|
| 142 |
Will be used as name for the hidden input field. |
| 143 |
|
| 144 |
=head3 split |
| 145 |
|
| 146 |
Splits the value into an array at \t if set and displays every array element |
| 147 |
on a new line. |
| 148 |
|
| 149 |
=head3 splitlines |
| 150 |
|
| 151 |
Splits the value into an array at \n if set and displays every array element |
| 152 |
on a new line. |
| 153 |
|
| 154 |
=head3 value2text |
| 155 |
|
| 156 |
Will run the value prefixed with the given paramenter through convert_text, |
| 157 |
so it can be translated. |
| 158 |
|
| 159 |
=head1 Author |
| 160 |
|
| 161 |
G. Richter (richter at embperl dot org), A. Beckert ([email protected]) |
| 162 |
|
| 163 |
=head1 See Also |
| 164 |
|
| 165 |
perl(1), Embperl, Embperl::Form |
| 166 |
|
| 167 |
|