[freeside-commits] freeside/httemplate/edit/cust_main
select-county.html, NONE, 1.1 select-state.html, NONE,
1.1 select-country.html, NONE, 1.1 contact.html, 1.2, 1.3
Ivan,,,
ivan at wavetail.420.am
Sat Sep 10 07:50:58 PDT 2005
Update of /home/cvs/cvsroot/freeside/httemplate/edit/cust_main
In directory wavetail:/tmp/cvs-serv31587/httemplate/edit/cust_main
Modified Files:
contact.html
Added Files:
select-county.html select-state.html select-country.html
Log Message:
ajax-style xmlhttprequest state/county/country selector!
--- NEW FILE: select-country.html ---
<%
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>
--- NEW FILE: select-state.html ---
<%
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>
Index: contact.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/cust_main/contact.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- contact.html 24 Aug 2005 13:22:26 -0000 1.2
+++ contact.html 10 Sep 2005 14:50:56 -0000 1.3
@@ -14,14 +14,23 @@
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 @@
<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 @@
<TR>
<TH ALIGN="right"><%=$r%>Country</TH>
- <TD><%= $country_html %></TD>
+ <TD><%= include('select-country.html', %select_hash ) %></TD>
</TR>
<TR>
--- NEW FILE: select-county.html ---
<%
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'} %>">
<% } %>
More information about the freeside-commits
mailing list