| 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::button ; |
| 19 |
|
| 20 |
use strict ; |
| 21 |
use base 'Embperl::Form::Control' ; |
| 22 |
|
| 23 |
use Embperl::Inline ; |
| 24 |
|
| 25 |
1 ; |
| 26 |
|
| 27 |
__EMBPERL__ |
| 28 |
|
| 29 |
[# --------------------------------------------------------------------------- |
| 30 |
# |
| 31 |
# show - output the control |
| 32 |
#] |
| 33 |
|
| 34 |
[$ sub show ($self, $req) |
| 35 |
|
| 36 |
my $span = ($self->{width_percent}) ; |
| 37 |
$self->{button} ||= [{}] ; |
| 38 |
my $state = $self -> {state} ; |
| 39 |
$]<table class="ef-element ef-element-width-[+ $self -> {width_percent} +] ef-element-[+ $self -> {type} +] [+ $self -> {state} +]"> |
| 40 |
<tr> <td class="ui-label-box" > |
| 41 |
[$ foreach my $button (@{$self->{button}}) $] |
| 42 |
[$if $self -> {symbol} $] |
| 43 |
<div class="cControlButtonDiv" |
| 44 |
title="[+ $self -> {showtext}?($self->{text}):$self -> form -> convert_label ($self, undef, undef, $req) +]" |
| 45 |
[$if $self -> {onclick} $] onClick="[+ do { local $escmode = 0 ; $self -> {onclick} } +]" [$endif$] |
| 46 |
[+ do { local $escmode = 0 ; $self -> {eventattrs} } +]><img class="cControlButtonSymbol" src="[+ $self -> {symbol} +]"> |
| 47 |
[+ $self -> {showvalue}?($self -> {value} || $self->{text}):$self -> form -> convert_label ($self, undef, undef, $req) +] |
| 48 |
</div> |
| 49 |
[$else$] |
| 50 |
[# Workaround around segfault in Embperl 2.1.1-dev *grmpf* #] |
| 51 |
<[# #]input |
| 52 |
class="cBase cControl cControlButton" name="[+ $self->{name} +]" |
| 53 |
value="[+ $self -> {showvalue}?($self -> {value} || $self->{text}):$self -> form -> convert_label ($self, undef, undef, $req) +]" |
| 54 |
title="[+ $self -> {showtext}?($self->{text}):$self -> form -> convert_label ($self, undef, undef, $req) +]" |
| 55 |
[$if $self -> {onclick} $] onClick="[+ do { local $escmode = 0 ; $self -> {onclick} } +]" [$endif$] |
| 56 |
[+ do { local $escmode = 0 ; $self -> {eventattrs} } +] |
| 57 |
[$if $self -> {image} $] |
| 58 |
type="image" src="[+ $self -> {image} +]" |
| 59 |
[$else$] |
| 60 |
type="button" |
| 61 |
[$endif$] |
| 62 |
style="[+ $self->{style} || 'text-align: center;' +]" |
| 63 |
[# onMouseOver="buttonover(this);" onMouseOut="buttonout(this);" #] |
| 64 |
[$ foreach my $attr (keys %$button) $] |
| 65 |
[$ if exists $button->{"__$attr".'_escmode'} $] |
| 66 |
[+ $attr +]="[+ do { local $escmode = int $button->{"__${attr}_escmode"}; $button->{$attr}; } +]" |
| 67 |
[$ else $] |
| 68 |
[+ $attr +]="[+ $button->{$attr} +]" |
| 69 |
[$ endif $] |
| 70 |
[$ endforeach $]> |
| 71 |
[$endif$] |
| 72 |
[$ endforeach $] |
| 73 |
|
| 74 |
</td></tr> |
| 75 |
</table>[$endsub$] |
| 76 |
|
| 77 |
__END__ |
| 78 |
|
| 79 |
=pod |
| 80 |
|
| 81 |
=head1 NAME |
| 82 |
|
| 83 |
Embperl::Form::Control::submit - A button inside an Embperl Form |
| 84 |
|
| 85 |
|
| 86 |
=head1 SYNOPSIS |
| 87 |
|
| 88 |
{ |
| 89 |
type => 'submit', |
| 90 |
text => 'send', |
| 91 |
name => 'foo', |
| 92 |
value => 'xxx', |
| 93 |
image => 'xxx', |
| 94 |
onclick => 'window.open (...)', |
| 95 |
|
| 96 |
button => [ |
| 97 |
{ |
| 98 |
onclick => 'do_something()', |
| 99 |
style => 'border: 1px solid black;', |
| 100 |
}, |
| 101 |
{ |
| 102 |
name => 'foobar', |
| 103 |
value => 'Click here, too', |
| 104 |
onclick => 'do_something()', |
| 105 |
class => 'HurzCSSClass', |
| 106 |
onmouseover => 'do(this)'; |
| 107 |
onmouseout => 'do(that)'; |
| 108 |
} |
| 109 |
] |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
=head1 DESCRIPTION |
| 114 |
|
| 115 |
Used to create an submit control inside an Embperl Form. |
| 116 |
If an image is given it will create an image button. |
| 117 |
See Embperl::Form on how to specify parameters. |
| 118 |
|
| 119 |
=head2 PARAMETER |
| 120 |
|
| 121 |
=head3 type |
| 122 |
|
| 123 |
Needs to be 'button' |
| 124 |
|
| 125 |
=head3 name |
| 126 |
|
| 127 |
Name of the button |
| 128 |
|
| 129 |
=head3 text |
| 130 |
|
| 131 |
Will be used as label for the submit button or tool tip |
| 132 |
in case of an image button |
| 133 |
|
| 134 |
=head3 value |
| 135 |
|
| 136 |
Gives the value to send |
| 137 |
|
| 138 |
=head3 image |
| 139 |
|
| 140 |
URL of an image. If given an image button will be created, |
| 141 |
if absent, an normal submit button will be created. |
| 142 |
|
| 143 |
=head3 onclick |
| 144 |
|
| 145 |
Javascript that should be executed when the users clicks on the button. |
| 146 |
|
| 147 |
=head3 button |
| 148 |
|
| 149 |
hashref of the key-value pairs of all attribute the button needs. |
| 150 |
|
| 151 |
=head1 Author |
| 152 |
|
| 153 |
G. Richter (richter at embperl dot org), A. Beckert ([email protected]) |
| 154 |
|
| 155 |
=head1 See Also |
| 156 |
|
| 157 |
perl(1), Embperl, Embperl::Form |
| 158 |
|
| 159 |
|