Merge branch 'master' of https://github.com/jgoodman/Freeside
[freeside.git] / httemplate / elements / city.html
index 1659ebf..6a2142f 100644 (file)
@@ -15,11 +15,20 @@ Example:
     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' ],
   );
 
 </%doc>
 
+% if ( $disable_select ) {
+<SCRIPT TYPE="text/javascript">
+function <% $pre %>county_changed(what, callback) {}
+</SCRIPT>
+% }
+% else {
+
+
 <% include('/elements/xmlhttp.html',
               'url'  => $p.'misc/cities.cgi',
               'subs' => [ $pre. 'get_cities' ],
@@ -34,7 +43,7 @@ Example:
     what.options[length] = optionName;
   }
 
-  var saved_<%$pre%>city= '';
+  var saved_<%$pre%>city= '<% $saved_city |h %>';
 
   function <% $pre %>county_changed(what, callback) {
 
@@ -61,9 +70,10 @@ Example:
      if ( citiesArray.length > 1 || 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);
         what.form.<% $pre %>city.style.display = 'none';
         what.form.<% $pre %>city_select.style.display = '';
-      } else {
+      } else if ( what.form.<% $pre %>city.style.display == 'none' ) {
         // turn on the text city, turn off the select
         what.form.<%$ pre %>city.value = saved_<%$pre%>city;
         what.form.<% $pre %>city.style.display = '';
@@ -86,6 +96,8 @@ Example:
 
 </SCRIPT>
 
+% } #!disable_select
+
 <INPUT TYPE     = "text"
        NAME     = "<%$pre%>city"
        ID       = "<%$pre%>city"
@@ -95,6 +107,12 @@ Example:
        <% $text_style %>
 >
 
+% if ( $disable_select ) {
+%# avoid JS errors
+<INPUT TYPE="hidden" ID="city_select">
+% }
+% else {
+
 <SELECT NAME     = "<%$pre%>city_select"
         ID       = "<%$pre%>city_select"
         onChange = "<%$pre%>city_select_changed(this); <% $opt{'onchange'} %>"
@@ -111,7 +129,7 @@ Example:
 % }
 
 </SELECT>
-
+% }
 %#           VALUE    = "<% $curr_value |h %>"
 <%init>
 
@@ -119,14 +137,24 @@ my %opt = @_;
 
 my $pre = $opt{'prefix'};
 
+my $conf = new FS::Conf;
+# Using tax_district_method implies that there's not a preloaded city/county
+# tax district table.
+my $disable_select = 1 if $conf->config('tax_district_method');
+
 my $text_style   = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
 my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
 
+push @$text_style,   @{ $opt{'text_style'} }   if $opt{'text_style'};
+push @$select_style, @{ $opt{'select_style'} } if $opt{'select_style'};
+
 my @cities = cities( $opt{'county'}, $opt{'state'}, $opt{'country'} );
-if ( scalar(@cities) > 1 || $cities[0] ) {
+my $saved_city = '';
+if ( scalar(@cities) > 1 || $cities[0] and !$disable_select ) {
   push @$text_style, 'display:none';
 } else {
   push @$select_style, 'display:none';
+  $saved_city = $opt{'city'};
 }
 
 $text_style =