From cd2371a35a0c416366fa1822d99571ca68a5ad1e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 19 Mar 2002 17:48:28 +0000 Subject: [PATCH] changes dum big "state/county/country" select to three, linked with javascript closes: Bug#353 --- FS/FS/cust_main_county.pm | 136 +++++++++++++++++++++++++++++++++- httemplate/edit/cust_main.cgi | 79 +++++++++----------- httemplate/edit/process/cust_main.cgi | 13 ---- 3 files changed, 169 insertions(+), 59 deletions(-) diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm index 383360b7b..17fe164e4 100644 --- a/FS/FS/cust_main_county.pm +++ b/FS/FS/cust_main_county.pm @@ -1,10 +1,21 @@ package FS::cust_main_county; use strict; -use vars qw( @ISA ); -use FS::Record; +use vars qw( @ISA @EXPORT_OK $conf + @cust_main_county %cust_main_county $countyflag ); +use Exporter; +use FS::Record qw( qsearch ); @ISA = qw( FS::Record ); +@EXPORT_OK = qw( regionselector ); + +@cust_main_county = (); +$countyflag = ''; + +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::cust_main_county'} = sub { + $conf = new FS::Conf; +}; =head1 NAME @@ -25,6 +36,9 @@ FS::cust_main_county - Object methods for cust_main_county objects $error = $record->check; + ($county_html, $state_html, $country_html) = + FS::cust_main_county::regionselector( $county, $state, $country ); + =head1 DESCRIPTION An FS::cust_main_county object represents a tax rate, defined by locale. @@ -94,12 +108,126 @@ sub check { =back -=head1 VERSION +=head1 SUBROUTINES -$Id: cust_main_county.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $ +=over 4 + +=item regionselector [ COUNTY STATE COUNTRY [ PREFIX [ ONCHANGE ] ] ] + +=cut + +sub regionselector { + my ( $selected_county, $selected_state, $selected_country, + $prefix, $onchange ) = @_; + $countyflag=1 if $selected_county; + + unless ( @cust_main_county ) { #cache + @cust_main_county = qsearch('cust_main_county', {} ); + foreach my $c ( @cust_main_county ) { + $countyflag=1 if $c->county; + push @{$cust_main_county{$c->country}{$c->state}}, $c->county; + } + } + + my $script_html = < + function opt(what,value,text) { + var optionName = new Option(text, value, false, false); + var length = what.length; + what.options[length] = optionName; + } + function ${prefix}country_changed(what) { + country = what.options[what.selectedIndex].text; + for ( var i = what.form.${prefix}state.length; i >= 0; i-- ) + what.form.${prefix}state.options[i] = null; +END + #what.form.${prefix}state.options[0] = new Option('', '', false, true); + + foreach my $country ( sort keys %cust_main_county ) { + $script_html .= "\nif ( country == \"$country\" ) {\n"; + foreach my $state ( sort keys %{$cust_main_county{$country}} ) { + my $text = $state || '(n/a)'; + $script_html .= qq!opt(what.form.${prefix}state, "$state", "$text");\n!; + } + $script_html .= "}\n"; + } + + $script_html .= <= 0; i-- ) + what.form.${prefix}county.options[i] = null; +END + + foreach my $country ( sort keys %cust_main_county ) { + $script_html .= "\nif ( country == \"$country\" ) {\n"; + foreach my $state ( sort keys %{$cust_main_county{$country}} ) { + $script_html .= "\nif ( state == \"$state\" ) {\n"; + foreach my $county ( sort @{$cust_main_county{$country}{$state}} ) { + my $text = $county || '(n/a)'; + $script_html .= + qq!opt(what.form.${prefix}county, "$county", "$text");\n!; + } + $script_html .= "}\n"; + } + $script_html .= "}\n"; + } + } + + $script_html .= < +END + + my $county_html = $script_html; + if ( $countyflag ) { + $county_html .= qq!'; + } else { + $county_html .= + qq!!; + } + + my $state_html = qq!'; + + $state_html .= ''; + + my $country_html = qq!'; + + ($county_html, $state_html, $country_html); + +} + +=back =head1 BUGS +regionseletor? putting web ui components in here? they should probably live +somewhere else... + =head1 SEE ALSO L, L, L, schema.html from the base diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 89a946b0f..39b6ca594 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -69,7 +69,7 @@ print qq!
!, # agent -my $r = qq!*!; +my $r = qq!* !; my @agents = qsearch( 'agent', {} ); #die "No agents created!" unless @agents; @@ -147,7 +147,7 @@ my($last,$first,$ss,$company,$address1,$address2,$city,$zip)=( ); print "

