2 Selector for DID phone number.
6 - prefix: prefix for all the object IDs, field names, javascript functions,
7 etc. for including multiple DID selectors on a single page.
9 - empty: text to display when no number is selected ("empty_label")
11 - bulknum: allow bulk selection of up to this many numbers (self-service
14 - svcpart: svcpart (required)
16 - tollfree: pass "tollfree" to misc/phonenums.cgi, instead of passing an
17 exchange/region/anything else.
19 - region: corresponds to the inverse of "get_dids_npa_select". The selector
20 creates an on-change handler telling the previous selector in the hierarchy
21 to update the list of phone numbers. If 'region' is true, it will look for
22 a previous selector named "region", and prefix the query it sends to
23 phonenums.cgi with '_REGION', which results in get_dids() being called
24 with a 'region' parameter instead of 'ratecenter' and 'state'.
27 Internally, this will set up an exchange_changed or region_changed function
28 to refresh the phone number list. The function will fetch misc/phonenums.cgi,
29 passing the exchange (or region) and
32 <% include('/elements/xmlhttp.html',
33 'url' => $p.'misc/phonenums.cgi',
34 'subs' => [ $opt{'prefix'}. 'get_phonenums' ],
38 <SCRIPT TYPE="text/javascript">
40 function opt(what,value,text) {
41 var optionName = new Option(text, value, false, false);
42 var length = what.length;
43 what.options[length] = optionName;
46 function <% $opt{'prefix'} %><% $previous %>_changed(what, callback) {
48 what.form.<% $opt{'prefix'} %>phonenum.disabled = 'disabled';
49 what.form.<% $opt{'prefix'} %>phonenum.style.display = 'none';
50 var phonenumwait = document.getElementById('<% $opt{'prefix'} %>phonenumwait');
51 phonenumwait.style.display = 'inline';
52 var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror');
53 phonenumerror.style.display = 'none';
55 var thing = "<% $previous eq 'region' ? '_REGION ' : '' %>" + what.options[what.selectedIndex].value;
57 function <% $opt{'prefix'} %>update_phonenums(phonenums) {
59 var reply = JSON.parse(phonenums);
60 // blank the current phonenum
61 for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
62 what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
65 if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ){
66 opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
70 // add the new phonenums
71 var phonenumArray = reply.phonenums;
72 for ( var s = 0; s < phonenumArray.length; s++ ) {
73 var phonenumLabel = phonenumArray[s];
74 if ( phonenumLabel == "" )
75 phonenumLabel = '(n/a)';
76 opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
79 //var phonenumFormLabel = document.getElementById('<% $opt{'prefix'} %>phonenumlabel');
81 what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
83 phonenumwait.style.display = 'none';
84 if ( phonenumArray.length >= 1 ) {
85 what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
86 what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
88 var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror');
89 phonenumerror.style.display = 'inline';
91 phonenumerror.textContent = reply.error;
93 phonenumerror.textContent = 'Select a different <% $opt{'region'} ? 'region' : 'city/exchange' %>';
98 if ( callback != null )
101 var phonenum_sel = what.form.<% $opt{'prefix'} %>phonenum;
102 var bulkdid = document.getElementById('bulkdid');
103 if ( bulkdid != null ) {
104 var numCheckboxes = Math.min(phonenum_sel.options.length-1,<% $opt{'bulknum'} %>);
106 for(i = 0; i < numCheckboxes; i++){
107 document.getElementById('bulkdid_'+i).style.display = 'block';
108 document.getElementById('checkbox_bulkdid_'+i).checked = false;
109 var tn = phonenum_sel.options[i+1].value;
110 document.getElementById('checkbox_bulkdid_'+i).value = tn;
111 document.getElementById('label_bulkdid_'+i).innerHTML = tn;
113 for(i = numCheckboxes; i < <% $opt{'bulknum'} %>; i++){
114 document.getElementById('bulkdid_'+i).style.display = 'none';
115 document.getElementById('checkbox_bulkdid_'+i).value = '';
116 document.getElementById('checkbox_bulkdid_'+i).checked = false;
117 document.getElementById('label_bulkdid_'+i).innerHTML = '';
123 // go get the new phonenums
124 <% $opt{'prefix'} %>get_phonenums( thing, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
128 % if ( $opt{'tollfree'} ) {
129 function <% $opt{'prefix'} %>update_phonenums(phonenums) {
130 // lame hack so I can copy the code from above
131 what = document.getElementById('<% $opt{prefix} %>phonenum');
133 // blank the current phonenum
134 for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
135 what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
138 opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
141 // add the new phonenums
142 var phonenumArray = eval('(' + phonenums + ')' );
143 for ( var s = 0; s < phonenumArray.length; s++ ) {
144 var phonenumLabel = phonenumArray[s];
145 if ( phonenumLabel == "" )
146 phonenumLabel = '(n/a)';
147 opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
150 what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
152 if ( phonenumArray.length >= 1 ) {
153 what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
154 what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
158 <% $opt{'prefix'} %>get_phonenums( 'tollfree', <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
163 % unless ( $opt{'tollfree'} ) {
164 <DIV ID="phonenumwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding phone numbers</B></DIV>
166 <DIV ID="phonenumerror" STYLE="display:none; font-weight: bold"><IMG SRC="<%$fsurl%>images/cross.png"></DIV>
169 <SELECT <% $opt{multiple} ? 'MULTIPLE SIZE=25' : '' %>
170 ID = "<% $opt{'prefix'} %>phonenum"
171 NAME = "<% $opt{'prefix'} %>phonenum"
172 <% $opt{'disabled'} %>
173 %# notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>"
175 % unless ( $opt{multiple} ) {
176 <OPTION VALUE="">Select phone number</OPTION>
184 $opt{disabled} = 'disabled' unless exists $opt{disabled};
186 my $previous = $opt{'region'} ? 'region' : 'exchange';