This commit was generated by cvs2svn to compensate for changes in r10640,
[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                 document.getElementById('checkbox_bulkdid_'+i).checked = false;
70                 var tn = phonenum_sel.options[i+1].value;
71                 document.getElementById('checkbox_bulkdid_'+i).value = tn;
72                 document.getElementById('label_bulkdid_'+i).innerHTML = tn;
73             }
74             for(i = numCheckboxes; i < <% $opt{'bulknum'} %>; i++){
75                 document.getElementById('bulkdid_'+i).style.display = 'none';
76                 document.getElementById('checkbox_bulkdid_'+i).value = '';
77                 document.getElementById('checkbox_bulkdid_'+i).checked = false;
78                 document.getElementById('label_bulkdid_'+i).innerHTML = '';
79             }
80         }
81
82     }
83
84     // go get the new phonenums
85     <% $opt{'prefix'} %>get_phonenums( exchange, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
86
87   }
88
89 % if ( $opt{'tollfree'} ) {
90     function <% $opt{'prefix'} %>update_phonenums(phonenums) {
91         // lame hack so I can copy the code from above
92         what = document.getElementById('<% $opt{prefix} %>phonenum');
93
94         // blank the current phonenum
95       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
96           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
97
98 %     if ($opt{empty}) {
99         opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
100 %     }
101
102       // add the new phonenums
103       var phonenumArray = eval('(' + phonenums + ')' );
104       for ( var s = 0; s < phonenumArray.length; s++ ) {
105           var phonenumLabel = phonenumArray[s];
106           if ( phonenumLabel == "" )
107               phonenumLabel = '(n/a)';
108           opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
109       }
110
111       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
112
113       if ( phonenumArray.length >= 1 ) {
114         what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
115         what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
116       } 
117
118     }
119     <% $opt{'prefix'} %>get_phonenums( 'tollfree', <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
120 % }
121
122 </SCRIPT>
123
124 % unless ( $opt{'tollfree'} ) {
125 <DIV ID="phonenumwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding phone numbers</B></DIV>
126
127 <DIV ID="phonenumerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different city/exchange</B></DIV>
128 % }
129
130 <SELECT ID="<% $opt{'prefix'} %>phonenum" NAME="<% $opt{'prefix'} %>phonenum" 
131     notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>"
132     <% $opt{'disabled'} %>>
133   <OPTION VALUE="">Select phone number</OPTION>
134 </SELECT>
135
136 <%init>
137
138 my %opt = @_;
139
140 $opt{disabled} = 'disabled' unless exists $opt{disabled};
141
142 </%init>