diff options
Diffstat (limited to 'httemplate/elements')
-rw-r--r-- | httemplate/elements/city.html | 142 | ||||
-rw-r--r-- | httemplate/elements/location.html | 14 | ||||
-rw-r--r-- | httemplate/elements/select-county.html | 32 | ||||
-rw-r--r-- | httemplate/elements/tr-select-cust_location.html | 5 |
4 files changed, 166 insertions, 27 deletions
diff --git a/httemplate/elements/city.html b/httemplate/elements/city.html new file mode 100644 index 000000000..1659ebf47 --- /dev/null +++ b/httemplate/elements/city.html @@ -0,0 +1,142 @@ +<%doc> + +Example: + + include( '/elements/city.html', + #recommended + country => $current_country, + state => $current_state, + county => $current_county, + city => $current_city, + + #optional + prefix => $optional_unique_prefix, + onchange => $javascript, + disabled => 0, #bool +# disable_empty => 1, #defaults to 1, disable the empty option +# empty_label => 'all', #label for empty option + style => [ 'attribute:value', 'another:value' ], + ); + +</%doc> + +<% include('/elements/xmlhttp.html', + 'url' => $p.'misc/cities.cgi', + 'subs' => [ $pre. 'get_cities' ], + ) +%> + +<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; + } + + var saved_<%$pre%>city= ''; + + function <% $pre %>county_changed(what, callback) { + + county = what.options[what.selectedIndex].value; + state = what.form.<% $pre %>state.options[what.form.<% $pre %>state.selectedIndex].value; + country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value; + + function <% $pre %>update_cities(cities) { + + // blank the current city list + for ( var i = what.form.<% $pre %>city_select.length; i >= 0; i-- ) + what.form.<% $pre %>city_select.options[i] = null; + + // add the new cities + var citiesArray = eval('(' + cities + ')' ); + + for ( var s = 0; s < citiesArray.length; s++ ) { + var cityLabel = citiesArray[s]; + if ( cityLabel == "" ) + cityLabel = '(n/a)'; + opt(what.form.<% $pre %>city_select, citiesArray[s], cityLabel); + } + + if ( citiesArray.length > 1 || citiesArray[0].length ) { + // turn off the text city, turn on the select + saved_<%$pre%>city = what.form.<%$ pre %>city.value; + what.form.<% $pre %>city.style.display = 'none'; + what.form.<% $pre %>city_select.style.display = ''; + } else { + // turn on the text city, turn off the select + what.form.<%$ pre %>city.value = saved_<%$pre%>city; + what.form.<% $pre %>city.style.display = ''; + what.form.<% $pre %>city_select.style.display = 'none'; + } + + //run the callback + if ( callback != null ) + callback(); + } + + // go get the new cities + <% $pre %>get_cities( county, state, country, <% $pre %>update_cities ); + + } + + function <%$pre%>city_select_changed(what) { + what.form.<%$pre%>city.value = what.options[what.selectedIndex].value; + } + +</SCRIPT> + +<INPUT TYPE = "text" + NAME = "<%$pre%>city" + ID = "<%$pre%>city" + VALUE = "<% $opt{'city'} |h %>" + onChange = "<% $opt{'onchange'} %>" + <% $opt{'disabled'} %> + <% $text_style %> +> + +<SELECT NAME = "<%$pre%>city_select" + ID = "<%$pre%>city_select" + onChange = "<%$pre%>city_select_changed(this); <% $opt{'onchange'} %>" + <% $opt{'disabled'} %> + <% $select_style %> +> + +% foreach my $city ( @cities ) { + + <OPTION VALUE="<% $city |h %>" + <% $city eq $opt{'city'} ? 'SELECTED' : '' %> + ><% $city eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $city %> + +% } + +</SELECT> + +%# VALUE = "<% $curr_value |h %>" +<%init> + +my %opt = @_; + +my $pre = $opt{'prefix'}; + +my $text_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; +my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; + +my @cities = cities( $opt{'county'}, $opt{'state'}, $opt{'country'} ); +if ( scalar(@cities) > 1 || $cities[0] ) { + push @$text_style, 'display:none'; +} else { + push @$select_style, 'display:none'; +} + +$text_style = + scalar(@$text_style) + ? 'STYLE="'. join(';', @$text_style). '"' + : ''; + +$select_style = + scalar(@$select_style) + ? 'STYLE="'. join(';', @$select_style). '"' + : ''; + +</%init> diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html index 07aaa69f0..5478e1e1e 100644 --- a/httemplate/elements/location.html +++ b/httemplate/elements/location.html @@ -49,16 +49,7 @@ Example: <TR> <TH ALIGN="right"><%$r%>City</TH> - <TD WIDTH="1"> - <INPUT TYPE = "text" - NAME = "<%$pre%>city" - ID = "<%$pre%>city" - VALUE = "<% $object->get($pre.'city') |h %>" - onChange = "<% $onchange %>" - <% $disabled %> - <% $style %> - > - </TD> + <TD WIDTH="1"><% include('/elements/city.html', %select_hash) %></TD> <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH> <TD><% include('/elements/select-county.html', %select_hash ) %></TD> <TH ALIGN="right" WIDTH="1"><%$r%>State</TH> @@ -123,7 +114,7 @@ $object->set($pre.'state', $statedefault ) || $object->get($pre.'country') ne $countrydefault; my @style = (); -push @style, 'background-color: #dddddd"' if $disabled; +push @style, 'background-color: #dddddd' if $disabled; my @address2_label_style = (); push @address2_label_style, 'visibility:hidden' @@ -152,6 +143,7 @@ my $county_style = : ''; my %select_hash = ( + 'city' => $object->get($pre.'city'), 'county' => $object->get($pre.'county'), 'state' => $object->get($pre.'state'), 'country' => $object->get($pre.'country'), diff --git a/httemplate/elements/select-county.html b/httemplate/elements/select-county.html index aa88abe96..aa9f453fd 100644 --- a/httemplate/elements/select-county.html +++ b/httemplate/elements/select-county.html @@ -67,8 +67,11 @@ Example: } //run the callback - if ( callback != null ) + if ( callback != null ) { callback(); + } else { + <% $pre %>county_changed(what.form.<% $pre %>county); + } } // go get the new counties @@ -80,7 +83,7 @@ Example: <SELECT NAME = "<% $pre %>county" ID = "<% $pre %>county" - onChange= "<% $opt{'onchange'} %>" + onChange= "<% $onchange %>" <% $opt{'disabled'} %> <% $style %> > @@ -127,11 +130,13 @@ $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); my $pre = $opt{'prefix'}; + +# disable_cityupdate? +my $onchange = + ( $opt{'disable_cityupdate'} ? '' : $pre.'county_changed(this); ' ). + $opt{'onchange'}; + $opt{'style'} ||= []; -my $style = - scalar(@{$opt{style}}) - ? 'STYLE="'. join(';', @{$opt{style}}). '"' - : ''; my @counties = (); if ( $countyflag ) { @@ -139,17 +144,16 @@ if ( $countyflag ) { @counties = map { length($_) ? $_ : $opt{'empty_data_value'} } counties( $opt{'state'}, $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"'; - } - } + push @{ $opt{'style'} }, 'display:none' + unless scalar(@counties) > 1; } +my $style = + scalar(@{$opt{style}}) + ? 'STYLE="'. join(';', @{$opt{style}}). '"' + : ''; + </%init> <%once> diff --git a/httemplate/elements/tr-select-cust_location.html b/httemplate/elements/tr-select-cust_location.html index da16dfe1c..ab043ee7e 100644 --- a/httemplate/elements/tr-select-cust_location.html +++ b/httemplate/elements/tr-select-cust_location.html @@ -21,7 +21,7 @@ Example: var locationnum = what.options[what.selectedIndex].value; if ( locationnum == -1 ) { -% for (@location_fields) { +% for (@location_fields, 'city_select') { what.form.<%$_%>.disabled = false; what.form.<%$_%>.style.backgroundColor = '#ffffff'; % } @@ -60,7 +60,7 @@ Example: } %#sleep/wait until dropdowns are updated? -% for (@location_fields) { +% for (@location_fields, 'city_select') { what.form.<%$_%>.disabled = true; what.form.<%$_%>.style.backgroundColor = '#dddddd'; % } @@ -85,6 +85,7 @@ Example: } else { county_el.selectedIndex = 0; } + county_changed(county_el); } return fix_county; } |