From ceeaad3d99869f159bf2fee490aafa4c95d03365 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 7 Jan 2015 14:30:15 -0800 Subject: [PATCH] add city search, RT#31659 --- FS/FS/cust_main/Search.pm | 12 ++++ httemplate/elements/city.html | 87 ++++++++++++++---------- httemplate/elements/select-country.html | 4 ++ httemplate/elements/select-county.html | 22 ++++-- httemplate/search/cust_main.html | 2 +- httemplate/search/report_cust_main.html | 114 ++++++++++++++++++++------------ 6 files changed, 156 insertions(+), 85 deletions(-) diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 461633a72..f0a7d4137 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -728,6 +728,18 @@ sub search { } ## + # city + ## + if ( $params->{'city'} =~ /\S/ ) { + my $city = dbh->quote($params->{'city'}); + push @where, "EXISTS( + SELECT 1 FROM cust_location + WHERE cust_location.custnum = cust_main.custnum + AND cust_location.city = $city + )"; + } + + ## # county ## if ( $params->{'county'} =~ /\S/ ) { diff --git a/httemplate/elements/city.html b/httemplate/elements/city.html index 6a2142f29..5f4d4e09e 100644 --- a/httemplate/elements/city.html +++ b/httemplate/elements/city.html @@ -2,22 +2,24 @@ Example: - include( '/elements/city.html', - #recommended - country => $current_country, - state => $current_state, - county => $current_county, - city => $current_city, - - #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_select => 1, # disable the selector (just show a text input) - style => [ 'attribute:value', 'another:value' ], - ); + <& /elements/city.html, + #recommended + country => $current_country, + state => $current_state, + county => $current_county, + city => $current_city, + + #optional + prefix => $optional_unique_prefix, + onchange => $javascript, + disabled => 0, #bool + style => [ 'attribute:value', 'another:value' ], + disable_empty => 1, #defaults to 1, set to 0 to disable the empty option + empty_label => 'all', #label for empty option + disable_text => 1, # disable the text input (just show the select) + #doesn't work as an option yet, set when conf tax_district_method + #disable_select => 1, # disable the selector (just show a text input) + &> @@ -47,16 +49,22 @@ function <% $pre %>county_changed(what, callback) {} function <% $pre %>county_changed(what, callback) { + what.form.<% $pre %>city_select.disabled = 'disabled'; + county = what.options[what.selectedIndex].value; state = what.form.<% $pre %>state.options[what.form.<% $pre %>state.selectedIndex].value; country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value; function <% $pre %>update_cities(cities) { - + // blank the current city list for ( var i = what.form.<% $pre %>city_select.length; i >= 0; i-- ) what.form.<% $pre %>city_select.options[i] = null; +% unless ( $opt{disable_empty} ) { + opt( what.form.<% $pre %>city_select, '', <% $opt{empty_label} |js_string %> ); +% } + // add the new cities var citiesArray = eval('(' + cities + ')' ); @@ -67,7 +75,7 @@ function <% $pre %>county_changed(what, callback) {} opt(what.form.<% $pre %>city_select, citiesArray[s], cityLabel); } - if ( citiesArray.length > 1 || citiesArray[0].length ) { + if ( citiesArray.length > 1 || (citiesArray[0] && citiesArray[0].length) ){ // turn off the text city, turn on the select saved_<%$pre%>city = what.form.<%$ pre %>city.value; <%$pre%>city_select_changed(what.form.<% $pre %>city_select); @@ -80,6 +88,8 @@ function <% $pre %>county_changed(what, callback) {} what.form.<% $pre %>city_select.style.display = 'none'; } + what.form.<% $pre %>city_select.disabled = ''; + //run the callback if ( callback != null ) callback(); @@ -98,39 +108,44 @@ function <% $pre %>county_changed(what, callback) {} % } #!disable_select - <% $text_style %> +% } > % if ( $disable_select ) { %# avoid JS errors - -% } -% else { + +% } else { - + <% $select_style %> + > -% foreach my $city ( @cities ) { +% unless ( $opt{'disable_empty'} ) { +