RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / elements / select-did.html
1 <%doc>
2
3 Example:
4
5   include('/elements/select-did.html',
6             #can't actuall change from phonenum yet# 'field'   => 'phonenum',
7
8             'svcpart' => 5,
9             #OR
10             'object' => $svc_phone,
11          );
12
13 </%doc>
14 % if ( $conf->exists('svc_phone-lnp') ) { #ask exports if they can_lnp instead?
15   <& /elements/selectlayers.html,
16        'field'      => 'lnp_status',
17        'curr_value' => $opt{'lnp_status'},
18        'options'    => [ '', 'portingin', 'native', 'portedin', 'portingout',
19                          'portin-reject', 'portout-reject',
20                        ],
21        'labels'     => { '' => 'Select new number',
22                          'portingin' => 'Port an existing number',
23                          'native' => 'Native',
24                          'portedin' => 'Ported In',
25                          'portingout' => 'Porting Out',
26                          'portin-reject' => 'Port-In Reject',
27                          'portout-reject' => 'Port-Out Reject',
28                        },
29        'layer_callback' => sub {
30          my( $layer, $layer_fields, $layer_values, $layer_prefix ) = @_;
31          if ( $layer eq 'portingin' ) {
32            $m->scomp('/elements/input-text.html', %opt, 'type'=>'text' );
33          } elsif ( $layer ne '' ) {
34            $m->scomp('/elements/hidden.html', %opt).
35            $m->scomp('/elements/phonenumber.html', $opt{'curr_value'}, 'callable' => 1);
36          } else {
37            $m->scomp('/elements/select-did.html:not_porting', %opt);
38          }
39        },
40   &>
41
42
43 % } else {
44   <& /elements/select-did.html:not_porting, %opt &>
45 % }
46 <%init>
47
48 my %opt = @_;
49
50 my $conf = new FS::Conf;
51
52 </%init>
53 <%method not_porting>
54 % if ( $use_selector ) {
55
56 %   if ( $export->option('restrict_selection') eq 'non-tollfree'
57 %                   || !$export->option('restrict_selection') ) {
58     <TABLE>
59       <TR>
60
61 %       my( $phonenum_checked, $manual_checked ) = ( '', '' );
62 %       if ( $export->get_dids_can_manual ) {
63 %         #not 100% perfect UI on error handling, but it'll do
64 %         if ( $opt{'curr_value'} ) {
65 %           $phonenum_checked = '';
66 %           $manual_checked   = 'CHECKED';
67 %         } else {
68 %           $phonenum_checked = 'CHECKED';
69 %           $manual_checked   = '';
70 %         }
71
72         <TD VALIGN="top">
73           <INPUT TYPE     = "radio"
74                  NAME     = "phonenum_which"
75                  VALUE    = "phonenum"
76                  onChange = "phonenum_which_changed(this)"
77                  onClick  = "phonenum_which_changed(this)"
78                  <% $phonenum_checked %>
79           > Inventory
80         </TD>
81 %       }
82
83 %       if ( $export->get_dids_npa_select ) {
84
85         <TD VALIGN="top">
86           <% include('/elements/select-state.html',
87                        'prefix'        => 'phonenum_', #$field.'_',
88                        'country'       => $country,
89                        'svcpart'       => $svcpart,
90                        'disable_empty' => 0,
91                        'empty_label'   => 'Select state',
92                        'disabled'      => ( $manual_checked ? 1 : 0 ),
93                     )
94           %>
95           <BR><FONT SIZE="-1" ID="phonenum_state_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>State</FONT>
96         </TD>
97
98           <TD VALIGN="top">
99             <% include('/elements/select-areacode.html',
100                          'state_prefix' => 'phonenum_', #$field.'_',
101                          'svcpart'      => $svcpart,
102                          'empty'        => 'Select area code',
103                       )
104             %>
105             <BR><FONT SIZE="-1" ID="areacode_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Area code</FONT>
106           </TD>
107
108           <TD VALIGN="top">
109             <% include('/elements/select-exchange.html',
110                          'svcpart'  => $svcpart,
111                          'empty'    => 'Select exchange',
112                       )
113             %>
114             <BR><FONT SIZE="-1" ID="exchange_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>City / Exchange</FONT>
115           </TD>
116
117 %       } else {
118 %
119 %       #this code path currently only being used by fibernetics
120 %       # should change "Province" label to "State" or make it configurable
121 %       # if/when other folks need an areacode-less DID selector that goes
122 %       # directly from state to region
123
124           <TD VALIGN="top">
125             <% include('/elements/select.html',
126                          'field'    => 'phonenum_state',
127                          'id'       => 'phonenum_state',
128                          'options'  => [ '', @{ $export->get_dids } ],
129                          'labels'   => { '' => 'Select province' },
130                          'onchange' => 'phonenum_state_changed(this);',
131                          'disabled' => ( $manual_checked ? 1 : 0 ),
132                       )
133             %>
134             <BR><FONT SIZE="-1" ID="phonenum_state_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Province</FONT>
135           </TD>
136
137           <TD VALIGN="top">
138             <% include('/elements/select-region.html',
139                          'state_prefix'  => 'phonenum_', #$field.'_',
140                          'svcpart'       => $svcpart,
141                          'empty'         => 'Select region',
142                       )
143             %>
144             <BR><FONT SIZE="-1" ID="region_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Region</FONT>
145           </TD>
146
147 %       }
148
149         <TD VALIGN="top">
150           <% include('/elements/select-phonenum.html',
151                        'svcpart'  => $svcpart,
152                        'empty'    => 'Select phone number',
153                        'bulknum'  => $bulknum,
154                        'multiple' => $multiple,
155                        'region'   => ! $export->get_dids_npa_select,
156                     )
157           %>
158           <BR><FONT SIZE="-1" ID="phonenum_phonenum_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Phone number</FONT>
159         </TD>
160
161       </TR>
162
163 %       if ( $export->get_dids_can_manual ) {
164           <TR>
165
166             <TD VALIGN="top">
167               <INPUT TYPE     = "radio"
168                      NAME     = "phonenum_which"
169                      VALUE    = "phonenum_manual"
170                      onChange = "phonenum_which_changed(this)"
171                      onClick  = "phonenum_which_changed(this)"
172                      <% $manual_checked %>
173               > Manual entry
174             </TD>
175
176             <TD VALIGN="top" COLSPAN=4>
177               <& /elements/input-text.html,
178                    %opt,
179                    field    => 'phonenum_manual',
180                    id       => 'phonenum_manual',
181                    type     => 'text',
182                    disabled => ( $phonenum_checked ? 1 : 0 ),
183               &>
184             </TD>
185           </TR>
186
187           <SCRIPT TYPE="text/javascript">
188             function phonenum_which_changed(what) {
189
190               if ( what.value == 'phonenum' && what.checked ) {
191
192                 what.form.phonenum_manual.disabled = true;
193                 what.form.phonenum_manual.style.backgroundColor = '#dddddd';
194
195                 what.form.phonenum_state.disabled = false;
196
197                 document.getElementById('phonenum_state_label').style.color = '#000000';
198                 if ( document.getElementById('areacode_label') ) {
199                   document.getElementById('areacode_label').style.color = '#000000';
200                 }
201                 if ( document.getElementById('exchange_label') ) {
202                   document.getElementById('exchange_label').style.color = '#000000';
203                 }
204                 if ( document.getElementById('region_label') ) {
205                   document.getElementById('region_label').style.color = '#000000';
206                 }
207                 document.getElementById('phonenum_phonenum_label').style.color = '#000000';
208
209                 var value = what.form.phonenum_state.options[ what.form.phonenum_state.selectedIndex].value;
210
211                 if ( value != '' ) {
212
213                   if ( what.form.areacode ) {
214                     what.form.areacode.disabled = false;
215
216                     var areacode_value = what.form.areacode.options[ what.form.areacode.selectedIndex].value;
217
218                     if ( areacode_value != '' ) {
219                       what.form.exchange.disabled = false;
220
221                       var exchange_value = what.form.exchange.options[ what.form.exchange.selectedIndex].value;
222
223                       if ( exchange_value != '' ) {
224                         what.form.phonenum.disabled = false;
225                       }
226
227                     }
228
229                   }
230                   if ( what.form.region ) {
231                     what.form.region.disabled = false;
232                     
233                     var region_value = what.form.region.options[ what.form.region.selectedIndex].value;
234
235                     if ( region_value != '' ) {
236                       what.form.phonenum.disabled = false;
237                     }
238
239                   }
240
241                 }
242
243               }
244
245               if ( what.value == 'phonenum_manual' && what.checked ) {
246
247                 what.form.phonenum_manual.disabled = false;
248                 what.form.phonenum_manual.style.backgroundColor = '#ffffff';
249
250                 what.form.phonenum_state.disabled = true;
251
252                 document.getElementById('phonenum_state_label').style.color = '#999999';
253                 if ( document.getElementById('areacode_label') ) {
254                   document.getElementById('areacode_label').style.color = '#999999';
255                 }
256                 if ( document.getElementById('exchange_label') ) {
257                   document.getElementById('exchange_label').style.color = '#999999';
258                 }
259                 if ( document.getElementById('region_label') ) {
260                   document.getElementById('region_label').style.color = '#999999';
261                 }
262                 document.getElementById('phonenum_phonenum_label').style.color = '#999999';
263
264                 if ( what.form.areacode ) {
265                   what.form.areacode.disabled = true;
266                 }
267
268                 if ( what.form.exchange ) {
269                   what.form.exchange.disabled = true;
270                 }
271
272                 if ( what.form.region ) {
273                   what.form.region.disabled = true;
274                 }
275
276                 what.form.phonenum.disabled = true;
277               }
278
279             }
280           </SCRIPT>
281
282 %       }
283
284     </TABLE>
285
286 % } 
287 %   if (     ( $export->option('restrict_selection') eq 'tollfree'
288 %                || !$export->option('restrict_selection')
289 %            )
290 %        and $export->get_dids_can_tollfree
291 %      ) {
292             <font size="-1">Toll-free</font>
293             <% include('/elements/select-phonenum.html',
294                        'svcpart' => $svcpart,
295                        'empty'   => 'Select phone number',
296                        'tollfree' => 1,
297                        'prefix' => 'tollfree',
298                        'bulknum' => 0,
299                     )
300             %>
301 %       }
302
303 %       if ( $bulknum ) {
304             <div id="bulkdid" style="padding-top: 11px">
305 %               my $i;
306 %               for($i=0; $i < $bulknum; $i++) {
307                     <div id="bulkdid_<%$i%>" style="display: none">
308                         <input type="checkbox" id="checkbox_bulkdid_<%$i%>"
309                             name="bulkdid" value="">
310                         <label for="checkbox_bulkdid_<%$i%>" 
311                             id="label_bulkdid_<%$i%>"></label>
312                     </div>
313 %               }
314             </div>
315 %       }
316
317 % } else {
318
319     <% include( '/elements/input-text.html', %opt, 'type'=>'text' ) %>
320
321 % }
322 <%init>
323
324 my %opt = @_;
325
326 my $conf = new FS::Conf;
327
328 #false laziness w/tr-select-did.html
329 #XXX make sure this comes through on errors too
330 my $svcpart  = $opt{'svcpart'}
331             || $opt{'object'}->svcpart
332             || $opt{'object'}->cust_svc->svcpart;
333
334 my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } );
335 die "unknown svcpart $svcpart" unless $part_svc;
336
337 my @exports = $part_svc->part_export_did;
338 if ( scalar(@exports) > 1 ) {
339   die "more than one DID-providing export attached to svcpart $svcpart";
340 }
341 my $export = scalar(@exports) ? $exports[0] : '';
342
343 my $use_selector = scalar(@exports) ? 1 : 0;
344
345 my $bulknum = $opt{'bulknum'} || 0; #Bulk DID orders via ordering system, vs.
346 my $multiple = $opt{'multiple'} || 0; #just selecting a bunch at a time
347
348 my $country  = ( $export && $export->option('country') )
349             || $conf->config('countrydefault')
350             || 'US';
351
352 </%init>
353 </%method>