5 include( '/elements/city.html',
7 country => $current_country,
8 state => $current_state,
9 county => $current_county,
10 city => $current_city,
13 prefix => $optional_unique_prefix,
14 onchange => $javascript,
16 # disable_empty => 1, #defaults to 1, disable the empty option
17 # empty_label => 'all', #label for empty option
18 # disable_select => 1, # disable the selector (just show a text input)
19 style => [ 'attribute:value', 'another:value' ],
24 % if ( $disable_select ) {
25 <SCRIPT TYPE="text/javascript">
26 function <% $pre %>county_changed(what, callback) {}
32 <% include('/elements/xmlhttp.html',
33 'url' => $p.'misc/cities.cgi',
34 'subs' => [ $pre. 'get_cities' ],
38 <SCRIPT TYPE="text/javascript">
40 function opt(what,value,text) {
41 var optionName = new Option(text, value, false, false);
42 var length = what.length;
43 what.options[length] = optionName;
46 var saved_<%$pre%>city= '<% $saved_city |h %>';
48 function <% $pre %>county_changed(what, callback) {
50 county = what.options[what.selectedIndex].value;
51 state = what.form.<% $pre %>state.options[what.form.<% $pre %>state.selectedIndex].value;
52 country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
54 function <% $pre %>update_cities(cities) {
56 // blank the current city list
57 for ( var i = what.form.<% $pre %>city_select.length; i >= 0; i-- )
58 what.form.<% $pre %>city_select.options[i] = null;
61 var citiesArray = eval('(' + cities + ')' );
63 for ( var s = 0; s < citiesArray.length; s++ ) {
64 var cityLabel = citiesArray[s];
65 if ( cityLabel == "" )
67 opt(what.form.<% $pre %>city_select, citiesArray[s], cityLabel);
70 if ( citiesArray.length > 1 || citiesArray[0].length ) {
71 // turn off the text city, turn on the select
72 saved_<%$pre%>city = what.form.<%$ pre %>city.value;
73 <%$pre%>city_select_changed(what.form.<% $pre %>city_select);
74 what.form.<% $pre %>city.style.display = 'none';
75 what.form.<% $pre %>city_select.style.display = '';
76 } else if ( what.form.<% $pre %>city.style.display == 'none' ) {
77 // turn on the text city, turn off the select
78 what.form.<%$ pre %>city.value = saved_<%$pre%>city;
79 what.form.<% $pre %>city.style.display = '';
80 what.form.<% $pre %>city_select.style.display = 'none';
84 if ( callback != null )
88 // go get the new cities
89 <% $pre %>get_cities( county, state, country, <% $pre %>update_cities );
93 function <%$pre%>city_select_changed(what) {
94 what.form.<%$pre%>city.value = what.options[what.selectedIndex].value;
102 NAME = "<%$pre%>city"
104 VALUE = "<% $opt{'city'} |h %>"
105 onChange = "<% $opt{'onchange'} %>"
106 <% $opt{'disabled'} %>
110 % if ( $disable_select ) {
112 <INPUT TYPE="hidden" ID="city_select">
116 <SELECT NAME = "<%$pre%>city_select"
117 ID = "<%$pre%>city_select"
118 onChange = "<%$pre%>city_select_changed(this); <% $opt{'onchange'} %>"
119 <% $opt{'disabled'} %>
123 % foreach my $city ( @cities ) {
125 <OPTION VALUE="<% $city |h %>"
126 <% $city eq $opt{'city'} ? 'SELECTED' : '' %>
127 ><% $city eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $city %>
133 %# VALUE = "<% $curr_value |h %>"
138 my $pre = $opt{'prefix'};
140 my $conf = new FS::Conf;
141 # Using tax_district_method implies that there's not a preloaded city/county
142 # tax district table.
143 my $disable_select = 1 if $conf->config('tax_district_method');
145 my $text_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
146 my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
148 push @$text_style, @{ $opt{'text_style'} } if $opt{'text_style'};
149 push @$select_style, @{ $opt{'select_style'} } if $opt{'select_style'};
151 my @cities = cities( $opt{'county'}, $opt{'state'}, $opt{'country'} );
153 if ( scalar(@cities) > 1 || $cities[0] and !$disable_select ) {
154 push @$text_style, 'display:none';
156 push @$select_style, 'display:none';
157 $saved_city = $opt{'city'};
162 ? 'STYLE="'. join(';', @$text_style). '"'
166 scalar(@$select_style)
167 ? 'STYLE="'. join(';', @$select_style). '"'