UI spring cleaning: animate company/spouse/contact hide/unhide
[freeside.git] / httemplate / edit / cust_main / basics.html
1 <TABLE CLASS="fsinnerbox">
2
3 <TR>
4   <TD ALIGN="right">Residential</TD>
5   <TD><INPUT TYPE     = "radio"
6              NAME     = "residential_commercial"
7              ID       = "residential_commercial_Residential"
8              VALUE    = "Residential"
9              onChange = "rescom_changed(this)"
10        <% $cust_main->residential_commercial eq 'Commercial' ? '' : 'CHECKED' %>
11   ></TD>
12 </TR>
13 <TR>
14   <TD ALIGN="right">Commercial</TD>
15   <TD><INPUT TYPE     = "radio"
16              NAME     = "residential_commercial"
17              ID       = "residential_commercial_Commercial"
18              VALUE    = "Commercial"
19              onChange = "rescom_changed(this)"
20        <% $cust_main->residential_commercial eq 'Commercial' ? 'CHECKED' : '' %>
21   ></TD>
22 </TR>
23
24 <SCRIPT TYPE="text/javascript">
25
26   function rescom_changed(what) {
27     if ( what.checked == (what.value == 'Commercial' ) ) {
28       $('#company_label').slideDown();
29       $('#company_input').slideDown();
30       $('#contacts_div').slideDown();
31       $('#spouse_label').slideUp();
32       $('#spouse_last_input').slideUp();
33       $('#spouse_first_input').slideUp();
34     } else {
35       if ( document.getElementById('company').value.length == 0 ) {
36         $('#company_label').slideUp();
37         $('#company_input').slideUp();
38       }
39       $('#contacts_div').slideUp();
40       $('#spouse_label').slideDown();
41       $('#spouse_last_input').slideDown();
42       $('#spouse_first_input').slideDown();
43     }
44   }
45
46
47   var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
48   var ship_fields = [
49     'locationname', 'address1', 'city', 'state', 'zip', 'country', 
50     'latitude', 'longitude', 'district'
51   ];
52
53   function agent_changed(what) {
54     var agentnum = what.value;
55
56 %   # unlock/lock service location
57
58     var f = what.form;
59     if ( ship_locked_agents[agentnum] ) {
60 %     # For this agent, the service location (except address2)
61 %     # should be locked to the agent's location.
62 %     # Set the ship_ fields to those values (just for display) and
63 %     # then disable them.
64       for(var x in ship_locked_agents[agentnum]) {
65         f['ship_'+x].value = ship_locked_agents[agentnum][x];
66         f['ship_'+x].disabled = true;
67       }
68       f['same'].checked = false;
69       f['same'].disabled = true;
70     } else {
71 %     # Unlock the ship_ location fields.  If they were previously
72 %     # disabled, then they contain some agent's address, which is 
73 %     # no longer meaningful.  So set them back to the customer's 
74 %     # current location.
75       for(var i=0; i<ship_fields.length; i++) {
76         x = ship_fields[i];
77         if ( f['ship_'+x].disabled )  {
78           f['ship_'+x].value  = f['old_ship_'+x].value;
79         }
80         f['ship_'+x].disabled = false;
81       }
82       f['same'].disabled = false;
83     }
84     samechanged(f['same']);
85
86 %   # update sales dropdown
87     salesnum_agentnum_changed(what);
88
89   }
90
91   <&| /elements/onload.js &>
92   rescom_changed(document.getElementById('residential_commercial_Residential'));
93   agent_changed(document.getElementById('agentnum'));
94   samechanged(document.getElementById('same'));
95   </&>
96  
97 </SCRIPT>
98
99 % foreach my $field ($cust_main->virtual_fields) {
100     <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %>
101 % }
102
103 %# tags
104 <& /elements/tr-select-cust_tag.html,
105              'custnum' => $custnum,
106              'cgi'     => $cgi,
107 &>
108
109 %# agent
110 % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
111 %
112 %   my $agentnum = $1;
113 %   $cust_main->agentnum($agentnum);
114
115     <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
116     <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
117       VALUE="<% $agentnum %>">
118     <TR>
119       <TH ALIGN="right"><% mt('Agent') |h %></TD>
120       <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
121     </TR>
122
123 % } else {
124
125   <& /elements/tr-select-agent.html, 
126                 'curr_value'    => $cust_main->agentnum,
127                 'label'         => $r. emt('Agent'),
128                 'empty_label'   => emt('Select agent'),
129                 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
130                 'viewall_right' => emt('None'), 
131                 'onchange'      => 'agent_changed(this)',
132   &>
133
134 % }
135
136 %# agent_custid
137 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
138
139     <TR>
140       <TH ALIGN="right"><% mt('Customer identifier') |h %></TD>
141       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
142     </TR>
143
144 % } else {
145
146     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
147
148 % }
149
150 %# class
151 <& /elements/tr-select-cust_class.html,
152              'curr_value'  => $cust_main->classnum,
153              'label'       => emt("Class"),
154 &>
155
156 %# tax status
157 <& /elements/tr-select-tax_status.html,
158              'curr_value'     => $cust_main->taxstatusnum,
159              'disable_empty'  => 0,
160              'empty_label'    => ' ',
161 &>
162
163 %#sales person
164 <& /elements/tr-select-sales.html,
165      'curr_value' => $cust_main->salesnum,
166      'th' => 1,
167 &>
168
169 %# referral (advertising source)
170 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
171 %if ( $custnum && ! $conf->exists('editreferrals') ) {
172
173   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
174
175 % } else { 
176
177   <& /elements/tr-select-part_referral.html,
178                 'curr_value' => $refnum,
179                 'label'      => $r. emt('Advertising source'),
180   &>
181 % } 
182
183
184 %# referring customer
185 %my $referring_cust_main = '';
186 %if ( $cust_main->referral_custnum
187 %     and $referring_cust_main =
188 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
189 %     and ! $curuser->access_right('Edit referring customer')
190 %) {
191
192   <TR>
193     <TH ALIGN="right"><% mt('Referring customer') |h %></TD>
194     <TD>
195       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
196     </TD>
197   </TR>
198   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
199
200 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
201
202   <TR>
203     <TH ALIGN="right"><% mt('Referring customer') |h %></TD>
204     <TD>
205       <& /elements/search-cust_main.html,
206                     'field_name' => 'referral_custnum',
207                     'curr_value' => $cust_main->referral_custnum,
208       &>
209     </TD>
210   </TR>
211
212 % } else { 
213   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
214 % } 
215
216 %# signup date
217 % if ( $conf->exists('cust_main-edit_signupdate') ) {
218     <& /elements/tr-input-date-field.html, {
219                   'name'        => 'signupdate',
220                   'value'       => $cust_main->signupdate,
221                   'label'       => emt('Signup date'),
222                   'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
223               }
224     &>
225 % }
226
227 % # permission to edit ticket subjects
228 % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
229   <TR>
230     <TD ALIGN="right">
231       <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
232         $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
233     <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
234   </TR>
235 % } else {
236   <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
237 % }
238
239 % # permission to edit
240 % if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
241   <TR>
242     <TD ALIGN="right">
243       <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
244         $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
245     <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
246   </TR>
247 % } else {
248   <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
249 % }
250
251 </TABLE>
252
253 <%init>
254
255 my( $cust_main, %opt ) = @_;
256
257 my $custnum = $opt{'custnum'};
258
259 my $conf = new FS::Conf;
260
261 if ( $cgi->param('error') ) {
262   $cust_main->set('residential_commercial',
263     ($cgi->param('residential_commercial') eq 'Commercial')
264       ? 'Commercial'
265       : 'Residential'
266   );
267 } elsif ( $custnum ) { #editing
268   $cust_main->set('residential_commercial',
269     length($cust_main->company)
270       ? 'Commercial'
271       : 'Residential'
272   );
273 } else { #new customer
274   $cust_main->set('residential_commercial',
275     $conf->exists('cust_main-default_commercial')
276       ? 'Commercial'
277       : 'Residential'
278   );
279 }
280
281 my $curuser = $FS::CurrentUser::CurrentUser;
282
283 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
284
285 # which agents lock the service address, if any
286 my %ship_locked_agents;
287 foreach (qsearch('agent',{})) {
288   my $agentnum = $_->agentnum;
289   next unless $conf->exists('agent-ship_address', $_->agentnum);
290   my $cust_main = $_->agent_cust_main or next;
291   my $agent_ship_location = $cust_main->ship_location;
292   $ship_locked_agents{$agentnum} = +{
293     map { $_ => $agent_ship_location->$_ }
294     qw(locationname address1 city state zip country latitude longitude district)
295   };
296 }
297
298 </%init>