| 1 | |||
| 2 | ################################################################################### | ||
| 3 | # | ||
| 4 | # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de | ||
| 5 | # Embperl - Copyright (c) 2008-2015 Gerald Richter | ||
| 6 | # Embperl - Copyright (c) 2015-2023 actevy.io | ||
| 7 | # | ||
| 8 | # You may distribute under the terms of either the GNU General Public | ||
| 9 | # License or the Artistic License, as specified in the Perl README file. | ||
| 10 | # | ||
| 11 | # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR | ||
| 12 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
| 13 | # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
| 14 | # | ||
| 15 | # $Id$ | ||
| 16 | # | ||
| 17 | ################################################################################### | ||
| 18 | |||
| 19 | package Embperl::Form::Control::select ; | ||
| 20 | |||
| 21 | use strict ; | ||
| 22 | use vars qw{%fdat $escmode} ; | ||
| 23 | use base 'Embperl::Form::ControlMultValue' ; | ||
| 24 | |||
| 25 | use Embperl::Inline ; | ||
| 26 | #use HTML::Escape qw/escape_html/ ; | ||
| 27 | |||
| 28 | sub escape_html | ||
| 29 | { | ||
| 30 | my $v = shift ; | ||
| 31 | $v =~ s/&/&/g ; | ||
| 32 | $v =~ s/"/"/g ; | ||
| 33 | $v =~ s/>/>/g ; | ||
| 34 | $v =~ s/</</g ; | ||
| 35 | return $v ; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub show_control | ||
| 39 | { | ||
| 40 | my ($self, $req, $filter) = @_ ; | ||
| 41 | |||
| 42 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday()], 'start show_control ' . $self->{name} . ' ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 43 | |||
| 44 | my $name = $self -> {name} ; | ||
| 45 | my $fdat = $req -> {docdata} || \%Embperl::fdat ; | ||
| 46 | my $value = $fdat -> {$name} ; | ||
| 47 | $Embperl::idat{$name} = $value ; | ||
| 48 | $filter ||= $self -> {filter} ; | ||
| 49 | my $nsprefix = $self -> form -> {jsnamespace} ; | ||
| 50 | my $val ; | ||
| 51 | my $i = 0 ; | ||
| 52 | my ($values, $options) = $self -> get_all_values ($req) ; | ||
| 53 | my ($ctlattrs, $ctlid, $ctlname) = $self -> get_std_control_attr($req) ; | ||
| 54 | $values ||= [] ; | ||
| 55 | |||
| 56 | my $multiple = $self->{multiple}?'multiple':'' ; | ||
| 57 | my @opt ; | ||
| 58 | my $out = '<select name="' .escape_html ($ctlname) . '" ' . $ctlattrs ; | ||
| 59 | $out .= ' size="' . escape_html ($self->{rows}) . '" ' if ($self->{rows}) ; | ||
| 60 | $out .= ' _ef_attach="ef_select" ' if ($self -> {trigger}) ; | ||
| 61 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday()], 'start show_control4 ' . $self->{name} . ' value: ' . scalar(@$values) . ' : ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 62 | my $i = 0 ; | ||
| 63 | my $escval ; | ||
| 64 | my $escopt ; | ||
| 65 | my $selected ; | ||
| 66 | foreach $val (@$values) | ||
| 67 | { | ||
| 68 | $escval = escape_html ($val) ; | ||
| 69 | $escopt = escape_html ($options ->[$i]) ; | ||
| 70 | $selected = $val eq $value?'selected':'' ; | ||
| 71 | push @opt, qq{<option value="$escval" $selected>} . ($escopt) . q{</option>} if (!defined ($filter) || ($val =~ /$filter/i)) ; | ||
| 72 | $i++ ; | ||
| 73 | } | ||
| 74 | $out .= ">\n" . join ("\n", @opt) . "\n" . '</select>' . "\n" ; | ||
| 75 | |||
| 76 | local $escmode = 0 ; | ||
| 77 | print OUT $out ; | ||
| 78 | |||
| 79 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday()], 'end show_control ' . $self->{name} . ' ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 80 | |||
| 81 | } | ||
| 82 | |||
| 83 | 1 ; | ||
| 84 | |||
| 85 | __EMBPERL__ | ||
| 86 | |||
| 87 | [# --------------------------------------------------------------------------- | ||
| 88 | # | ||
| 89 | # show_hidden - out hidden field | ||
| 90 | #] | ||
| 91 | |||
| 92 | [$ sub show_hidden ($self, $req) $] | ||
| 93 | <input type="hidden" name="[+ $self -> {name} +]"> | ||
| 94 | [$endsub$] | ||
| 95 | |||
| 96 | [# --------------------------------------------------------------------------- | ||
| 97 | # | ||
| 98 | # show_control - output the control | ||
| 99 | #] | ||
| 100 | |||
| 101 | [$ sub xshow_control ($self, $req, $filter) | ||
| 102 | |||
| 103 | my $name = $self -> {name} ; | ||
| 104 | $filter ||= $self -> {filter} ; | ||
| 105 | my $nsprefix = $self -> form -> {jsnamespace} ; | ||
| 106 | my $val ; | ||
| 107 | my $i = 0 ; | ||
| 108 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday], 'start show_control ' . $self->{name} . ' ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 109 | my ($values, $options) = $self -> get_all_values ($req) ; | ||
| 110 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday], 'start show_control2 ' . $self->{name} . ' ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 111 | my ($ctlattrs, $ctlid, $ctlname) = $self -> get_std_control_attr($req) ; | ||
| 112 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday], 'start show_control3 ' . $self->{name} . ' ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 113 | $values ||= [] ; | ||
| 114 | $] | ||
| 115 | <select name="[+ $ctlname +]" [+ $self->{multiple}?'multiple':''+] [+ do { local $escmode = 0 ; $ctlattrs } +] | ||
| 116 | [$if ($self -> {rows}) $] size="[+ $self->{rows} +]" [$endif$] | ||
| 117 | [$if ($self -> {trigger}) $]_ef_attach="ef_select"[$endif$] | ||
| 118 | > | ||
| 119 | [- | ||
| 120 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday], 'start show_control4 ' . $self->{name} . ' value: ' . scalar(@$values) . ' : ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 121 | -] | ||
| 122 | [* $i = 0 ; *] | ||
| 123 | [$ foreach $val (@$values) $] | ||
| 124 | [$if !defined ($filter) || ($val =~ /$filter/i) $] | ||
| 125 | <option value="[+ $val +]">[+ $options ->[$i] || $val +]</option> | ||
| 126 | [$endif$] | ||
| 127 | [* $i++ ; *] | ||
| 128 | [$endforeach$] | ||
| 129 | </select> | ||
| 130 | [- | ||
| 131 | push @{$req -> {timing}}, ([Time::HiRes::gettimeofday], 'end show_control3 ' . $self->{name} . ' ' . __FILE__ . '#' . __LINE__) if ($req -> {timing}); | ||
| 132 | -] | ||
| 133 | [$endsub$] | ||
| 134 | |||
| 135 | __END__ |