summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate')
-rwxr-xr-xhttemplate/edit/cust_main.cgi14
-rw-r--r--httemplate/edit/cust_main/select-county.html52
-rw-r--r--httemplate/misc/counties.cgi43
3 files changed, 75 insertions, 34 deletions
diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi
index e2ed0f1da..896472d2b 100755
--- a/httemplate/edit/cust_main.cgi
+++ b/httemplate/edit/cust_main.cgi
@@ -204,17 +204,19 @@ function bill_changed(what) {
what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
% }
-
what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
+
+ function fix_ship_county() {
+ what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
+ }
+
function fix_ship_state() {
what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
+ ship_state_changed(what.form.ship_state, fix_ship_county );
}
+
ship_country_changed(what.form.ship_country, fix_ship_state );
- function fix_ship_county() {
- what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
- }
- ship_state_changed(what.form.ship_state, fix_ship_county );
}
}
function samechanged(what) {
@@ -242,7 +244,7 @@ function samechanged(what) {
% my $disabledselect = '';
% unless ( $cust_main->ship_last && $same ne 'Y' ) {
% $checked = 'CHECKED';
-% $disabled = 'DISABLED style="background-color: #dddddd"';
+% $disabled = 'DISABLED STYLE="background-color: #dddddd"';
% foreach (
% qw( last first company address1 address2 city county state zip country
% daytime night fax )
diff --git a/httemplate/edit/cust_main/select-county.html b/httemplate/edit/cust_main/select-county.html
index c9b64bf4f..5b068214e 100644
--- a/httemplate/edit/cust_main/select-county.html
+++ b/httemplate/edit/cust_main/select-county.html
@@ -16,8 +16,8 @@
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;
+ state = what.options[what.selectedIndex].value;
+ country = what.form.<% $opt{'prefix'} %>country.options[what.form.<% $opt{'prefix'} %>country.selectedIndex].value;
function <% $opt{'prefix'} %>update_counties(counties) {
@@ -34,6 +34,12 @@
opt(what.form.<% $opt{'prefix'} %>county, countiesArray[s], countyLabel);
}
+ if ( countiesArray.length > 1 ) {
+ what.form.<% $opt{'prefix'} %>county.style.display = '';
+ } else {
+ what.form.<% $opt{'prefix'} %>county.style.display = 'none';
+ }
+
//run the callback
if ( callback != null )
callback();
@@ -47,14 +53,8 @@
</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'},
-% }
-% )
-% ) {
+
+% foreach my $county ( @counties ) {
<OPTION VALUE="<% $county %>"<% $county eq $opt{'county'} ? ' SELECTED' : '' %>><% $county %>
@@ -75,14 +75,44 @@
% }
<%init>
+
my %opt = @_;
foreach my $opt (qw( county state country prefix onchange disabled )) {
$opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
}
+my @counties = ();
+if ( $countyflag ) {
+
+ @counties =
+ sort
+ map { $_->county }
+ qsearch( {
+ 'select' => 'DISTINCT county',
+ 'table' => 'cust_main_county',
+ 'hashref' => { 'state' => $opt{'state'},
+ 'country' => $opt{'country'},
+ },
+ } );
+
+ # this is very hacky
+ unless ( scalar(@counties) > 1 ) {
+ if ( $opt{'disabled'} =~ /STYLE=/i ) {
+ $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
+ } else {
+ $opt{'disabled'} .= ' STYLE="display:none"';
+ }
+ }
+
+}
+
+</%init>
+<%once>
+
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];
-</%init>
+
+</%once>
diff --git a/httemplate/misc/counties.cgi b/httemplate/misc/counties.cgi
index c9eb98500..940cba7dc 100644
--- a/httemplate/misc/counties.cgi
+++ b/httemplate/misc/counties.cgi
@@ -1,18 +1,27 @@
-%
-%
-% my( $state, $country ) = $cgi->param('arg');
-%
-% my @counties =
-% sort
-% map { s/[\n\r]//g; $_; }
-% map { $_->county; }
-% qsearch( 'cust_main_county',
-% { 'state' => $state,
-% 'country' => $country,
-% },
-% )
-% ;
-%
-%
-%
[ <% 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;
+
+</%init>