RT#21463 Option to show disabled package definitions [bug fix]
[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       // blank the current phonenum
60       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
61           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
62
63 %     if ($opt{empty}) {
64         if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ){
65           opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
66         }
67 %     }
68
69       // add the new phonenums
70       var phonenumArray = eval('(' + phonenums + ')' );
71       for ( var s = 0; s < phonenumArray.length; s++ ) {
72           var phonenumLabel = phonenumArray[s];
73           if ( phonenumLabel == "" )
74               phonenumLabel = '(n/a)';
75           opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
76       }
77
78       //var phonenumFormLabel = document.getElementById('<% $opt{'prefix'} %>phonenumlabel');
79
80       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
81
82       phonenumwait.style.display = 'none';
83       if ( phonenumArray.length >= 1 ) {
84         what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
85         what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
86       } else {
87         var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror');
88         phonenumerror.style.display = 'inline';
89       }
90
91       //run the callback
92       if ( callback != null ) 
93         callback();
94
95         var phonenum_sel = what.form.<% $opt{'prefix'} %>phonenum;
96         var bulkdid = document.getElementById('bulkdid');
97         if ( bulkdid != null ) {
98             var numCheckboxes = Math.min(phonenum_sel.options.length-1,<% $opt{'bulknum'} %>);
99             var i;
100             for(i = 0; i < numCheckboxes; i++){
101                 document.getElementById('bulkdid_'+i).style.display = 'block';
102                 document.getElementById('checkbox_bulkdid_'+i).checked = false;
103                 var tn = phonenum_sel.options[i+1].value;
104                 document.getElementById('checkbox_bulkdid_'+i).value = tn;
105                 document.getElementById('label_bulkdid_'+i).innerHTML = tn;
106             }
107             for(i = numCheckboxes; i < <% $opt{'bulknum'} %>; i++){
108                 document.getElementById('bulkdid_'+i).style.display = 'none';
109                 document.getElementById('checkbox_bulkdid_'+i).value = '';
110                 document.getElementById('checkbox_bulkdid_'+i).checked = false;
111                 document.getElementById('label_bulkdid_'+i).innerHTML = '';
112             }
113         }
114
115     }
116
117     // go get the new phonenums
118     <% $opt{'prefix'} %>get_phonenums( thing, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
119
120   }
121
122 % if ( $opt{'tollfree'} ) {
123     function <% $opt{'prefix'} %>update_phonenums(phonenums) {
124         // lame hack so I can copy the code from above
125         what = document.getElementById('<% $opt{prefix} %>phonenum');
126
127         // blank the current phonenum
128       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
129           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
130
131 %     if ($opt{empty}) {
132         opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
133 %     }
134
135       // add the new phonenums
136       var phonenumArray = eval('(' + phonenums + ')' );
137       for ( var s = 0; s < phonenumArray.length; s++ ) {
138           var phonenumLabel = phonenumArray[s];
139           if ( phonenumLabel == "" )
140               phonenumLabel = '(n/a)';
141           opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
142       }
143
144       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
145
146       if ( phonenumArray.length >= 1 ) {
147         what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
148         what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
149       } 
150
151     }
152     <% $opt{'prefix'} %>get_phonenums( 'tollfree', <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
153 % }
154
155 </SCRIPT>
156
157 % unless ( $opt{'tollfree'} ) {
158 <DIV ID="phonenumwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding phone numbers</B></DIV>
159
160 <DIV ID="phonenumerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different <% $opt{'region'} ? 'region' : 'city/exchange' %></B></DIV>
161 % }
162
163 <SELECT <% $opt{multiple} ? 'MULTIPLE SIZE=25' : '' %>
164         ID   = "<% $opt{'prefix'} %>phonenum"
165         NAME = "<% $opt{'prefix'} %>phonenum" 
166         <% $opt{'disabled'} %>
167 %#        notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>"
168 >
169 % unless ( $opt{multiple} ) {
170     <OPTION VALUE="">Select phone number</OPTION>
171 % }
172 </SELECT>
173
174 <%init>
175
176 my %opt = @_;
177
178 $opt{disabled} = 'disabled' unless exists $opt{disabled};
179
180 my $previous = $opt{'region'} ? 'region' : 'exchange';
181
182 </%init>