enable CardFortress in test database, #71513
[freeside.git] / httemplate / elements / select-phonenum.html
1 <%doc>
2 Selector for DID phone number.
3
4 Options:
5
6 - prefix: prefix for all the object IDs, field names, javascript functions,
7 etc. for including multiple DID selectors on a single page.
8
9 - empty: text to display when no number is selected ("empty_label")
10
11 - bulknum: allow bulk selection of up to this many numbers (self-service 
12 only? wtf?)
13
14 - svcpart: svcpart (required)
15
16 - tollfree: pass "tollfree" to misc/phonenums.cgi, instead of passing an 
17 exchange/region/anything else.
18
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'.
25
26
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 
30 </%doc>
31
32 <% include('/elements/xmlhttp.html',
33               'url'  => $p.'misc/phonenums.cgi',
34               'subs' => [ $opt{'prefix'}. 'get_phonenums' ],
35           )
36 %>
37
38 <SCRIPT TYPE="text/javascript">
39
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;
44   }
45
46   function <% $opt{'prefix'} %><% $previous %>_changed(what, callback) {
47
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';
54
55     var thing = "<% $previous eq 'region' ? '_REGION ' : '' %>" + what.options[what.selectedIndex].value;
56
57     function <% $opt{'prefix'} %>update_phonenums(phonenums) {
58
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;
63
64 %     if ($opt{empty}) {
65         if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ){
66           opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
67         }
68 %     }
69
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);
77       }
78
79       //var phonenumFormLabel = document.getElementById('<% $opt{'prefix'} %>phonenumlabel');
80
81       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
82
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 = '';
87       } else {
88         var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror');
89         phonenumerror.style.display = 'inline';
90         if ( reply.error ) {
91           phonenumerror.textContent = reply.error;
92         } else {
93           phonenumerror.textContent = 'Select a different <% $opt{'region'} ? 'region' : 'city/exchange' %>';
94         }
95       }
96
97       //run the callback
98       if ( callback != null ) 
99         callback();
100
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'} %>);
105             var i;
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;
112             }
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 = '';
118             }
119         }
120
121     }
122
123     // go get the new phonenums
124     <% $opt{'prefix'} %>get_phonenums( thing, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
125
126   }
127
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');
132
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;
136
137 %     if ($opt{empty}) {
138         opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
139 %     }
140
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);
148       }
149
150       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
151
152       if ( phonenumArray.length >= 1 ) {
153         what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
154         what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
155       } 
156
157     }
158     <% $opt{'prefix'} %>get_phonenums( 'tollfree', <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
159 % }
160
161 </SCRIPT>
162
163 % unless ( $opt{'tollfree'} ) {
164 <DIV ID="phonenumwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding phone numbers</B></DIV>
165
166 <DIV ID="phonenumerror" STYLE="display:none; font-weight: bold"><IMG SRC="<%$fsurl%>images/cross.png"></DIV>
167 % }
168
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'} %>"
174 >
175 % unless ( $opt{multiple} ) {
176     <OPTION VALUE="">Select phone number</OPTION>
177 % }
178 </SELECT>
179
180 <%init>
181
182 my %opt = @_;
183
184 $opt{disabled} = 'disabled' unless exists $opt{disabled};
185
186 my $previous = $opt{'region'} ? 'region' : 'exchange';
187
188 </%init>