Billing address", &itable("#cccccc"), <${r}Contact name
(last, first) +${r}Contact name
(last, first) END print <Company ${r}Address   -${r}City${r}State/Country${r}State END -#false laziness with ship_state +#false laziness with ship state my $countrydefault = $conf->config('countrydefault') || 'US'; $cust_main->country( $countrydefault ) unless $cust_main->country; + $cust_main->state( $conf->config('statedefault') || 'CA' ) unless $cust_main->state || $cust_main->country ne 'US'; -foreach ( sort { - ( $b->country eq $countrydefault ) <=> ( $a->country eq $countrydefault ) - or $a->country cmp $b->country - or $a->state cmp $b->state - or $a->county cmp $b->county -} qsearch('cust_main_county',{}) ) { - print "state eq $_->state - && $cust_main->county eq $_->county - && $cust_main->country eq $_->country - ); - print ">",$_->state; - print " (",$_->county,")" if $_->county; - print " / ", $_->country; -} -print qq!${r}Zip!; + +my($county_html, $state_html, $country_html) = + FS::cust_main_county::regionselector( $cust_main->county, + $cust_main->state, + $cust_main->country ); + +print "$county_html $state_html"; + +print qq!${r}Zip!; my($daytime,$night,$fax)=( $cust_main->daytime, @@ -199,12 +193,13 @@ my($daytime,$night,$fax)=( ); print <${r}Country$country_html Day Phone Night Phone Fax END -print "$r required fields
"; +print "${r}required fields
"; # service address @@ -221,7 +216,11 @@ END print " what.form.ship_$_.value = what.form.$_.value;\n" for (qw( last first company address1 address2 city zip daytime night fax )); print < @@ -251,7 +250,7 @@ END ); print &itable("#cccccc"), <${r}Contact name
(last, first) + ${r}Contact name
(last, first) END print <Company ${r}Address   - ${r}City${r}State/Country${r}State END #false laziness with regular state - $cust_main->ship_country( $conf->config('countrydefault') || 'US' ) - unless $cust_main->ship_country; + $cust_main->ship_country( $countrydefault ) unless $cust_main->ship_country; + $cust_main->ship_state( $conf->config('statedefault') || 'CA' ) unless $cust_main->ship_state || $cust_main->ship_country ne 'US'; - foreach ( sort { - ( $b->country eq $countrydefault ) <=> ( $a->country eq $countrydefault ) - or $a->country cmp $b->country - or $a->state cmp $b->state - or $a->county cmp $b->county - } qsearch('cust_main_county',{}) ) { - print "ship_state eq $_->state - && $cust_main->ship_county eq $_->county - && $cust_main->ship_country eq $_->country - ); - print ">",$_->state; - print " (",$_->county,")" if $_->county; - print " / ", $_->country; - } - print qq!${r}Zip!; + + my($ship_county_html, $ship_state_html, $ship_country_html) = + FS::cust_main_county::regionselector( $cust_main->ship_county, + $cust_main->ship_state, + $cust_main->ship_country, + 'ship_', + 'changed(this)', ); + + print "$ship_county_html $ship_state_html"; + + print qq!${r}Zip!; my($ship_daytime,$ship_night,$ship_fax)=( $cust_main->ship_daytime, @@ -296,12 +290,13 @@ END ); print <${r}Country$ship_country_html Day Phone Night Phone Fax END - print "$r required fields
"; + print "${r}required fields
"; } diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index c8038ecf6..6ce60d14a 100755 --- a/httemplate/edit/process/cust_main.cgi +++ b/httemplate/edit/process/cust_main.cgi @@ -8,19 +8,6 @@ $cgi->param('tax','') unless defined $cgi->param('tax'); $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] ); -$cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ - or die "Oops, illegal \"state\" param: ". $cgi->param('state'); -$cgi->param('state', $1); -$cgi->param('county', $3 || ''); -$cgi->param('country', $4); - -$cgi->param('ship_state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ - or $cgi->param('ship_state') =~ /^(((())))$/ - or die "Oops, illegal \"ship_state\" param: ". $cgi->param('ship_state'); -$cgi->param('ship_state', $1); -$cgi->param('ship_county', $3 || ''); -$cgi->param('ship_country', $4); - my $payby = $cgi->param('payby'); if ( $payby ) { $cgi->param('payinfo', $cgi->param( $payby. '_payinfo' ) ); -- 2.11.0