| 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::selectdyn ; |
| 19 |
|
| 20 |
use strict ; |
| 21 |
use vars qw{%fdat} ; |
| 22 |
use base 'Embperl::Form::ControlMultValue' ; |
| 23 |
|
| 24 |
use Embperl::Inline ; |
| 25 |
|
| 26 |
# ------------------------------------------------------------------------------------------ |
| 27 |
|
| 28 |
sub get_std_control_attr |
| 29 |
{ |
| 30 |
my ($self, $req, $id, $type, $addclass) = @_ ; |
| 31 |
|
| 32 |
if ($type eq 'readonly') |
| 33 |
{ |
| 34 |
$id = $req -> {uuid} . '_' . $self -> {name} ; |
| 35 |
my $url = $self -> {showurl} ; |
| 36 |
$url =~ s/<id>/$self -> get_id_from_value ($Embperl::fdat{$self -> {name}})/e ; |
| 37 |
my $attr = $self -> SUPER::get_std_control_attr ($req, $id, $type, 'ef-control-selectdyn-readonly') ; |
| 38 |
return $attr . qq{ onDblClick="\$('#$self->{use_ajax}').ef_document ('load', '$url');"} ; |
| 39 |
} |
| 40 |
|
| 41 |
return $self -> SUPER::get_std_control_attr ($req, $id, $type, $addclass) ; |
| 42 |
} |
| 43 |
|
| 44 |
# ------------------------------------------------------------------------------------------ |
| 45 |
# |
| 46 |
# init_data - daten aufteilen |
| 47 |
# |
| 48 |
|
| 49 |
sub init_data |
| 50 |
{ |
| 51 |
my ($self, $req) = @_ ; |
| 52 |
|
| 53 |
my $val = $self -> get_value ($req) ; |
| 54 |
if ($val ne '') |
| 55 |
{ |
| 56 |
my $name = $self -> {name} ; |
| 57 |
my $fdat = $req -> {docdata} || \%Embperl::fdat ; |
| 58 |
$fdat -> {'_opt_' . $name} = $self -> get_option_from_value ($val, $req) ; |
| 59 |
$fdat -> {'_id_' . $name} = $self -> get_id_from_value ($val, $req) ; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
# ------------------------------------------------------------------------------------------ |
| 64 |
# |
| 65 |
# prepare_fdat - daten zusammenfuehren |
| 66 |
# |
| 67 |
|
| 68 |
sub prepare_fdat |
| 69 |
{ |
| 70 |
my ($self, $req) = @_ ; |
| 71 |
|
| 72 |
return if ($self -> is_readonly ($req)) ; |
| 73 |
|
| 74 |
my $fdat = $req -> {form} || \%fdat ; |
| 75 |
my $name = $self->{name} ; |
| 76 |
$fdat -> {$name} = '' if (exists ($fdat -> {"_opt_$name"}) && $fdat -> {"_opt_$name"} eq '') ; |
| 77 |
delete $fdat -> {"_opt_$name"} ; |
| 78 |
delete $fdat -> {"_id_$name"} ; |
| 79 |
} |
| 80 |
|
| 81 |
# --------------------------------------------------------------------------- |
| 82 |
|
| 83 |
sub show_control_addons |
| 84 |
{ |
| 85 |
my ($self, $req) = @_ ; |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
1 ; |
| 91 |
|
| 92 |
__EMBPERL__ |
| 93 |
|
| 94 |
|
| 95 |
[# --------------------------------------------------------------------------- |
| 96 |
# |
| 97 |
# show_control - output the control |
| 98 |
#] |
| 99 |
|
| 100 |
[$ sub show_control ($self, $req, $filter) |
| 101 |
|
| 102 |
my $name = $self -> {name} ; |
| 103 |
my $class = $self -> {class} ; |
| 104 |
$] |
| 105 |
|
| 106 |
<input name="_opt_[+ $name +]" [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req) } +] |
| 107 |
type="text" _ef_attach="ef_selectdyn" |
| 108 |
[$if $self -> {size} $]size="[+ $self->{size} +]" [$endif$] |
| 109 |
[$if $self -> {showurl} $]_ef_show_url="[+ $self -> {showurl} +]" [$endif$] |
| 110 |
[$if $self -> {popupurl} $]_ef_popup_url="[+ $self -> {popupurl} +]" [$endif$] |
| 111 |
[$if $self -> {datasrcurl} $]_ef_datasrc_url="[+ $self -> {datasrcurl} +]" [$endif$] |
| 112 |
[$if $self -> {datasrc} $]_ef_datasrc_nam="[+ $self -> {datasrc} +]" [$endif$] |
| 113 |
[$if $self -> {datasrctermmax} $]_ef_datasrc_term_max="[+ $self -> {datasrctermmax} +]" [$endif$] |
| 114 |
[$if $self -> {use_ajax} $]_ef_use_ajax="[+ $self -> {use_ajax} +]" [$endif$] |
| 115 |
[$if $self -> {show_on_select} $]_ef_show_on_select="[+ $self -> {show_on_select}?'1':'' +]" [$endif$] |
| 116 |
> |
| 117 |
<input type="hidden" name="[+ $name +]"> |
| 118 |
<input type="hidden" name="_id_[+ $name +]"> |
| 119 |
[$endsub$] |
| 120 |
|
| 121 |
|
| 122 |
__END__ |
| 123 |
|
| 124 |
=pod |
| 125 |
|
| 126 |
=head1 NAME |
| 127 |
|
| 128 |
Embperl::Form::Control::selectdyn - A dynamic select control inside an Embperl Form |
| 129 |
|
| 130 |
|
| 131 |
=head1 SYNOPSIS |
| 132 |
|
| 133 |
{ |
| 134 |
type => 'selectdyn', |
| 135 |
text => 'blabla', |
| 136 |
name => 'foo', |
| 137 |
values => [1,2,3], |
| 138 |
options => ['foo', 'bar', 'none'], |
| 139 |
rows => 5 |
| 140 |
} |
| 141 |
|
| 142 |
=head1 DESCRIPTION |
| 143 |
|
| 144 |
Used to create an select control inside an Embperl Form. |
| 145 |
See Embperl::Form on how to specify parameters. |
| 146 |
|
| 147 |
=head2 PARAMETER |
| 148 |
|
| 149 |
=head3 type |
| 150 |
|
| 151 |
Needs to be 'select' |
| 152 |
|
| 153 |
=head3 name |
| 154 |
|
| 155 |
Specifies the name of the select control |
| 156 |
|
| 157 |
=head3 text |
| 158 |
|
| 159 |
Will be used as label for the select control |
| 160 |
|
| 161 |
=head3 values |
| 162 |
|
| 163 |
Gives the values as an array ref of the select control. |
| 164 |
|
| 165 |
=head3 options |
| 166 |
|
| 167 |
Gives the options as an array ref that should be displayed to the user. |
| 168 |
If no options are given, the values from values are used. |
| 169 |
|
| 170 |
=head3 rows |
| 171 |
|
| 172 |
If specified a select box is display with the given number of lines. |
| 173 |
If not specified or undef, a drop down list is shown. |
| 174 |
|
| 175 |
=head3 addtop |
| 176 |
|
| 177 |
Array ref which contains items that should be added at the top |
| 178 |
of the select box. Each item consists of an array ref with two |
| 179 |
entries, the first is the value and the second is the option |
| 180 |
that is displayed on the page. If the second is missing the |
| 181 |
value (first entry)is displayed. Example: |
| 182 |
|
| 183 |
addtop => [ [1 => 'first item'], [2 => 'second item']] |
| 184 |
|
| 185 |
=head3 addbottom |
| 186 |
|
| 187 |
Array ref which contains items that should be added at the bottom |
| 188 |
of the select box. Each item consists of an array ref with two |
| 189 |
entries, the first is the value and the second is the option |
| 190 |
that is displayed on the page. If the second is missing the |
| 191 |
value (first entry)is displayed. Example: |
| 192 |
|
| 193 |
addbottom => [ [9999 => 'last item'], [9999 => 'very last item']] |
| 194 |
|
| 195 |
=head3 filter |
| 196 |
|
| 197 |
If given, only items where the value matches the regex given in |
| 198 |
C<filter> are displayed. |
| 199 |
|
| 200 |
=head3 showurl |
| 201 |
|
| 202 |
This URL will be requested if the user clicks on SHOW in the popup or |
| 203 |
double clicks the control. The value of the selected option will be |
| 204 |
appended to that url. Should be something like '/foo/bar.epl?id='. |
| 205 |
NOTE: This URL is not encoded in anyway, so make sure it is properly |
| 206 |
url encoded. |
| 207 |
|
| 208 |
=head3 datasrcurl |
| 209 |
|
| 210 |
This URL will be requested when the user types any input to request |
| 211 |
the data for the control. The characters the users has typed will be |
| 212 |
passed by the parameter query and the name of the datasrc attribute |
| 213 |
will be passed in the datasrc parameter. |
| 214 |
NOTE: This URL is not encoded in anyway, so make sure it is properly |
| 215 |
url encoded. |
| 216 |
|
| 217 |
=head3 show_on_select |
| 218 |
|
| 219 |
If true show the selected item as soon as it is selected (useses showurl) |
| 220 |
|
| 221 |
=head3 use_ajax |
| 222 |
|
| 223 |
If set to an id of an html element, documents that are loaded via showurl |
| 224 |
are fetch via ajax into this html container, instead of fetching a whole page. |
| 225 |
|
| 226 |
=head3 $fdat{-init-<name>} |
| 227 |
|
| 228 |
If set this value is used to prefill the input box, if not set get_values |
| 229 |
method of the datasource object is call, which might be take a long time |
| 230 |
in case of many options. |
| 231 |
|
| 232 |
|
| 233 |
=head1 Author |
| 234 |
|
| 235 |
G. Richter (richter at embperl dot org) |
| 236 |
|
| 237 |
=head1 See Also |
| 238 |
|
| 239 |
perl(1), Embperl, Embperl::Form |
| 240 |
|
| 241 |
|