0b91add5206e6a43df869027cb82612ee6420504
[freeside.git] / httemplate / elements / location.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/location.html',
6              'object'         => $cust_main,  # or $cust_location
7              'prefix'         => $pre,        #only for cust_main objects
8              'onchange'       => $javascript,
9              'disabled'       => $disabled,
10              'same_checked'   => $same_checked,
11              'geocode'        => $geocode, #passed through
12              'censustract'    => $censustract, #passed through
13              'no_asterisks'   => 0, #set true to disable the red asterisks next
14                                     #to required fields
15              'address1_label' => 'Address', #label for address
16          )
17
18 </%doc>
19
20 % if ( $opt{'alt_format'} ) {
21
22 <TR>
23     <<%$th%> ALIGN="right">Location kind</<%$th%>>
24     <TD>
25     <% include('/elements/select.html',
26                  'cgi'        => $cgi,
27                  'field'      => 'location_kind',
28                  'id'         => 'location_kind',
29                  'disabled'   => $disabled,
30                  'style'      => \@style,
31                  'options'    => \@location_kind_options,
32                  'labels'     => $location_kind_labels,
33                  'curr_value' => scalar($cgi->param('location_kind'))
34                                    || $object->get($pre.'location_kind'),
35               )
36     %>
37     </TD>
38   </TR>
39
40 % } 
41
42 <TR>
43   <<%$th%> ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></<%$th%>>
44   <TD COLSPAN=7>
45     <INPUT TYPE     = "text"
46            NAME     = "<%$pre%>address1"
47            ID       = "<%$pre%>address1"
48            VALUE    = "<% $object->get($pre.'address1') |h %>"
49            SIZE     = 54
50            onChange = "<% $onchange %>"
51            <% $disabled %>
52            <% $style %>
53     >
54   </TD>
55 </TR>
56
57 % if ( ! $opt{'alt_format'} ) { #regular format
58
59 <TR>
60       <TD ALIGN="right"><FONT ID="<% $pre %>address2_required" color="#ff0000" <% $address2_label_style %>>*</FONT>&nbsp;<FONT ID="<% $pre %>address2_label" <% $address2_label_style %>><B>Unit&nbsp;#</B></FONT></TD>
61       <TD COLSPAN=7>
62         <INPUT TYPE     = "text"
63                NAME     = "<%$pre%>address2"
64                ID       = "<%$pre%>address2"
65                VALUE    = "<% $object->get($pre.'address2') |h %>"
66                SIZE     = 54
67                onChange = "<% $onchange %>"
68                <% $disabled %>
69                <% $style %>
70         >
71       </TD>
72 </TR>
73
74 % } else { # alternate format
75
76       <INPUT TYPE  = "hidden"
77              NAME  = "<%$pre%>address2"
78              VALUE = "<% $object->get($pre.'address2') |h %>"
79       >
80
81 <TR>
82     <<%$th%> ALIGN="right">Unit type and #</<%$th%>>
83     <TD COLSPAN=7>
84
85 %     my $location_type = scalar($cgi->param('location_type'))
86 %                           || $object->get($pre.'location_type');
87 %     #my $location_number = scalar($cgi->param('location_number'))
88 %     #                        || $object->get($pre.'location_number');
89 %
90 %   if ( $object->get($pre.'address2') && ! $location_type ) {
91 %   }
92 %
93 %     if ( 1 ) { #ikano, switch on via config
94 %       tie my %location_types, 'Tie::IxHash',
95 %         FS::part_export::ikano->location_types;
96         <% include('/elements/select.html',
97                      'cgi'        => $cgi,
98                      'field'      => 'location_type',
99                      'id'         => 'location_type',
100                      'disabled'   => $disabled,
101                      'style'      => \@style,
102                      'options'    => [ keys %location_types ],
103                      'labels'     => \%location_types,
104                      'curr_value' => $location_type,
105                      'onchange'   => 'location_type_changed',
106                   )
107         %>
108         <SCRIPT TYPE="text/javascript">
109           function location_type_changed (what) {
110             if ( what.options[what.selectedIndex].value == '' ) {
111               what.form.location_number.disabled = true;
112               what.form.location_number.style.backgroundColor = '#dddddd';
113             } else {
114               what.form.location_number.disabled = false;
115               what.form.location_number.style.backgroundColor = '#ffffff';
116             }
117           }
118         </SCRIPT>
119 %     } else {
120         <INPUT TYPE  = "text" 
121                NAME  = "location_type" 
122                ID    = "location_type"
123                VALUE = "<% $location_type |h %>"
124                SIZE  = "10"
125                <% $disabled %>
126                <% $style %>
127         >
128 %     }
129
130     <INPUT TYPE="text" 
131                NAME  = "location_number"
132                ID    = "location_number"
133                VALUE = "<% scalar($cgi->param('location_number')) || $object->get($pre.'location_number') |h %>"
134                SIZE  = "5"
135                <% $disabled || ($location_type ? '' : 'DISABLED') %>
136                <% $style %>
137         >
138
139 %   if ( $object->get($pre.'address2') ) {
140
141 %     #XXX try to parse first
142 %     if ( 0 ) {
143 %     } else { #XXX i don't work so well when the dropdown is changed :/  i probably need to be triggered by "default service address"
144         Can't parse unit type and number from <B><% $object->get($pre.'address2') |h %></B>
145 %    }
146
147 % }
148
149     </TD>
150
151 </TR>
152
153 % } 
154
155
156 <TR>
157   <<%$th%> ALIGN="right"><%$r%>City</<%$th%>>
158   <TD WIDTH="1"><% include('/elements/city.html', %select_hash) %></TD>
159   <<%$th%> ALIGN="right" WIDTH="1" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
160   <TD WIDTH="1"><% include('/elements/select-county.html', %select_hash ) %></TD>
161   <<%$th%> ALIGN="right" WIDTH="1"><%$r%>State</<%$th%>>
162   <TD WIDTH="1">
163     <% include('/elements/select-state.html', %select_hash ) %>
164   </TD>
165   <<%$th%> ALIGN="right" WIDTH="1"><%$r%>Zip</<%$th%>>
166   <TD>
167     <INPUT TYPE     = "text"
168            NAME     = "<%$pre%>zip"
169            ID       = "<%$pre%>zip"
170            VALUE    = "<% $object->get($pre.'zip') |h %>"
171            SIZE     = 10
172            onChange = "<% $onchange %>"
173            <% $disabled %>
174            <% $style %>
175     >
176   </TD>
177 </TR>
178
179 <TR>
180   <<%$th%> ALIGN="right"><%$r%>Country</<%$th%>>
181   <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
182 </TR>
183
184 % if ( !$pre ) { 
185   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
186 % } else {
187 %   if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) {
188       <TR><<%$th%> ALIGN="right">Census tract<BR>(automatic)</<%$th%>>
189         <TD>
190           <INPUT TYPE="text" NAME="censustract" VALUE="<% $opt{censustract} %>">
191         </TD>
192       </TR>
193 %   } else {
194       <INPUT TYPE="hidden" NAME="censustract" VALUE="<% $opt{censustract} %>">
195 %   } 
196 % } 
197
198 <%init>
199
200 my %opt = @_;
201
202 my $pre      = $opt{'prefix'};
203 my $object   = $opt{'object'};
204 my $onchange = $opt{'onchange'};
205 my $disabled = $opt{'disabled'};
206
207 my $conf = new FS::Conf;
208
209 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font>&nbsp;!;
210
211 #false laziness with ship state
212 my $countrydefault = $conf->config('countrydefault') || 'US';
213 $object->set($pre.'country', $countrydefault )
214   unless $object->get($pre.'country');
215
216 my $statedefault = $conf->config('statedefault')
217                    || ($countrydefault eq 'US' ? 'CA' : '');
218 $object->set($pre.'state', $statedefault )
219   unless $object->get($pre.'state')
220          || $object->get($pre.'country') ne $countrydefault;
221
222 my @style = ();
223 push @style, 'background-color: #dddddd' if $disabled;
224
225 my @address2_label_style = ();
226 push @address2_label_style, 'visibility:hidden'
227   if $disabled
228   || ! $conf->exists('cust_main-require_address2')
229   || ( !$pre && !$opt{'same_checked'} );
230
231 my @counties = counties( $object->get($pre.'state'),
232                          $object->get($pre.'country'),
233                        );
234 my @county_style = ();
235 push @county_style, 'display:none' # 'visibility:hidden'
236   unless scalar(@counties) > 1;
237
238 my $style =
239   scalar(@style)
240     ? 'STYLE="'. join(';', @style). '"'
241     : '';
242 my $address2_label_style =
243   scalar(@address2_label_style)
244     ? 'STYLE="'. join(';', @address2_label_style). '"'
245     : '';
246 my $county_style = 
247   scalar(@county_style)
248     ? 'STYLE="'. join(';', @county_style). '"'
249     : '';
250
251 my %select_hash = (
252   'city'     => $object->get($pre.'city'),
253   'county'   => $object->get($pre.'county'),
254   'state'    => $object->get($pre.'state'),
255   'country'  => $object->get($pre.'country'),
256   'prefix'   => $pre,
257   'onchange' => $onchange,
258   'disabled' => $disabled,
259   'style'    => \@style,
260 );
261
262 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
263
264 my @location_kind_options = ( '', 'R', 'B' );
265 my $location_kind_labels = { '' => '', 'R' => 'Residential', 'B' => 'Business' };
266
267 </%init>