1c13ae03923e18755f369fb1683379732de12726
[freeside.git] / httemplate / elements / select-phonenum.html
1 <% include('/elements/xmlhttp.html',
2               'url'  => $p.'misc/phonenums.cgi',
3               'subs' => [ $opt{'prefix'}. 'get_phonenums' ],
4           )
5 %>
6
7 <SCRIPT TYPE="text/javascript">
8
9   function opt(what,value,text) {
10     var optionName = new Option(text, value, false, false);
11     var length = what.length;
12     what.options[length] = optionName;
13   }
14
15   function <% $opt{'prefix'} %>exchange_changed(what, callback) {
16
17     what.form.<% $opt{'prefix'} %>phonenum.disabled = 'disabled';
18     what.form.<% $opt{'prefix'} %>phonenum.style.display = 'none';
19     var phonenumwait = document.getElementById('<% $opt{'prefix'} %>phonenumwait');
20     phonenumwait.style.display = '';
21     var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror');
22     phonenumerror.style.display = 'none';
23
24     exchange = what.options[what.selectedIndex].value;
25
26     function <% $opt{'prefix'} %>update_phonenums(phonenums) {
27
28       // blank the current phonenum
29       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
30           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
31
32 %     if ($opt{empty}) {
33         opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
34 %     }
35
36       // add the new phonenums
37       var phonenumArray = eval('(' + phonenums + ')' );
38       for ( var s = 0; s < phonenumArray.length; s++ ) {
39           var phonenumLabel = phonenumArray[s];
40           if ( phonenumLabel == "" )
41               phonenumLabel = '(n/a)';
42           opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
43       }
44
45       //var phonenumFormLabel = document.getElementById('<% $opt{'prefix'} %>phonenumlabel');
46
47       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
48
49       phonenumwait.style.display = 'none';
50       if ( phonenumArray.length >= 1 ) {
51         what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
52         what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
53       } else {
54         var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror');
55         phonenumerror.style.display = '';
56       }
57
58       //run the callback
59       if ( callback != null ) 
60         callback();
61
62         var phonenum_sel = what.form.<% $opt{'prefix'} %>phonenum;
63         var bulkdid = document.getElementById('bulkdid');
64         if ( bulkdid != null ) {
65             var numCheckboxes = Math.min(phonenum_sel.options.length-1,<% $opt{'bulknum'} %>);
66             var i;
67             for(i = 0; i < numCheckboxes; i++){
68                 document.getElementById('bulkdid_'+i).style.display = 'block';
69                 var tn = phonenum_sel.options[i+1].value;
70                 document.getElementById('checkbox_bulkdid_'+i).value = tn;
71                 document.getElementById('label_bulkdid_'+i).innerHTML = tn;
72             }
73             for(i = numCheckboxes; i < <% $opt{'bulknum'} %>; i++){
74                 document.getElementById('bulkdid_'+i).style.display = 'none';
75                 document.getElementById('checkbox_bulkdid_'+i).value = '';
76                 document.getElementById('label_bulkdid_'+i).innerHTML = '';
77             }
78         }
79
80     }
81
82     // go get the new phonenums
83     <% $opt{'prefix'} %>get_phonenums( exchange, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
84
85   }
86
87 </SCRIPT>
88
89 <DIV ID="phonenumwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding phone numbers</B></DIV>
90
91 <DIV ID="phonenumerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different city/exchange</B></DIV>
92
93 <SELECT NAME="<% $opt{'prefix'} %>phonenum" notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
94   <OPTION VALUE="">Select phone number</OPTION>
95 </SELECT>
96
97 <%init>
98
99 my %opt = @_;
100
101 $opt{disabled} = 'disabled' unless exists $opt{disabled};
102
103 </%init>