From 20bddf47a41b6d064b3cfa4c41e55c157cf0c3de Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 9 Jan 2009 04:06:26 +0000 Subject: pick/enter a location when ordering a package, RT#4499 --- httemplate/elements/location.html | 150 +++++++++++++++++++++++ httemplate/elements/select-country.html | 9 +- httemplate/elements/select-county.html | 8 ++ httemplate/elements/select-state.html | 9 ++ httemplate/elements/tr-select-part_referral.html | 4 +- 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 httemplate/elements/location.html (limited to 'httemplate/elements') diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html new file mode 100644 index 000000000..bf340894a --- /dev/null +++ b/httemplate/elements/location.html @@ -0,0 +1,150 @@ +<%doc> + +Example: + + include( '/elements/location.html', + 'object' => $cust_main, # or $cust_location + 'prefix' => $pre, #only for cust_main objects + 'onchange' => $javascript, + 'disabled' => $disabled, + 'same_checked' => $same_checked, + 'geocode' => $geocode, #passed through + 'no_asterisks' => 0, #set true to disable the red asterisks next + #to required fields + ) + + + + + <%$r%>Address + + + <% $style %> + > + + + + + * Unit # + + + <% $style %> + > + + + + + <%$r%>City + + + <% $style %> + > + + ><%$r%>County + + <% include('/elements/select-county.html', %select_hash ) %> + + <%$r%>State + + <% include('/elements/select-state.html', %select_hash ) %> + + <%$r%>Zip + + + <% $style %> + > + + + + + <%$r%>Country + <% include('/elements/select-country.html', %select_hash ) %> + + +% if ( !$pre ) { + +% } + +<%init> + +my %opt = @_; + +my $pre = $opt{'prefix'}; +my $object = $opt{'object'}; +my $onchange = $opt{'onchange'}; +my $disabled = $opt{'disabled'}; + +my $conf = new FS::Conf; + +my $r = $opt{'no_asterisks'} ? '' : qq!* !; + +#false laziness with ship state +my $countrydefault = $conf->config('countrydefault') || 'US'; +$object->set($pre.'country', $countrydefault ) + unless $object->get($pre.'country'); + +my $statedefault = $conf->config('statedefault') + || ($countrydefault eq 'US' ? 'CA' : ''); +$object->set($pre.'state', $statedefault ) + unless $object->get($pre.'state') + || $object->get($pre.'country') ne $countrydefault; + +my @style = (); +push @style, 'background-color: #dddddd"' if $disabled; + +my @address2_label_style = (); +push @address2_label_style, 'visibility:hidden' + if $disabled + || ! $conf->exists('cust_main-require_address2') + || ( !$pre && !$opt{'same_checked'} ); + +my @counties = counties( $object->get($pre.'state'), + $object->get($pre.'country'), + ); +my @county_style = (); +push @county_style, 'visibility:hidden' + unless scalar(@counties) > 1; + +my $style = + scalar(@style) + ? 'STYLE="'. join(';', @style). '"' + : ''; +my $address2_label_style = + scalar(@address2_label_style) + ? 'STYLE="'. join(';', @address2_label_style). '"' + : ''; +my $county_style = + scalar(@county_style) + ? 'STYLE="'. join(';', @county_style). '"' + : ''; + +my %select_hash = ( + 'county' => $object->get($pre.'county'), + 'state' => $object->get($pre.'state'), + 'country' => $object->get($pre.'country'), + 'prefix' => $pre, + 'onchange' => $onchange, + 'disabled' => $disabled, + 'style' => \@style, +); + + diff --git a/httemplate/elements/select-country.html b/httemplate/elements/select-country.html index c4368c271..45b0ccd5f 100644 --- a/httemplate/elements/select-country.html +++ b/httemplate/elements/select-country.html @@ -13,7 +13,7 @@ Example: disable_empty => 1, #defaults to 1, disable the empty option empty_label => 'all', #label for empty option disable_stateupdate => 0, #bool - disabled update of the select-state.html - + style => [ 'attribute:value', 'another:value' ], ); @@ -70,6 +70,7 @@ Example: ID = "<% $pre %>country" onChange = "<% $onchange %>" <% $opt{'disabled'} %> + <% $style %> > % unless ( $opt{'disable_empty'} ) { @@ -101,6 +102,12 @@ my $onchange = ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ). $opt{'onchange'}; +$opt{'style'} ||= []; +my $style = + scalar(@{$opt{style}}) + ? 'STYLE="'. join(';', @{$opt{style}}). '"' + : ''; + my $conf = new FS::Conf; my $default = $conf->config('countrydefault') || 'US'; diff --git a/httemplate/elements/select-county.html b/httemplate/elements/select-county.html index 8ef34dbe6..59f235a23 100644 --- a/httemplate/elements/select-county.html +++ b/httemplate/elements/select-county.html @@ -14,6 +14,7 @@ Example: 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' ], ); @@ -79,6 +80,7 @@ Example: ID = "<% $pre %>county" onChange= "<% $opt{'onchange'} %>" <% $opt{'disabled'} %> + <% $style %> > % unless ( $opt{'disable_empty'} ) { @@ -123,6 +125,12 @@ $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); my $pre = $opt{'prefix'}; +$opt{'style'} ||= []; +my $style = + scalar(@{$opt{style}}) + ? 'STYLE="'. join(';', @{$opt{style}}). '"' + : ''; + my @counties = (); if ( $countyflag ) { diff --git a/httemplate/elements/select-state.html b/httemplate/elements/select-state.html index f7ac2c7bf..9b358e24d 100644 --- a/httemplate/elements/select-state.html +++ b/httemplate/elements/select-state.html @@ -14,6 +14,7 @@ Example: disable_empty => 1, #defaults to 1, disable the empty option empty_label => 'all', #label for empty option disable_countyupdate => 0, #bool - disabled update of the select-state.html + style => [ 'attribute:value', 'another:value' ], ); @@ -21,6 +22,8 @@ Example: