5 <& /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 style => [ 'attribute:value', 'another:value' ],
17 disable_empty => 1, #defaults to 1, set to 0 to disable the empty option
18 empty_label => 'all', #label for empty option
19 disable_text => 1, # disable the text input (just show the select)
20 #doesn't work as an option yet, set when conf tax_district_method
21 #disable_select => 1, # disable the selector (just show a text input)
26 % if ( $disable_select ) {
27 <SCRIPT TYPE="text/javascript">
28 function <% $pre %>county_changed(what, callback) {}
34 <% include('/elements/xmlhttp.html',
35 'url' => $p.'misc/cities.cgi',
36 'subs' => [ $pre. 'get_cities' ],
40 <SCRIPT TYPE="text/javascript">
42 function opt(what,value,text) {
43 var optionName = new Option(text, value, false, false);
44 var length = what.length;
45 what.options[length] = optionName;
48 var saved_<%$pre%>city= '<% $saved_city |h %>';
50 function <% $pre %>county_changed(what, callback) {
52 what.form.<% $pre %>city_select.disabled = 'disabled';
54 county = what.options[what.selectedIndex].value;
55 state = what.form.<% $pre %>state.options[what.form.<% $pre %>state.selectedIndex].value;
56 country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
58 function <% $pre %>update_cities(cities) {
60 // blank the current city list
61 for ( var i = what.form.<% $pre %>city_select.length; i >= 0; i-- )
62 what.form.<% $pre %>city_select.options[i] = null;
64 % unless ( $opt{disable_empty} ) {
65 opt( what.form.<% $pre %>city_select, '', <% $opt{empty_label} |js_string %> );
69 var citiesArray = eval('(' + cities + ')' );
71 for ( var s = 0; s < citiesArray.length; s++ ) {
72 var cityLabel = citiesArray[s];
73 if ( cityLabel == "" )
75 opt(what.form.<% $pre %>city_select, citiesArray[s], cityLabel);
78 if ( citiesArray.length > 1 || (citiesArray[0] && citiesArray[0].length) ){
79 // turn off the text city, turn on the select
80 saved_<%$pre%>city = what.form.<%$ pre %>city.value;
81 <%$pre%>city_select_changed(what.form.<% $pre %>city_select);
82 what.form.<% $pre %>city.style.display = 'none';
83 what.form.<% $pre %>city_select.style.display = '';
84 } else if ( what.form.<% $pre %>city.style.display == 'none' ) {
85 // turn on the text city, turn off the select
86 what.form.<%$ pre %>city.value = saved_<%$pre%>city;
87 what.form.<% $pre %>city.style.display = '';
88 what.form.<% $pre %>city_select.style.display = 'none';
91 what.form.<% $pre %>city_select.disabled = '';
94 if ( callback != null )
98 // go get the new cities
99 <% $pre %>get_cities( county, state, country, <% $pre %>update_cities );
103 function <%$pre%>city_select_changed(what) {
104 what.form.<%$pre%>city.value = what.options[what.selectedIndex].value;
111 <INPUT TYPE = "<% $opt{disable_text} ? 'hidden' : 'text' %>"
112 NAME = "<%$pre%>city"
114 VALUE = "<% $opt{'city'} |h %>"
115 % unless ( $opt{disable_text} ) {
116 onChange = "<% $opt{'onchange'} %>"
117 <% $opt{'disabled'} %>
122 % if ( $disable_select ) {
124 <INPUT TYPE="hidden" ID="city_select">
127 <SELECT NAME = "<%$pre%>city_select"
128 ID = "<%$pre%>city_select"
129 onChange = "<%$pre%>city_select_changed(this); <% $opt{onchange} %>"
134 % unless ( $opt{'disable_empty'} ) {
135 <OPTION VALUE="" <% $opt{city} eq '' ? 'SELECTED' : '' %>><% $opt{empty_label} %>
138 % foreach my $city ( @cities ) {
140 <OPTION VALUE="<% $city |h %>"
141 <% $city eq $opt{city} ? 'SELECTED' : '' %>
142 ><% $city eq $opt{empty_data_value} ? $opt{empty_data_label} : $city %>
153 my $pre = $opt{'prefix'};
155 my $conf = new FS::Conf;
156 # Using tax_district_method implies that there's not a preloaded city/county
157 # tax district table.
158 my $disable_select = 1 if $conf->config('tax_district_method');
160 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
162 if ($conf->exists('cust_main-no_city_in_address')) {
163 $opt{'disable_text'} = 1;
167 my $text_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
168 my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
170 push @$text_style, @{ $opt{'text_style'} } if $opt{'text_style'};
171 push @$select_style, @{ $opt{'select_style'} } if $opt{'select_style'};
173 my @cities = cities( $opt{'county'}, $opt{'state'}, $opt{'country'} );
175 if ( scalar(@cities) > 1 || $cities[0] and !$disable_select ) {
176 push @$text_style, 'display:none';
178 push @$select_style, 'display:none';
179 $saved_city = $opt{'city'};
184 ? 'STYLE="'. join(';', @$text_style). '"'
188 scalar(@$select_style)
189 ? 'STYLE="'. join(';', @$select_style). '"'