2
###################################################################################
4
# Embperl - Copyright (c) 1997-2005 Gerald Richter / ecos gmbh www.ecos.de
6
# You may distribute under the terms of either the GNU General Public
7
# License or the Artistic License, as specified in the Perl README file.
9
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15
###################################################################################
17
package Embperl::Form::Control::mult ;
20
use base 'Embperl::Form::Control::grid' ;
22
use vars qw{%fdat $epreq} ;
26
# ---------------------------------------------------------------------------
28
# new - create a new control
35
my ($class, $args) = @_ ;
37
my $self = Embperl::Form::ControlMultValue -> new($args) ;
45
# ---------------------------------------------------------------------------
47
# init - init the new control
55
my $form = $self -> form ;
56
$self -> {fields} ||= [$self -> {field}] ;
57
$self -> {class} ||= 'cMult' ;
58
$form -> new_controls ($self -> {fields}, $form -> {options}) ;
63
# ------------------------------------------------------------------------------------------
65
# init_data - daten aufteilen
70
my ($self, $req) = @_ ;
72
my $ldap = $req->{ldap};
73
my $name = $self->{name} ;
74
my @entries = split("\t",$fdat{$name});
76
print STDERR 'init_data', Dumper (\%fdat, $name, \@entries) ;
79
foreach my $entry (@entries)
81
$fdat{"$name--$i"} = $entry ;
82
warn "init_data mult field=$name--$i fd=" . $fdat{"$name--$i"} ;
86
$fdat{"$name-max"} = $i?$i:1;
89
# ------------------------------------------------------------------------------------------
91
# prepare_fdat - daten zusammenfuehren
96
my ($self, $req) = @_ ;
97
my $ldap = $req->{ldap};
98
my $name = $self->{name} ;
99
my $max = $fdat{"$name-max"} || 1 ;
100
warn "prepare_dat mult name =$name, max=$max" ;
102
print STDERR Dumper (\%fdat) ;
106
for (my $i = 0; $i < $max; $i++)
108
warn "prepare_dat mult field=$name--$i fd=" . $fdat{"$name--$i"} ;
109
$val = $fdat{"$name--$i"} ;
110
push @rows, $val if ($val ne '') ;
112
$fdat{$name} = \@rows ;
113
print STDERR Dumper (\%fdat, \@rows) ;
116
sub show { Embperl::Form::Control::show (@_) }
123
[# ---------------------------------------------------------------------------
125
# show_control - output the control
128
[$ sub show_control ($self, $req)
130
my $name = $self -> {name} ;
131
my $span = ($self->{width_percent}) ;
132
my $nsprefix = $self -> form -> {jsnamespace} ;
134
$jsname =~ s/[^a-zA-Z0-9]/_/g ;
136
my $max = $fdat{"$name-max"} ;
139
$fdat{$name} = $self -> {default} if ($fdat{$name} eq '' && exists ($self -> {default})) ;
142
<input type="hidden" name="[+ $self -> {name} +]-max" id="[+ $self -> {id} +]-max">
143
<table class="[+ $self -> {class} +]Table cBase" id="[+ $self -> {id} +]">
144
[- $self -> show_grid_table ($req) ; -]
146
<table id="[+ $self -> {id} +]-newrow" style="display: none">
148
local $req -> {epf_no_script} = 1 ;
149
$self -> show_grid_table_row ($req, '%row%') ;
153
[+ $jsname +] = new [+ $nsprefix +]Grid (document.getElementById('[+ $self -> {id} +]'),
154
document.getElementById('[+ $self -> {id} +]-newrow'),
155
document.getElementById('[+ $self -> {id} +]-max')) ;
161
[# ---------------------------------------------------------------------------
163
# show_grid_table_row Erzeugt eine Grid-Tabelle-Zeile
166
[$ sub show_grid_table_row ($self, $req, $i)
168
$field = $self -> {fields}[0] ;
170
$name = $self -> {name} ;
172
$jsname =~ s/[^a-zA-Z0-9]/_/g ;
176
<tr class="cGridRow" id="[+ "$id-row-$i" +]">
178
<td class="[+ $self -> {class} +]Cell">
180
local $field -> {name} = "$name--$i" ;
181
$field -> show_control ($req)
188
[$ sub show_label_icon ($self)
189
$name = $self -> {name} ;
191
$jsname =~ s/[^a-zA-Z0-9]/_/g ;
196
<img src="/images/button_plus.gif" id="cmdAdd" name="-add" title="Zeile Hinzufügen" onclick="[+ $jsname +].addRow()">
197
<img src="/images/button_kreuz.gif" id="cmdDelete" name="-delete" title="Zeile Löschen" onclick="[+ $jsname +].delRow()">
200
[# ---------------------------------------------------------------------------
202
# show_grid_table Erzeugt eine Grid-Tabelle
205
[$ sub show_grid_table ($self, $req)
206
my $name = $self->{name} ;
207
my $fields = $self -> {fields} ;
208
my $id = $self -> {id};
210
my $max = $fdat{"$name-max"} || 1 ;
213
[* for ($i = 0; $i < $max ; $i++ ) { *]
214
[- $self -> show_grid_table_row ($req, $i) ; -]
227
Embperl::Form::Control::grid - A grid control inside an Embperl Form
235
Used to create a grid control inside an Embperl Form.
236
See Embperl::Form on how to specify parameters.
246
Array ref with field definitions
250
If grid has more rows as given in this parameter,
251
a header line is also displayed at the bottom of the
252
grid. Default is 10. Set to -1 to always get a
253
header at the bottom.
258
name => 'provider-path',
263
{ name => 'active', text => 'Aktiv', type => 'checkbox', width => '30' },
264
{ name => 'path', text => 'Pfad' },
270
G. Richter (richter@dev.ecos.de)
274
perl(1), Embperl, Embperl::Form