2
2
###################################################################################
4
# Embperl - Copyright (c) 1997-2005 Gerald Richter / ecos gmbh www.ecos.de
4
# Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5
# Embperl - Copyright (c) 2008-2012 Gerald Richter
6
7
# You may distribute under the terms of either the GNU General Public
7
8
# License or the Artistic License, as specified in the Perl README file.
55
if (my $e = $self -> {event})
57
for (my $i = 0; $i < @$e; $i += 2)
59
$eventattrs .= $e -> [$i] . '="' . $e -> [$i+1] . '" ' ;
62
$self -> {eventattrs} = $eventattrs ;
63
$self -> {imagedir} ||= '/images' ;
89
101
my ($self, $req) = @_ ;
91
return $self -> {readonly} ;
103
return $self -> {readonly} || $req -> {form_options_masks}{$self->{name}}{readonly} || $req -> {form_options_masks}{'*'}{readonly} ;
94
106
# ---------------------------------------------------------------------------
96
# show - output the whole control including the label
108
# is_hidden - returns true if this is a hidden control
102
114
my ($self, $req) = @_ ;
104
$fdat{$self -> {name}} = $self -> {default} if ($fdat{$self -> {name}} eq '' && exists ($self -> {default})) ;
106
$span += $self -> show_label_cell ($req, $span);
107
return $self -> show_control_cell ($req, $span) ;
110
120
# ---------------------------------------------------------------------------
112
122
# get_on_show_code
145
155
# ---------------------------------------------------------------------------
157
# load_form - load a form to a given formptr.
159
# This class method should be overwritten, to load a form to a given
160
# formptr, in case it is not already loaded
161
# The formptr maybe passed in the options hash during form creation
169
my ($class, $formptr) = @_ ;
173
# ---------------------------------------------------------------------------
175
# get_control_from_id
178
sub get_control_from_id
180
my ($class, $id) = @_ ;
182
my ($formptr, $ctlid) = split /#/, $id ;
183
my $form = $Embperl::FormData::forms{$formptr} ;
187
$class -> load_form ($formptr) ;
188
$form = $Embperl::FormData::forms{$formptr} ;
189
die "Form for '$formptr' is not available" if (!$form) ;
192
my $ctl = $form -> {controlids}{$ctlid} ;
193
die "Control '$ctlid' in Form '$formptr' is not available" if (!$ctl) ;
198
# ---------------------------------------------------------------------------
203
sub get_id_for_control
205
my ($self, $reqdata) = @_ ;
207
return "$self->{formptr}#$self->{id}" ;
210
# ---------------------------------------------------------------------------
212
# label_text - return text of label
219
return $self -> {label_text} if ($self -> {label_text}) ;
221
return $self -> {label_text} = $self -> {showtext}?($self->{text} ||
222
$self->{name}):$self -> form -> convert_label ($self) ;
226
# ---------------------------------------------------------------------------
228
# get_validate_auto_rules - get rules for validation, in case user did
230
# should be overwritten by control
233
sub get_validate_auto_rules
235
my ($self, $req) = @_ ;
237
return if (!$self -> {required}) ;
238
return [ required => 1 ] ;
241
# ---------------------------------------------------------------------------
147
243
# get_validate_rules - get rules for validation
154
250
my @local_rules ;
155
251
if ($self -> {validate})
158
253
@local_rules = ( -key => $self->{name} );
159
push @local_rules, -name => $self->{text} if ($self -> {text}) ;
254
push @local_rules, -name => $self -> label_text ;
160
255
push @local_rules, @{$self -> {validate}};
259
my $auto = $self -> get_validate_auto_rules ($req) ;
262
@local_rules = ( -key => $self->{name} );
263
push @local_rules, -name => $self -> label_text ;
264
push @local_rules, @{$auto};
162
267
return \@local_rules ;
270
# ---------------------------------------------------------------------------
272
# has_auto_label_size - returns true if label should be auto sized for this control
275
sub has_auto_label_size
281
# ---------------------------------------------------------------------------
283
# get_value - return the current value for the control
284
# if dataprefix is set, every hash key within dataprefix is tried
289
my ($self, $req) = @_ ;
291
my $fdat = $req -> {docdata} || \%Embperl::fdat ;
292
my $name = $self -> {name} ;
293
my $dataprefix = $self -> {dataprefix} ;
294
return $fdat -> {$name} if (!$dataprefix) ;
296
foreach my $prefix (@$dataprefix)
298
my $item = $prefix?$fdat -> {$prefix}{$name}:$fdat -> {$name} ;
299
return $item if (defined ($item)) ;
306
# ---------------------------------------------------------------------------
308
# get_std_control_attr - return the default attributes for the control
310
# ret string with all standard attribute, already html escaped
313
sub get_std_control_attr
315
my ($self, $req, $id, $type, $addclass) = @_ ;
317
my $name = $self -> {force_name} || $self -> {name} ;
318
my $ctrlid = $id || ($req -> {uuid} . '_' . $name) ;
319
my $class = $self -> {class} ;
320
my $width = $self -> {width_percent} ;
321
my $events = $self -> {eventattrs} ;
322
$type ||= $self -> {type} ;
323
my $state = $self -> {state} ;
325
my $attrs = qq{class="ef-control ef-control-width-$width ef-control-$type ef-control-$type-width-$width $addclass $class $state" id="$ctrlid" $events} ;
326
return wantarray?($attrs, $ctrlid, $name):$attrs ;
168
332
# ===========================================================================
172
336
[$syntax EmbperlBlocks $]
340
[# ---------------------------------------------------------------------------
342
# show - output the whole control including the label
345
[$sub show ($self, $req)
347
$fdat{$self -> {name}} = $self -> {default} if ($fdat{$self -> {name}} eq '' && exists ($self -> {default})) ;
350
$]<table class="ef-element ef-element-width-[+ $self -> {width_percent} +] ef-element-[+ $self -> {type} +] [+ $self -> {state} +]">
353
$span += $self -> show_label_cell ($req, $span);
354
$self -> show_control_cell ($req, $span) ;
174
360
[# ---------------------------------------------------------------------------
176
362
# show_sub_begin - output begin of sub form
197
383
# show - output the label
200
[$ sub show_label ($self, $req) $][+ $self->{text} || $self->{name} +][$endsub$]
386
[$ sub show_label ($self, $req) $][-
388
if ($self -> {showoptionslabel})
390
my $opts = $self -> form -> convert_options ($self, [$self -> {value}]) ;
391
$self -> {text} = $opts -> [0] ;
392
$self -> {showtext} = 1 ;
394
-][+ $self -> label_text +][$endsub$]
202
396
[# ---------------------------------------------------------------------------
207
401
[$sub show_label_icon ($self, $req) $]
208
[$if $self -> {sublines} $] <img src="/images/plus.png" style="vertical-align: middle;">[$endif$]
209
[$if $self -> {parentid} $] <img src="/images/vline.png" style="vertical-align: middle;">[$endif$]
402
[$if $self -> {xxsublines} $] <img src="/images/plus.png" style="vertical-align: middle;">[$endif$]
403
[$if $self -> {xxparentid} $] <img src="/images/vline.png" style="vertical-align: middle;">[$endif$]
212
406
[# ---------------------------------------------------------------------------
217
411
[$ sub show_label_cell ($self, $req)
220
$style = "white-space:nowrap;" if ($self->{labelnowrap}) ;
414
$style = 'white-space:nowrap; ' if ($self->{labelnowrap}) ;
415
$addclass = 'ef-label-box-width-' . ($self->{width_percent}) ;
416
$addclass2 = 'ef-label-width-' . ($self->{width_percent}) ;
223
<td class="cLabelBox[$ if $self->{labelclass} $][+ " $self->{labelclass}" +][$ endif $]"
224
colspan="1" [$ if $style $]style="[+ $style +]"[$ endif $]>
418
<td class="ef-label-box [+ $addclass +] [$ if $self->{labelclass} $][+ " $self->{labelclass}" +][$ endif $]" [$ if $style $]style="[+ $style +]"[$ endif $]>
419
<div class="ef-label [+ $addclass2 +]">
226
421
$self -> show_label ($req);
227
422
$self -> show_label_icon ($req) ;
233
429
[# ---------------------------------------------------------------------------
235
431
# show_control - output the control itself
238
[$ sub show_control ($self, $req) $][+ $self->{value} +][$endsub$]
434
[$ sub show_control ($self, $req) $]<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req) } +]>[+ $self->{value} +]</div>[$endsub$]
240
436
[# ---------------------------------------------------------------------------
242
438
# show_control_readonly - output the control as readonly
245
[$ sub show_control_readonly ($self, $req) $][+ $self -> {value} || $fdat{$self -> {name}} +][$endsub$]
441
[$ sub show_control_readonly ($self, $req, $value)
443
$value = $self -> {value} || $fdat{$self -> {name}} if (!defined($value)) ;
445
<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, '', 'readonly') } +]>[+ $value +]</div>
448
[# ---------------------------------------------------------------------------
450
# show_control_addons - output additional things after the control
453
[$ sub show_control_addons ($self, $req) $][$endsub$]
248
456
[# ---------------------------------------------------------------------------
253
461
[$ sub show_control_cell ($self, $req, $x)
255
my $span = $self->{width_percent} - $x ;
463
my $ro = $self -> is_readonly ($req) ;
464
my $addclass = 'ef-control-box-width-' . ($self->{width_percent} || 50 ) ;
465
$addclass .= ' ef-control-box-readonly' if ($ro) ;
257
<td class="cControlBox" colspan="[+ $span +]">
258
[* my @ret = $self -> is_readonly?$self -> show_control_readonly($req):$self -> show_control ($req); *]
467
<td class="ef-control-box [+ $addclass +]">
469
my @ret = $ro?$self -> show_control_readonly($req):$self -> show_control ($req);
470
$self -> show_control_addons ($req) ;
260
473
[* return @ret ; *]
344
561
Output the control itself
563
=head2 show_control_readonly
565
Output the control itself as readonly
567
=head2 show_control_addons
569
output additional things after the control
346
571
=head2 show_control_cell
348
573
Output the table cell in which the control will be displayed
361
586
Will be used as label for the control, if not given
362
name is used as default
587
'name' is used as default.
589
Normaly the the name and text parameters are processed
590
by the method C<convert_label> of the C<Embperl::Form>
591
object. This method can be overwritten, to allow translation etc.
593
If the parameter C<showtext> is given a true value, C<convert_label>
594
is not called and the text is displayed as it is.
598
Display label without passing it through C<convert_label>. See C<text>.
364
600
=head2 labelnowrap
392
628
=head2 width_percent
394
630
With this parameter you can also specify the width of
395
the control in percent. This parameter take precendence over
631
the control in percent. This parameter take precedence over
400
636
Default value of the control
640
Basepath where to find images, in case the control uses images.
641
Default value is /images
645
When set will trigger state changes of other controls. See "state".
649
Can be used to hide/show disable/enable the control trigger by
652
Checkbox define the following states:
656
=item * <id-of-checkbox>-show
658
Show control if checkbox checked
660
=item * <id-of-checkbox>-hide
662
Hide control if checkbox checked
664
=item * <id-of-checkbox>-enable
666
Enable control if checkbox checked
668
=item * <id-of-checkbox>-disable
670
Disable control if checkbox checked
404
G. Richter (richter@dev.ecos.de)
678
G. Richter (richter at embperl dot org)