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-country.html | 120 +++++++++++++++++++++++++ httemplate/elements/select-county.html | 152 ++++++++++++++++++++++++++++++++ httemplate/elements/select-did.html | 5 +- httemplate/elements/select-state.html | 45 ++++++++-- 4 files changed, 314 insertions(+), 8 deletions(-) create mode 100644 httemplate/elements/select-country.html create mode 100644 httemplate/elements/select-county.html (limited to 'httemplate/elements') diff --git a/httemplate/elements/select-country.html b/httemplate/elements/select-country.html new file mode 100644 index 000000000..c4368c271 --- /dev/null +++ b/httemplate/elements/select-country.html @@ -0,0 +1,120 @@ +<%doc> + +Example: + + include( '/elements/select-country.html', + #recommended + country => $current_country, + + #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 + disable_stateupdate => 0, #bool - disabled update of the select-state.html + + ); + + +% unless ( $opt{'disable_stateupdate'} ) { + + <% include('/elements/xmlhttp.html', + 'url' => $p.'misc/states.cgi', + 'subs' => [ $pre. 'get_states' ], + ) + %> + + + +% } + + + +<%init> + +my %opt = @_; +foreach my $opt (qw( country prefix onchange disabled disable_stateupdate )) { + $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt}); +} + +$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); + +my $pre = $opt{'prefix'}; + +my $onchange = + ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ). + $opt{'onchange'}; + +my $conf = new FS::Conf; +my $default = $conf->config('countrydefault') || 'US'; + +my @all_countries = ( + sort { ($b eq $default) <=> ($a eq $default) + or code2country($a) cmp code2country($b) + } + map { $_->country } + qsearch({ + 'select' => 'country', + 'table' => 'cust_main_county', + 'hashref' => {}, + 'extra_sql' => 'GROUP BY country', + }) + ); + + 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]; + + diff --git a/httemplate/elements/select-did.html b/httemplate/elements/select-did.html index a8ef09d61..069516476 100644 --- a/httemplate/elements/select-did.html +++ b/httemplate/elements/select-did.html @@ -18,8 +18,9 @@ Example: <% include('/elements/select-state.html', - 'country' => $country, - 'empty' => 'Select state', + 'country' => $country, + 'disable_empty' => 0, + 'empty_label' => 'Select state', ) %> diff --git a/httemplate/elements/select-state.html b/httemplate/elements/select-state.html index 4f1c056b5..f7ac2c7bf 100644 --- a/httemplate/elements/select-state.html +++ b/httemplate/elements/select-state.html @@ -1,12 +1,35 @@ - + +% unless ( $opt{'disable_empty'} ) { +