summaryrefslogtreecommitdiff
path: root/httemplate/edit/cust_main
diff options
context:
space:
mode:
authorivan <ivan>2005-09-10 14:50:57 +0000
committerivan <ivan>2005-09-10 14:50:57 +0000
commit9e342300c380e29af1b9678f1a9604609e0061b6 (patch)
tree72d0edb8de70b19465264c76669045b0ba202e6e /httemplate/edit/cust_main
parent3502e0627909ea99683d1724adb0d4a3fee578b2 (diff)
ajax-style xmlhttprequest state/county/country selector!
Diffstat (limited to 'httemplate/edit/cust_main')
-rw-r--r--httemplate/edit/cust_main/contact.html32
-rw-r--r--httemplate/edit/cust_main/select-country.html68
-rw-r--r--httemplate/edit/cust_main/select-county.html87
-rw-r--r--httemplate/edit/cust_main/select-state.html27
4 files changed, 204 insertions, 10 deletions
diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html
index d3b7b167f..e0cd06f56 100644
--- a/httemplate/edit/cust_main/contact.html
+++ b/httemplate/edit/cust_main/contact.html
@@ -14,14 +14,23 @@ $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($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';
@@ -75,7 +84,10 @@ my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
<INPUT TYPE="text" NAME="<%=$pre%>city" VALUE="<%= $cust_main->get($pre.'city') %>" onChange="<%= $onchange %>" <%=$disabled%>>
</TD>
<TH ALIGN="right"><%=$r%>State</TH>
- <TD><%= $county_html. $state_html %></TD>
+ <TD>
+ <%= include('select-county.html', %select_hash ) %>
+ <%= include('select-state.html', %select_hash ) %>
+ </TD>
<TH><%=$r%>Zip</TH>
<TD>
<INPUT TYPE="text" NAME="<%=$pre%>zip" VALUE="<%= $cust_main->get($pre.'zip') %>" SIZE=10 onChange="<%= $onchange %>" <%=$disabled%>>
@@ -84,7 +96,7 @@ my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
<TR>
<TH ALIGN="right"><%=$r%>Country</TH>
- <TD><%= $country_html %></TD>
+ <TD><%= include('select-country.html', %select_hash ) %></TD>
</TR>
<TR>
diff --git a/httemplate/edit/cust_main/select-country.html b/httemplate/edit/cust_main/select-country.html
new file mode 100644
index 000000000..44f4f0a55
--- /dev/null
+++ b/httemplate/edit/cust_main/select-country.html
@@ -0,0 +1,68 @@
+<%
+
+ my %opt = @_;
+ foreach my $opt (qw( county state country prefix onchange disabled )) {
+ $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
+ }
+
+ my $conf = new FS::Conf;
+ my $countrydefault = $conf->config('countrydefault') || 'US';
+
+%>
+
+<%= include('/elements/xmlhttp.html', $p.'misc/states.cgi', $opt{'prefix'}. 'get_states') %>
+
+<SCRIPT TYPE="text/javascript">
+
+ function opt(what,value,text) {
+ var optionName = new Option(text, value, false, false);
+ var length = what.length;
+ what.options[length] = optionName;
+ }
+
+ function <%= $opt{'prefix'} %>country_changed(what, callback) {
+
+ country = what.options[what.selectedIndex].text;
+
+ function <%= $opt{'prefix'} %>update_states(states) {
+
+ // blank the current state list
+ for ( var i = what.form.<%= $opt{'prefix'} %>state.length; i >= 0; i-- )
+ what.form.<%= $opt{'prefix'} %>state.options[i] = null;
+
+ // add the new states
+ var statesArray = eval('(' + states + ')' );
+ for ( var s = 0; s < statesArray.length; s++ ) {
+ var stateLabel = statesArray[s];
+ if ( stateLabel == "" )
+ stateLabel = '(n/a)';
+ opt(what.form.<%= $opt{'prefix'} %>state, statesArray[s], stateLabel);
+ }
+
+ //run the callback
+ if ( callback != null )
+ callback();
+ }
+
+ // go get the new states
+ <%= $opt{'prefix'} %>get_states( country, <%= $opt{'prefix'} %>update_states );
+
+ }
+
+</SCRIPT>
+
+<SELECT NAME="<%= $opt{'prefix'} %>country" onChange="<%= $opt{'prefix'} %>country_changed(this); <%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
+
+<% foreach my $country (
+ sort { ($b eq $countrydefault) <=> ($a eq $countrydefault) or $a cmp $b }
+ map { $_->country }
+ qsearch( 'cust_main_county',{}, 'DISTINCT ON ( country ) *', )
+ ) {
+%>
+
+ <OPTION VALUE="<%= $country %>"<%= $country eq $opt{'country'} ? ' SELECTED' : '' %>><%= $country %>
+
+<% } %>
+
+</SELECT>
+
diff --git a/httemplate/edit/cust_main/select-county.html b/httemplate/edit/cust_main/select-county.html
new file mode 100644
index 000000000..70a8f9477
--- /dev/null
+++ b/httemplate/edit/cust_main/select-county.html
@@ -0,0 +1,87 @@
+<%
+
+ my %opt = @_;
+ foreach my $opt (qw( county state country prefix onchange disabled )) {
+ $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
+ }
+
+ my $sql = "SELECT COUNT(*) FROM cust_main_county".
+ " WHERE county IS NOT NULL AND county != ''";
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+ my $countyflag = $sth->fetchrow_arrayref->[0];
+
+%>
+
+<% if ( $countyflag ) { %>
+
+ <%= include('/elements/xmlhttp.html', $p.'misc/counties.cgi', $opt{'prefix'}. 'get_counties' ) %>
+
+ <SCRIPT TYPE="text/javascript">
+
+ function opt(what,value,text) {
+ var optionName = new Option(text, value, false, false);
+ var length = what.length;
+ what.options[length] = optionName;
+ }
+
+ function <%= $opt{'prefix'} %>state_changed(what, callback) {
+
+ state = what.options[what.selectedIndex].text;
+ country = what.form.<%= $opt{'prefix'} %>country.options[what.form.<%= $opt{'prefix'} %>country.selectedIndex].text;
+
+ function <%= $opt{'prefix'} %>update_counties(counties) {
+
+ // blank the current county list
+ for ( var i = what.form.<%= $opt{'prefix'} %>county.length; i >= 0; i-- )
+ what.form.<%= $opt{'prefix'} %>county.options[i] = null;
+
+ // add the new counties
+ var countiesArray = eval('(' + counties + ')' );
+ for ( var s = 0; s < countiesArray.length; s++ ) {
+ var countyLabel = countiesArray[s];
+ if ( countyLabel == "" )
+ countyLabel = '(n/a)';
+ opt(what.form.<%= $opt{'prefix'} %>county, countiesArray[s], countyLabel);
+ }
+
+ //run the callback
+ if ( callback != null )
+ callback();
+ }
+
+ // go get the new counties
+ <%= $opt{'prefix'} %>get_counties( state, country, <%= $opt{'prefix'} %>update_counties );
+
+ }
+
+ </SCRIPT>
+
+ <SELECT NAME="<%= $opt{'prefix'} %>county" onChange="<%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
+
+ <% foreach my $county (
+ sort
+ map { $_->county }
+ qsearch('cust_main_county', { 'state' => $opt{'state'},
+ 'country' => $opt{'country'},
+ }
+ )
+ ) {
+ %>
+
+ <OPTION VALUE="<%= $county %>"<%= $county eq $opt{'county'} ? ' SELECTED' : '' %>><%= $county %>
+
+ <% } %>
+
+ </SELECT>
+
+<% } else { %>
+
+ <SCRIPT TYPE="text/javascript">
+ function <%= $opt{'prefix'} %>state_changed(what) {
+ }
+ </SCRIPT>
+
+ <INPUT TYPE="hidden" NAME="<%= $opt{'prefix'} %>county" VALUE="<%= $opt{'county'} %>">
+
+<% } %>
diff --git a/httemplate/edit/cust_main/select-state.html b/httemplate/edit/cust_main/select-state.html
new file mode 100644
index 000000000..98e685ab8
--- /dev/null
+++ b/httemplate/edit/cust_main/select-state.html
@@ -0,0 +1,27 @@
+<%
+
+ my %opt = @_;
+ foreach my $opt (qw( county state country prefix onchange disabled )) {
+ $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
+ }
+
+%>
+
+<SELECT NAME="<%= $opt{'prefix'} %>state" onChange="<%= $opt{'prefix'} %>state_changed(this); <%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
+
+<% foreach my $state (
+ sort
+ map { $_->state }
+ qsearch( 'cust_main_county',
+ { 'country' => $opt{'country'} },
+ 'DISTINCT ON ( state ) *',
+ )
+ ) {
+%>
+
+ <OPTION VALUE="<%= $state %>"<%= $state eq $opt{'state'} ? ' SELECTED' : '' %>><%= $state || '(n/a)' %>
+
+<% } %>
+
+</SELECT>
+