combine ticket notification scrips, #15353
[freeside.git] / httemplate / elements / select-exchange.html
1 <% include('/elements/xmlhttp.html',
2               'url'  => $p.'misc/exchanges.cgi',
3               'subs' => [ $opt{'prefix'}. 'get_exchanges' ],
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'} %>areacode_changed(what, callback) {
16
17     what.form.<% $opt{'prefix'} %>exchange.disabled = 'disabled';
18     what.form.<% $opt{'prefix'} %>exchange.style.display = 'none';
19     var exchangewait = document.getElementById('<% $opt{'prefix'} %>exchangewait');
20     exchangewait.style.display = '';
21     var exchangeerror = document.getElementById('<% $opt{'prefix'} %>exchangeerror');
22     exchangeerror.style.display = 'none';
23
24     what.form.<% $opt{'prefix'} %>phonenum.disabled = 'disabled';
25
26     areacode = what.options[what.selectedIndex].value;
27
28     function <% $opt{'prefix'} %>update_exchanges(exchanges) {
29
30       // blank the current exchange
31       for ( var i = what.form.<% $opt{'prefix'} %>exchange.length; i >= 0; i-- )
32           what.form.<% $opt{'prefix'} %>exchange.options[i] = null;
33       // blank the current phonenum too
34       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
35           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
36       if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
37         opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
38       }
39
40 %     if ($opt{empty}) {
41         opt(what.form.<% $opt{'prefix'} %>exchange, '', '<% $opt{empty} %>');
42 %     }
43
44       // add the new exchanges
45       var exchangeArray = eval('(' + exchanges + ')' );
46       for ( var s = 0; s < exchangeArray.length; s++ ) {
47           var exchangeLabel = exchangeArray[s];
48           if ( exchangeLabel == "" )
49               exchangeLabel = '(n/a)';
50           opt(what.form.<% $opt{'prefix'} %>exchange, exchangeArray[s], exchangeLabel);
51       }
52
53       exchangewait.style.display = 'none';
54       if ( exchangeArray.length >= 1 ) {
55         what.form.<% $opt{'prefix'} %>exchange.disabled = '';
56         what.form.<% $opt{'prefix'} %>exchange.style.display = '';
57       } else {
58         var exchangeerror = document.getElementById('<% $opt{'prefix'} %>exchangeerror');
59         exchangeerror.style.display = '';
60       }
61
62       //run the callback
63       if ( callback != null ) 
64         callback();
65     }
66
67     // go get the new exchanges
68     <% $opt{'prefix'} %>get_exchanges( areacode, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_exchanges );
69
70   }
71
72 </SCRIPT>
73
74 <DIV ID="exchangewait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding cities / exchanges</B></DIV>
75
76 <DIV ID="exchangeerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different area code</B></DIV>
77
78 <SELECT NAME="<% $opt{'prefix'} %>exchange" onChange="<% $opt{'prefix'} %>exchange_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
79   <OPTION VALUE="">Select city / exchange</OPTION>
80 </SELECT>
81
82 <%init>
83
84 my %opt = @_;
85
86 $opt{disabled} = 'disabled' unless exists $opt{disabled};
87
88 </%init>