Add a (magically appearing and disappearing) label on the county selector. confusing...
authorivan <ivan>
Wed, 27 Dec 2006 02:37:17 +0000 (02:37 +0000)
committerivan <ivan>
Wed, 27 Dec 2006 02:37:17 +0000 (02:37 +0000)
FS/FS/Misc.pm
htetc/handler.pl
httemplate/edit/cust_main/contact.html
httemplate/edit/cust_main/select-county.html
httemplate/misc/counties.cgi

index 97ff8ed..5d74adf 100644 (file)
@@ -7,7 +7,10 @@ use Carp;
 use Data::Dumper;
 
 @ISA = qw( Exporter );
-@EXPORT_OK = qw( send_email send_fax states_hash state_label card_types );
+@EXPORT_OK = qw( send_email send_fax
+                 states_hash counties state_label
+                 card_types
+               );
 
 $DEBUG = 0;
 
@@ -359,13 +362,12 @@ sub states_hash {
 #     sort
      map { s/[\n\r]//g; $_; }
      map { $_->state; }
-     qsearch({ 
-               'select'    => 'state',
-               'table'     => 'cust_main_county',
-               'hashref'   => { 'country' => $country },
-               'extra_sql' => 'GROUP BY state',
-            })
-  ;
+         qsearch({ 
+                   'select'    => 'state',
+                   'table'     => 'cust_main_county',
+                   'hashref'   => { 'country' => $country },
+                   'extra_sql' => 'GROUP BY state',
+                });
 
   #it could throw a fatal "Invalid country code" error (for example "AX")
   my $subcountry = eval { new Locale::SubCountry($country) }
@@ -378,6 +380,26 @@ sub states_hash {
        @states;
 }
 
+=item counties STATE COUNTRY
+
+Returns a list of counties for this state and country.
+
+=cut
+
+sub counties {
+  my( $state, $country ) = @_;
+
+  sort map { s/[\n\r]//g; $_; }
+       map { $_->county }
+           qsearch({
+             'select'  => 'DISTINCT county',
+             'table'   => 'cust_main_county',
+             'hashref' => { 'state'   => $state,
+                            'country' => $country,
+                          },
+           });
+}
+
 =item state_label STATE COUNTRY_OR_LOCALE_SUBCOUNRY_OBJECT
 
 =cut
index 2272e26..f47d4c9 100644 (file)
@@ -129,7 +129,7 @@ sub handler
                      eidiot small_custview myexit http_header);
       use FS::UI::Web;
       use FS::Msgcat qw(gettext geterror);
-      use FS::Misc qw( send_email send_fax states_hash state_label );
+      use FS::Misc qw( send_email send_fax states_hash counties state_label );
       use FS::Report::Table::Monthly;
       use FS::TicketSystem;
 
index a001634..e813986 100644 (file)
@@ -1,50 +1,8 @@
-%
-%
-%my( $cust_main, $pre, $onchange, $disabled ) = @_;
-%my $conf = new FS::Conf;
-%
-%#false laziness with ship state
-%my $countrydefault = $conf->config('countrydefault') || 'US';
-%$cust_main->set($pre.'country', $countrydefault )
-%  unless $cust_main->get($pre.'country');
-%
-%my $statedefault = $conf->config('statedefault')
-%                   || ($countrydefault eq 'US' ? 'CA' : '');
-%$cust_main->set($pre.'state', $statedefault )
-%  unless $cust_main->get($pre.'state')
-%         || $cust_main->get($pre.'country') ne $countrydefault;
-%
-%#my($county_html, $state_html, $country_html) =
-%#  FS::cust_main_county::regionselector( $cust_main->get($pre.'county'),
-%#                                        $cust_main->get($pre.'state'),
-%#                                        $cust_main->get($pre.'country'),
-%#                                        $pre,
-%#                                        $onchange,
-%#                                        $disabled,
-%#                                      );
-%
-%my %select_hash = (
-%  'county'   => $cust_main->get($pre.'county'),
-%  'state'    => $cust_main->get($pre.'state'),
-%  'country'  => $cust_main->get($pre.'country'),
-%  'prefix'   => $pre,
-%  'onchange' => $onchange,
-%  'disabled' => $disabled,
-%);
-%
-%my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone';
-%my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone';
-%
-%my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
-%
-%
-
-
 <% &ntable("#cccccc") %>
 
 <TR>
   <TH ALIGN="right"><%$r%>Contact&nbsp;name<BR>(last,&nbsp;first)</TH>
-  <TD COLSPAN=3>
+  <TD COLSPAN=5>
     <INPUT TYPE="text" NAME="<%$pre%>last" VALUE="<% $cust_main->get($pre.'last') %>" onChange="<% $onchange %>" <%$disabled%>> , 
     <INPUT TYPE="text" NAME="<%$pre%>first" VALUE="<% $cust_main->get($pre.'first') %>" onChange="<% $onchange %>" <%$disabled%>>
   </TD>
 
 <TR>
   <TD ALIGN="right">Company</TD>
-  <TD COLSPAN=5>
+  <TD COLSPAN=7>
     <INPUT TYPE="text" NAME="<%$pre%>company" VALUE="<% $cust_main->get($pre.'company') %>" SIZE=70 onChange="<% $onchange %>" <%$disabled%>>
   </TD>
 </TR>
 
 <TR>
   <TH ALIGN="right"><%$r%>Address</TH>
-  <TD COLSPAN=5>
+  <TD COLSPAN=7>
     <INPUT TYPE="text" NAME="<%$pre%>address1" VALUE="<% $cust_main->get($pre.'address1') %>" SIZE=70 onChange="<% $onchange %>" <%$disabled%>>
   </TD>
 </TR>
 
 <TR>
   <TD ALIGN="right">&nbsp;</TD>
-  <TD COLSPAN=5>
+  <TD COLSPAN=7>
     <INPUT TYPE="text" NAME="<%$pre%>address2" VALUE="<% $cust_main->get($pre.'address2') %>" SIZE=70 onChange="<% $onchange %>" <%$disabled%>>
   </TD>
 </TR>
   <TD>
     <INPUT TYPE="text" NAME="<%$pre%>city" VALUE="<% $cust_main->get($pre.'city') %>" onChange="<% $onchange %>" <%$disabled%>>
   </TD>
-  <TH ALIGN="right"><%$r%>State</TH>
+  <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
   <TD>
     <% include('select-county.html', %select_hash ) %>
+  </TD>
+  <TH ALIGN="right"><%$r%>State</TH>
+  <TD>
     <% include('select-state.html', %select_hash ) %>
   </TD>
   <TH><%$r%>Zip</TH>
 </TABLE>
 <%$r%>required fields<BR>
 
+<%init>
+
+my( $cust_main, $pre, $onchange, $disabled ) = @_;
+my $conf = new FS::Conf;
+
+#false laziness with ship state
+my $countrydefault = $conf->config('countrydefault') || 'US';
+$cust_main->set($pre.'country', $countrydefault )
+  unless $cust_main->get($pre.'country');
+
+my $statedefault = $conf->config('statedefault')
+                   || ($countrydefault eq 'US' ? 'CA' : '');
+$cust_main->set($pre.'state', $statedefault )
+  unless $cust_main->get($pre.'state')
+         || $cust_main->get($pre.'country') ne $countrydefault;
+
+#my($county_html, $state_html, $country_html) =
+#  FS::cust_main_county::regionselector( $cust_main->get($pre.'county'),
+#                                        $cust_main->get($pre.'state'),
+#                                        $cust_main->get($pre.'country'),
+#                                        $pre,
+#                                        $onchange,
+#                                        $disabled,
+#                                      );
+
+my %select_hash = (
+  'county'   => $cust_main->get($pre.'county'),
+  'state'    => $cust_main->get($pre.'state'),
+  'country'  => $cust_main->get($pre.'country'),
+  'prefix'   => $pre,
+  'onchange' => $onchange,
+  'disabled' => $disabled,
+);
+
+my @counties = counties( $cust_main->get($pre.'state'),
+                         $cust_main->get($pre.'country'),
+                       );
+my $county_style = scalar(@counties) > 1 ? '' : 'STYLE="visibility:hidden"';
+
+my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone';
+my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone';
+
+my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
+
+</%init>
index 5b06821..0dc8268 100644 (file)
             opt(what.form.<% $opt{'prefix'} %>county, countiesArray[s], countyLabel);
         }
 
+        var countyFormLabel = document.getElementById('<% $opt{'prefix'} %>countylabel');
+
         if ( countiesArray.length > 1 ) { 
           what.form.<% $opt{'prefix'} %>county.style.display = '';
+          countyFormLabel.style.visibility = 'visible';
         } else {
           what.form.<% $opt{'prefix'} %>county.style.display = 'none';
+          countyFormLabel.style.visibility = 'hidden';
         }
 
         //run the callback
@@ -84,16 +88,7 @@ foreach my $opt (qw( county state country prefix onchange disabled )) {
 my @counties = ();
 if ( $countyflag ) {
 
-  @counties =
-      sort
-      map { $_->county }
-      qsearch( {
-        'select'  => 'DISTINCT county',
-        'table'   => 'cust_main_county',
-        'hashref' => { 'state'   => $opt{'state'},
-                       'country' => $opt{'country'},
-                     },
-      } );
+  @counties = counties( $opt{'state'}, $opt{'country'} );
 
   # this is very hacky
   unless ( scalar(@counties) > 1 ) {
index 940cba7..c022a27 100644 (file)
@@ -1,27 +1,7 @@
 [ <% join(', ', map { qq("$_") } @counties) %> ]
 <%init>
 
-my $DEBUG = 0;
-
 my( $state, $country ) = $cgi->param('arg');
-
-warn "fetching counties for $state / $country \n"
-  if $DEBUG;
-
-my @counties = 
-    sort
-    map { s/[\n\r]//g; $_; }
-    map { $_->county; }
-    qsearch( {
-      'select'  => 'DISTINCT county',
-      'table'   => 'cust_main_county',
-      'hashref' => { 'state'   => $state,
-                     'country' => $country,
-                   },
-    } )
-;
-
-warn "counties: ". join(', ', map { qq("$_") } @counties). "\n"
-  if $DEBUG;
+my @counties = counties($state, $country);
 
 </%init>