CGI-Bus
view release on metacpan or search on metacpan
lib/CGI/Bus/wg.pm view on Meta::CPAN
use CGI::Bus::Base;
use vars qw(@ISA $AUTOLOAD);
@ISA =qw(CGI::Bus::Base);
1;
#######################
sub ddlb { # Drop-Down List Box - Input helper
my ($s,$w,$n,$ds) =(shift
#,!$_[0] || $_[0] =~/^(?:<|\$_|\s)/ || $_[0] =~/(?:>|\$_|\s)$/ ? shift : undef
,shift
,shift, shift);
my $x; if (ref($n)) {$x =$n; $n =$x->{-name}}
my $g =$s->cgi;
my $r ='';
if ($g->param($n .'_B')) {
my $ff =(ref($_[0]) ? $_[0]->[0] : $_[0]);
my $fs =sub{
'{var k;'
."var l=window.document.forms[0].${n}_L;"
.(!$_[0]
? "k=window.document.forms[0].$ff.value +String.fromCharCode(window.event.keyCode);"
: $_[0] eq '1'
# ? "k=window.document.forms[0].$ff.value +=String.fromCharCode(window.event.keyCode);"
# ? "window.document.forms[0].$ff.fireEvent(\"onkeypress\"); k=window.document.forms[0].$ff.value;"
? "window.document.forms[0].$ff.focus(); k=window.document.forms[0].$ff.value =String.fromCharCode(window.event.keyCode); "
: $_[0] eq '2'
? "k=prompt('Enter search string',String.fromCharCode(window.event.keyCode));"
# $_[0] eq '3'
: "k=prompt('Enter search substring',''); ${n}_L.focus();"
)
.'if(!k){return(false)}; k=k.toLowerCase();'
.'for (var i=0; i <l.length; ++i) {'
.($g->user_agent('MSIE')
?'if (l.options.item(i).value.toLowerCase().indexOf(k)'
.($_[0] eq '3' ?'>=' :'==') .'0 || l.options.item(i).innerText.toLowerCase().indexOf(k)'
.($_[0] eq '3' ?'>=' :'==') .'0){'
:'if (l.options.item(i).value.toLowerCase().indexOf(k)'
.($_[0] eq '3' ?'>=' :'==') .'0){')
.'l.selectedIndex =i; break;}}'
.($_[0] ? 'return(false);' : '')
.'}'};
if ($ff !~/^\t/ && $w) {
$r .='<script for="' .$ff
.'" event="onkeypress()" >' .&$fs(0) .'</script>';
}
$r .=$w if $w;
$r .=$g->submit(($x ? (%$x) : ())
,-name=>($n .'_C')
,-value=>$s->lng(0,'ddlbclose')
,-title=>$s->lng(1,'ddlbclose'));
$r .='<br />';
$ds = &$ds($s) if ref($ds) eq 'CODE';
my $dl;
if (ref($ds) eq 'HASH') {
$dl =$ds;
$ds =do{use locale; [sort {lc($ds->{$a}) cmp lc($ds->{$b})} keys %$ds]};
foreach my $k (keys %$dl) {$dl->{$k} =substr($dl->{$k},0,60) .'...' if length($dl->{$k}) >60}
}
$r .=$g->scrolling_list(($x ? (%$x) : ())
,-name=>($n .'_L')
,-values=>$ds
,-labels=>$dl
,-size=>(scalar(@$ds) <10 ? scalar(@$ds) : 10)
,-onDblClick=>"{${n}_L.nextSibling.nextSibling.click();"
.($ff !~/^\t/ && scalar(@_) >1 ? ' submit();' : '')
.' return(false)}'
,($ff !~/^\t/ && $w
? (-onKeyPress=>&$fs(1))
: ())
,-default=> 0 ? '' : $ff !~/^\t/ ? $g->param($ff) : ''
);
chomp($r);
$r .='<br />';
if (scalar(@_) == 1 && $ff !~/^\t/) {
$r .=$g->submit(($x ? (%$x) : ())
,-name=>($n .'_S')
,-value=>'<'
.(ref($_[0]) ?($_[0]->[1] || $_[0]->[0]) :($_[0] || ''))
,-title=>$s->lng(1,'ddlbsetvalue'));
}
else {
foreach my $ff (@_) {
next if !$ff;
my ($fn, $l) =ref($ff) ? (@$ff) : ($ff, '');
next if !$fn;
my $wn =($fn =~/([^\t]+)$/ ? $1 : $fn); # /^\t(.*)/
$l =scalar(@_) ==1 ? '' : $wn if !$l ||($l eq $fn);
$r .=
$g->button(($x ? (%$x) : ())
,-name=>''
,-value=>(($fn !~/^\t/ ? '<' : '<+') .$l)
,-onClick=> "var fs =window.document.forms[0].${n}_L; "
."var ft =window.document.forms[0].$wn; "
."var i =fs.selectedIndex; "
.($g->user_agent('MSIE')
?($fn !~/^\t/ ? "ft.value =(fs.options.item(i).value ==\"\" ? fs.options.item(i).text : fs.options.item(i).value); "
: "ft.value =(ft.value ==\"\" ? \"\" : (ft.value +\", \")) +(fs.options.item(i).value ==\"\" ? fs.options.item(i).text : fs.options.item(i).value); ")
:($fn !~/^\t/ ? "ft.value =fs[i].value; "
: "ft.value =(ft.value ==\"\" ? \"\" : (ft.value +\", \")) +fs[i].value; ")
)
,-title=>$s->lng(1,'ddlbsetvalue'));
}
}
$r .=$g->button(($x ? (%$x) : ())
,-name=>''
,-value=>$s->lng(0,'ddlbfind')
,-title=>$s->lng(1,'ddlbfind')
,-onClick=>&$fs(3));
$r .=$g->submit(($x ? (%$x) : ())
,-name=>($n .'_C')
,-value=>$s->lng(0,'ddlbclose')
,-title=>$s->lng(1,'ddlbclose'));
$r .='<script for="window" event="onload">{'
# .'window.scrollTo(window.document.forms[0].' .$n .'_L, window.screenTop);'
.(0 && $ff !~/^\t/ && $w && defined($g->param($ff)) && ($g->param($ff) ne '')
? "window.document.forms[0].${ff}.select(); window.document.forms[0].${ff}.focus();"
( run in 0.530 second using v1.01-cache-2.11-cpan-ceb78f64989 )