From f5481d63043954fa6fa8a34a5820b23408192f8b Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Tue, 4 Jun 2019 08:11:19 -0400 Subject: [PATCH] RT# 83365 - Added city select to work like back end --- fs_selfservice/FS-SelfService/SelfService.pm | 127 +++++++++++++++++++++++-- fs_selfservice/FS-SelfService/cgi/contact.html | 11 +-- 2 files changed, 123 insertions(+), 15 deletions(-) diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index a516a9719..af989ed8a 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -2440,7 +2440,10 @@ sub regionselector { my $prefix = exists($param->{'prefix'}) ? $param->{'prefix'} : ''; - my $countyflag = 0; + my $disabled = $param->{'disabled'}; + + my $countyflag = $param->{selected_county} ? 1 : 0; + my $cityflag = $param->{selected_city} ? 1 : 0; my %cust_main_county; @@ -2450,17 +2453,17 @@ sub regionselector { foreach my $c ( @{ $param->{'locales'} } ) { #$countyflag=1 if $c->county; $countyflag=1 if $c->{county}; + $cityflag=1 if ($c->{city} && $cityflag); #push @{$cust_main_county{$c->country}{$c->state}}, $c->county; #$cust_main_county{$c->country}{$c->state}{$c->county} = 1; - $cust_main_county{$c->{country}}{$c->{state}}{$c->{county}} = 1; + $cust_main_county{$c->{country}}{$c->{state}}{$c->{county}}{$c->{city}} = 1; } # } - $countyflag=1 if $param->{selected_county}; my $script_html = < - function opt(what,value,text) { - var optionName = new Option(text, value, false, false); + function opt(what,value,text,selected) { + var optionName = new Option(text, value, false, selected); var length = what.length; what.options[length] = optionName; } @@ -2500,8 +2503,37 @@ END #foreach my $county ( sort @{$cust_main_county{$country}{$state}} ) { foreach my $county ( sort keys %{$cust_main_county{$country}{$state}} ) { my $text = $county || '(n/a)'; - $script_html .= - qq!opt(what.form.${prefix}county, "$county", "$text");\n!; + if (!$county) { + if ( $cityflag) { + $script_html .= qq!what.form.${prefix}city.style.display='';\n + what.form.${prefix}city_select.style.display='none';\n! + } + $script_html .= qq!opt(what.form.${prefix}county, "$county", "$text");\n! + #$script_html .= qq!what.form.${prefix}county.style.display='none';\n! + } + else { + $script_html .= qq!var countySelected = false; if ("$param->{selected_county}" == "$text") { countySelected = true; }\n + opt(what.form.${prefix}county, "$county", "$text", countySelected);\n + what.form.${prefix}county.style.display='';\n + county = what.form.${prefix}county.options[what.form.${prefix}county.selectedIndex].text;\n!; + if ( $cityflag) { + $script_html .= qq!\nif ( county == \"$county\" ) {\n!; + foreach my $city ( sort keys %{$cust_main_county{$country}{$state}{$county}} ) { + my $text = $city || '(n/a)'; + if (!$city) { + $script_html .= qq!what.form.${prefix}city.style.display='';\n + what.form.${prefix}city_select.style.display='none';\n! + } + else { + $script_html .= qq!var citySelected = false; if ("$param->{selected_city}" == "$text") { citySelected = true; }\n + opt(what.form.${prefix}city_select, "$city", "$text", citySelected);\n + what.form.${prefix}city.style.display='none';\n + what.form.${prefix}city_select.style.display='';\n! + } + } + $script_html .= "}\n"; + } + } } $script_html .= "}\n"; } @@ -2511,12 +2543,89 @@ END $script_html .= <= 0; i-- ) + what.form.${prefix}city_select.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}} ) { + foreach my $county ( sort keys %{$cust_main_county{$country}{$state}} ) { + $script_html .= "\nif ( county == \"$county\" ) {\n"; + foreach my $city ( sort keys %{$cust_main_county{$country}{$state}{$county}} ) { + my $text = $city || '(n/a)'; + if (!$city) { + $script_html .= qq!what.form.${prefix}city.style.display='';\n + what.form.${prefix}city_select.style.display='none';\n! + } + else { + $script_html .= qq!var citySelected = false; if (saved_city == "$text") { citySelected = true; }\n + opt(what.form.${prefix}city_select, "$city", "$text", citySelected);\n + what.form.${prefix}city.style.display='none';\n + what.form.${prefix}city_select.style.display='';\n! + } + } + $script_html .= "}\n"; + } + $script_html .= "}\n"; + } + $script_html .= "}\n"; + } + } + + $script_html .= < END + my $city_html = ''; + if ( $cityflag ) { + if ( scalar (keys %{ $cust_main_county{$param->{'selected_country'}}{$param->{'selected_state'}}{$param->{'selected_county'}} }) > 1 ) { + $city_html .= qq!!; + } else { + $city_html .= qq! + !; + } + } + my $county_html = $script_html; if ( $countyflag ) { - $county_html .= qq!!; foreach my $county ( sort keys %{ $cust_main_county{$param->{'selected_country'}}{$param->{'selected_state'}} } ) { @@ -2570,7 +2679,7 @@ END } - ($county_html, $state_html, $country_html); + ($county_html, $state_html, $country_html, $city_html); } diff --git a/fs_selfservice/FS-SelfService/cgi/contact.html b/fs_selfservice/FS-SelfService/cgi/contact.html index 7ae0d4880..798af7090 100644 --- a/fs_selfservice/FS-SelfService/cgi/contact.html +++ b/fs_selfservice/FS-SelfService/cgi/contact.html @@ -42,14 +42,11 @@ - <%=$r%>City - - > - <%= - ($county_html, $state_html, $country_html) = + ($county_html, $state_html, $country_html, $city_html) = FS::SelfService::regionselector( { prefix => $pre, + selected_city => ${$pre.'city'}, selected_county => ${$pre.'county'}, selected_state => ${$pre.'state'}, selected_country => ${$pre.'country'}, @@ -58,6 +55,8 @@ locales => \@cust_main_county, } ); + $OUT .= qq!${r}City!; + $OUT .= qq!$city_html!; $OUT .= qq!${r}State/County!; $OUT .= qq!$county_html $state_html!; $OUT .= qq!${r}Zip!; @@ -73,7 +72,7 @@ <%= if ( $disabled ) { $OUT .= qq!var what = document.getElementById("${pre}city");!; - for (qw( county state country ) ) { + for (qw( city county state country ) ) { $OUT .= "what.form.$pre$_.disabled = true;"; $OUT .= "what.form.$pre$_.style.backgroundColor = '#dddddd';"; } -- 2.11.0