From d8cb6cd67cc574c90dbbfbd8db2da6711c516d65 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 28 Dec 2008 18:48:51 +0000 Subject: fix browse results for selecting counties (resulting from separating tax classes), also add dropdowns to browse by state and county, RT#4496 --- httemplate/elements/select-county.html | 152 +++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 httemplate/elements/select-county.html (limited to 'httemplate/elements/select-county.html') diff --git a/httemplate/elements/select-county.html b/httemplate/elements/select-county.html new file mode 100644 index 000000000..8ef34dbe6 --- /dev/null +++ b/httemplate/elements/select-county.html @@ -0,0 +1,152 @@ +<%doc> + +Example: + + include( '/elements/select-county.html', + #recommended + country => $current_country, + state => $current_state, + county => $current_county, + + #optional + prefix => $optional_unique_prefix, + onchange => $javascript, + disabled => 0, #bool + disable_empty => 1, #defaults to 1, disable the empty option + empty_label => 'all', #label for empty option + ); + + +% if ( $countyflag ) { + + <% include('/elements/xmlhttp.html', + 'url' => $p.'misc/counties.cgi', + 'subs' => [ $pre. 'get_counties' ], + ) + %> + + + + + +% } else { + + + + + +% } + +<%init> + +my %opt = @_; +foreach my $opt (qw( county state country prefix onchange disabled + empty_value )) { + $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt}); +} + +$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); + +my $pre = $opt{'prefix'}; + +my @counties = (); +if ( $countyflag ) { + + @counties = map { length($_) ? $_ : $opt{'empty_data_value'} } + counties( $opt{'state'}, $opt{'country'} ); + + # this is very hacky + unless ( scalar(@counties) > 1 ) { + if ( $opt{'disabled'} =~ /STYLE=/i ) { + $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i; + } else { + $opt{'disabled'} .= ' STYLE="display:none"'; + } + } + +} + + +<%once> + +my $sql = "SELECT COUNT(*) FROM cust_main_county". + " WHERE county IS NOT NULL AND county != ''"; +my $sth = dbh->prepare($sql) or die dbh->errstr; +$sth->execute or die $sth->errstr; +my $countyflag = $sth->fetchrow_arrayref->[0]; + + -- cgit v1.2.1