| 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::displaylink ; |
| 19 |
|
| 20 |
use strict ; |
| 21 |
use base 'Embperl::Form::Control' ; |
| 22 |
|
| 23 |
use Embperl::Inline ; |
| 24 |
|
| 25 |
# --------------------------------------------------------------------------- |
| 26 |
# |
| 27 |
# show_control_readonly - output readonly control |
| 28 |
# |
| 29 |
|
| 30 |
sub show_control_readonly |
| 31 |
{ |
| 32 |
my ($self, $req) = @_ ; |
| 33 |
|
| 34 |
$self -> show_control ($req) ; |
| 35 |
} |
| 36 |
|
| 37 |
1 ; |
| 38 |
|
| 39 |
__EMBPERL__ |
| 40 |
|
| 41 |
[# --------------------------------------------------------------------------- |
| 42 |
# |
| 43 |
# show_control - output the control |
| 44 |
#] |
| 45 |
|
| 46 |
[$ sub show_control ($self, $req) |
| 47 |
|
| 48 |
my $name = $self->{name}; |
| 49 |
my $hrefs = $self -> {href} ; |
| 50 |
my $targets = $self -> {target} ; |
| 51 |
my $opens = $self -> {open} ; |
| 52 |
my $displays = $self -> {link} || $self -> {value} ; |
| 53 |
my $form = $self -> form ; |
| 54 |
my $showoptions = $self -> {showoptions} ; |
| 55 |
my $state = $self -> {state} ; |
| 56 |
|
| 57 |
$hrefs = [$hrefs] if (!ref $hrefs) ; |
| 58 |
$targets = [$targets] if ($targets && !ref $targets) ; |
| 59 |
$opens = [$opens] if ($opens && !ref $opens) ; |
| 60 |
$displays = [$displays] if (!ref $displays) ; |
| 61 |
|
| 62 |
|
| 63 |
@hrefs = map { my $x = $_ ; $x =~ s/%%%name%%%/$epreq->Escape ($fdat{$name},6)/eg ; $x =~ s/%%(.+?)%%/$epreq->Escape ($fdat{$1}, 6)/eg ; $x } ref ($hrefs)?@$hrefs:($hrefs) ; |
| 64 |
@opens = map { my $x = $_ ; $x =~ s/%%%name%%%/$epreq->Escape ($fdat{$name},6)/eg ; $x =~ s/%%(.+?)%%/$epreq->Escape ($fdat{$1}, 6)/eg ; $x } ref ($opens)?@$opens:($opens) ; |
| 65 |
@displays = map { my $x = $_ ; $x =~ s/%%%name%%%/$fdat{$name}/g ; $x =~ s/%%(.+?)%%/$fdat{$1}/eg ; $x } @$displays ; |
| 66 |
|
| 67 |
my $dispn = 0 ; |
| 68 |
$] |
| 69 |
<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, '', 'readonly') } +]> |
| 70 |
[$ foreach $display (@displays) $] |
| 71 |
[$if $opens[$dispn] $] |
| 72 |
<a href="#" class="[+ $state +]" onclick="if (this.className.search('ef-disabled') == -1) [+ $opens[$dispn] +][$if $hrefs[$dispn] $]('[+ $hrefs[$dispn] +]')[$endif$]" [+ do { local $escmode = 0 ; $self -> {eventattrs} } +]> |
| 73 |
[$else$] |
| 74 |
<a href="[+ do {local $escmode=0;$hrefs[$dispn]} +]" class="[+ $state +]" |
| 75 |
[$if $targets -> [$dispn] $]target="[+ $targets -> [$dispn] +]"[$endif$] |
| 76 |
[+ do { local $escmode = 0 ; $self -> {eventattrs} } +]> |
| 77 |
[$endif$][$ if $showoptions < 0 $][+ do { local $escmode = 0 ; $display } +][$else$][+ $showoptions?$display:$form -> convert_text ($self, $display, undef, $req) +][$endif$]</a> |
| 78 |
[- $dispn++ -] |
| 79 |
[$endforeach$] |
| 80 |
</div> |
| 81 |
__END__ |
| 82 |
|
| 83 |
=pod |
| 84 |
|
| 85 |
=head1 NAME |
| 86 |
|
| 87 |
Embperl::Form::Control::displaylink - A control to display links inside an Embperl Form |
| 88 |
|
| 89 |
|
| 90 |
=head1 SYNOPSIS |
| 91 |
|
| 92 |
{ |
| 93 |
type => 'displaylink', |
| 94 |
text => 'blabla', |
| 95 |
link => ['ecos', 'bb5000'], |
| 96 |
href => ['http://www.ecos.de', 'http://www.bb5000.info'] |
| 97 |
} |
| 98 |
|
| 99 |
=head1 DESCRIPTION |
| 100 |
|
| 101 |
Used to create a control which displays links inside an Embperl Form. |
| 102 |
See Embperl::Form on how to specify parameters. |
| 103 |
|
| 104 |
=head2 PARAMETER |
| 105 |
|
| 106 |
=head3 type |
| 107 |
|
| 108 |
Needs to be set to 'displaylink'. |
| 109 |
|
| 110 |
=head3 text |
| 111 |
|
| 112 |
Will be used as label for the text display control. |
| 113 |
|
| 114 |
=head3 link |
| 115 |
|
| 116 |
Arrayref with texts for the links that should be shown to the user |
| 117 |
|
| 118 |
=head3 href |
| 119 |
|
| 120 |
Arrayref with hrefs |
| 121 |
|
| 122 |
%%<name>%% is replaced by $fdat{<name>} |
| 123 |
|
| 124 |
=head3 open |
| 125 |
|
| 126 |
Arrayref, if a value is given for the link, the value will be used as |
| 127 |
javascript function which is executed onclick. href will be pass as |
| 128 |
argument. |
| 129 |
|
| 130 |
%%<name>%% is replaced by $fdat{<name>} |
| 131 |
|
| 132 |
=head3 target |
| 133 |
|
| 134 |
Arrayref with targets |
| 135 |
|
| 136 |
=head3 showtext |
| 137 |
|
| 138 |
If set the texts from the link parameter will not be passed thru convert_text |
| 139 |
|
| 140 |
=head1 Author |
| 141 |
|
| 142 |
G. Richter (richter at embperl dot org) |
| 143 |
|
| 144 |
=head1 See Also |
| 145 |
|
| 146 |
perl(1), Embperl, Embperl::Form |
| 147 |
|
| 148 |
|