From 3c8870ee619416f126a65c93d5ef7a2f2e24bc96 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 27 Dec 2006 02:37:17 +0000 Subject: [PATCH] Add a (magically appearing and disappearing) label on the county selector. confusing when labeled "state" --- FS/FS/Misc.pm | 38 +++++++--- htetc/handler.pl | 2 +- httemplate/edit/cust_main/contact.html | 100 ++++++++++++++------------- httemplate/edit/cust_main/select-county.html | 15 ++-- httemplate/misc/counties.cgi | 22 +----- 5 files changed, 90 insertions(+), 87 deletions(-) diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index 97ff8ed61..5d74adf23 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -7,7 +7,10 @@ use Carp; use Data::Dumper; @ISA = qw( Exporter ); -@EXPORT_OK = qw( send_email send_fax states_hash state_label card_types ); +@EXPORT_OK = qw( send_email send_fax + states_hash counties state_label + card_types + ); $DEBUG = 0; @@ -359,13 +362,12 @@ sub states_hash { # sort map { s/[\n\r]//g; $_; } map { $_->state; } - qsearch({ - 'select' => 'state', - 'table' => 'cust_main_county', - 'hashref' => { 'country' => $country }, - 'extra_sql' => 'GROUP BY state', - }) - ; + qsearch({ + 'select' => 'state', + 'table' => 'cust_main_county', + 'hashref' => { 'country' => $country }, + 'extra_sql' => 'GROUP BY state', + }); #it could throw a fatal "Invalid country code" error (for example "AX") my $subcountry = eval { new Locale::SubCountry($country) } @@ -378,6 +380,26 @@ sub states_hash { @states; } +=item counties STATE COUNTRY + +Returns a list of counties for this state and country. + +=cut + +sub counties { + my( $state, $country ) = @_; + + sort map { s/[\n\r]//g; $_; } + map { $_->county } + qsearch({ + 'select' => 'DISTINCT county', + 'table' => 'cust_main_county', + 'hashref' => { 'state' => $state, + 'country' => $country, + }, + }); +} + =item state_label STATE COUNTRY_OR_LOCALE_SUBCOUNRY_OBJECT =cut diff --git a/htetc/handler.pl b/htetc/handler.pl index 2272e2603..f47d4c9bf 100644 --- a/htetc/handler.pl +++ b/htetc/handler.pl @@ -129,7 +129,7 @@ sub handler eidiot small_custview myexit http_header); use FS::UI::Web; use FS::Msgcat qw(gettext geterror); - use FS::Misc qw( send_email send_fax states_hash state_label ); + use FS::Misc qw( send_email send_fax states_hash counties state_label ); use FS::Report::Table::Monthly; use FS::TicketSystem; diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html index a001634a2..e813986cd 100644 --- a/httemplate/edit/cust_main/contact.html +++ b/httemplate/edit/cust_main/contact.html @@ -1,50 +1,8 @@ -% -% -%my( $cust_main, $pre, $onchange, $disabled ) = @_; -%my $conf = new FS::Conf; -% -%#false laziness with ship state -%my $countrydefault = $conf->config('countrydefault') || 'US'; -%$cust_main->set($pre.'country', $countrydefault ) -% unless $cust_main->get($pre.'country'); -% -%my $statedefault = $conf->config('statedefault') -% || ($countrydefault eq 'US' ? 'CA' : ''); -%$cust_main->set($pre.'state', $statedefault ) -% unless $cust_main->get($pre.'state') -% || $cust_main->get($pre.'country') ne $countrydefault; -% -%#my($county_html, $state_html, $country_html) = -%# FS::cust_main_county::regionselector( $cust_main->get($pre.'county'), -%# $cust_main->get($pre.'state'), -%# $cust_main->get($pre.'country'), -%# $pre, -%# $onchange, -%# $disabled, -%# ); -% -%my %select_hash = ( -% 'county' => $cust_main->get($pre.'county'), -% 'state' => $cust_main->get($pre.'state'), -% 'country' => $cust_main->get($pre.'country'), -% 'prefix' => $pre, -% 'onchange' => $onchange, -% 'disabled' => $disabled, -%); -% -%my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone'; -%my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone'; -% -%my $r = qq!* !; -% -% - - <% &ntable("#cccccc") %> <%$r%>Contact name
(last, first) - + > , > @@ -62,21 +20,21 @@ Company - + > <%$r%>Address - + >   - + > @@ -86,9 +44,12 @@ > - <%$r%>State + ><%$r%>County <% include('select-county.html', %select_hash ) %> + + <%$r%>State + <% include('select-state.html', %select_hash ) %> <%$r%>Zip @@ -126,3 +87,48 @@ <%$r%>required fields
+<%init> + +my( $cust_main, $pre, $onchange, $disabled ) = @_; +my $conf = new FS::Conf; + +#false laziness with ship state +my $countrydefault = $conf->config('countrydefault') || 'US'; +$cust_main->set($pre.'country', $countrydefault ) + unless $cust_main->get($pre.'country'); + +my $statedefault = $conf->config('statedefault') + || ($countrydefault eq 'US' ? 'CA' : ''); +$cust_main->set($pre.'state', $statedefault ) + unless $cust_main->get($pre.'state') + || $cust_main->get($pre.'country') ne $countrydefault; + +#my($county_html, $state_html, $country_html) = +# FS::cust_main_county::regionselector( $cust_main->get($pre.'county'), +# $cust_main->get($pre.'state'), +# $cust_main->get($pre.'country'), +# $pre, +# $onchange, +# $disabled, +# ); + +my %select_hash = ( + 'county' => $cust_main->get($pre.'county'), + 'state' => $cust_main->get($pre.'state'), + 'country' => $cust_main->get($pre.'country'), + 'prefix' => $pre, + 'onchange' => $onchange, + 'disabled' => $disabled, +); + +my @counties = counties( $cust_main->get($pre.'state'), + $cust_main->get($pre.'country'), + ); +my $county_style = scalar(@counties) > 1 ? '' : 'STYLE="visibility:hidden"'; + +my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone'; +my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone'; + +my $r = qq!* !; + + diff --git a/httemplate/edit/cust_main/select-county.html b/httemplate/edit/cust_main/select-county.html index 5b068214e..0dc826896 100644 --- a/httemplate/edit/cust_main/select-county.html +++ b/httemplate/edit/cust_main/select-county.html @@ -34,10 +34,14 @@ opt(what.form.<% $opt{'prefix'} %>county, countiesArray[s], countyLabel); } + var countyFormLabel = document.getElementById('<% $opt{'prefix'} %>countylabel'); + if ( countiesArray.length > 1 ) { what.form.<% $opt{'prefix'} %>county.style.display = ''; + countyFormLabel.style.visibility = 'visible'; } else { what.form.<% $opt{'prefix'} %>county.style.display = 'none'; + countyFormLabel.style.visibility = 'hidden'; } //run the callback @@ -84,16 +88,7 @@ foreach my $opt (qw( county state country prefix onchange disabled )) { my @counties = (); if ( $countyflag ) { - @counties = - sort - map { $_->county } - qsearch( { - 'select' => 'DISTINCT county', - 'table' => 'cust_main_county', - 'hashref' => { 'state' => $opt{'state'}, - 'country' => $opt{'country'}, - }, - } ); + @counties = counties( $opt{'state'}, $opt{'country'} ); # this is very hacky unless ( scalar(@counties) > 1 ) { diff --git a/httemplate/misc/counties.cgi b/httemplate/misc/counties.cgi index 940cba7dc..c022a27d9 100644 --- a/httemplate/misc/counties.cgi +++ b/httemplate/misc/counties.cgi @@ -1,27 +1,7 @@ [ <% join(', ', map { qq("$_") } @counties) %> ] <%init> -my $DEBUG = 0; - my( $state, $country ) = $cgi->param('arg'); - -warn "fetching counties for $state / $country \n" - if $DEBUG; - -my @counties = - sort - map { s/[\n\r]//g; $_; } - map { $_->county; } - qsearch( { - 'select' => 'DISTINCT county', - 'table' => 'cust_main_county', - 'hashref' => { 'state' => $state, - 'country' => $country, - }, - } ) -; - -warn "counties: ". join(', ', map { qq("$_") } @counties). "\n" - if $DEBUG; +my @counties = counties($state, $country); -- 2.11.0