combine ticket notification scrips, #15353
[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         if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ){
34           opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
35         }
36 %     }
37
38       // add the new phonenums
39       var phonenumArray = eval('(' + phonenums + ')' );
40       for ( var s = 0; s < phonenumArray.length; s++ ) {
41           var phonenumLabel = phonenumArray[s];
42           if ( phonenumLabel == "" )
43               phonenumLabel = '(n/a)';
44           opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
45       }
46
47       //var phonenumFormLabel = document.getElementById('<% $opt{'prefix'} %>phonenumlabel');
48
49       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
50
51       phonenumwait.style.display = 'none';
52       if ( phonenumArray.length >= 1 ) {
53         what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
54         what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
55       } else {
56         var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror');
57         phonenumerror.style.display = '';
58       }
59
60       //run the callback
61       if ( callback != null ) 
62         callback();
63
64         var phonenum_sel = what.form.<% $opt{'prefix'} %>phonenum;
65         var bulkdid = document.getElementById('bulkdid');
66         if ( bulkdid != null ) {
67             var numCheckboxes = Math.min(phonenum_sel.options.length-1,<% $opt{'bulknum'} %>);
68             var i;
69             for(i = 0; i < numCheckboxes; i++){
70                 document.getElementById('bulkdid_'+i).style.display = 'block';
71                 document.getElementById('checkbox_bulkdid_'+i).checked = false;
72                 var tn = phonenum_sel.options[i+1].value;
73                 document.getElementById('checkbox_bulkdid_'+i).value = tn;
74                 document.getElementById('label_bulkdid_'+i).innerHTML = tn;
75             }
76             for(i = numCheckboxes; i < <% $opt{'bulknum'} %>; i++){
77                 document.getElementById('bulkdid_'+i).style.display = 'none';
78                 document.getElementById('checkbox_bulkdid_'+i).value = '';
79                 document.getElementById('checkbox_bulkdid_'+i).checked = false;
80                 document.getElementById('label_bulkdid_'+i).innerHTML = '';
81             }
82         }
83
84     }
85
86     // go get the new phonenums
87     <% $opt{'prefix'} %>get_phonenums( exchange, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
88
89   }
90
91 % if ( $opt{'tollfree'} ) {
92     function <% $opt{'prefix'} %>update_phonenums(phonenums) {
93         // lame hack so I can copy the code from above
94         what = document.getElementById('<% $opt{prefix} %>phonenum');
95
96         // blank the current phonenum
97       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
98           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
99
100 %     if ($opt{empty}) {
101         opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
102 %     }
103
104       // add the new phonenums
105       var phonenumArray = eval('(' + phonenums + ')' );
106       for ( var s = 0; s < phonenumArray.length; s++ ) {
107           var phonenumLabel = phonenumArray[s];
108           if ( phonenumLabel == "" )
109               phonenumLabel = '(n/a)';
110           opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
111       }
112
113       what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
114
115       if ( phonenumArray.length >= 1 ) {
116         what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
117         what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
118       } 
119
120     }
121     <% $opt{'prefix'} %>get_phonenums( 'tollfree', <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
122 % }
123
124 </SCRIPT>
125
126 % unless ( $opt{'tollfree'} ) {
127 <DIV ID="phonenumwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding phone numbers</B></DIV>
128
129 <DIV ID="phonenumerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different city/exchange</B></DIV>
130 % }
131
132 <SELECT <% $opt{multiple} ? 'MULTIPLE SIZE=25' : '' %>
133         ID   = "<% $opt{'prefix'} %>phonenum"
134         NAME = "<% $opt{'prefix'} %>phonenum" 
135         <% $opt{'disabled'} %>
136 %#        notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>"
137 >
138 % unless ( $opt{multiple} ) {
139     <OPTION VALUE="">Select phone number</OPTION>
140 % }
141 </SELECT>
142
143 <%init>
144
145 my %opt = @_;
146
147 $opt{disabled} = 'disabled' unless exists $opt{disabled};
148
149 </%init>