customer referral report, RT#75757
[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 = 'inline';
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       var reply = JSON.parse(exchanges);
31       // blank the current exchange
32       for ( var i = what.form.<% $opt{'prefix'} %>exchange.length; i >= 0; i-- )
33           what.form.<% $opt{'prefix'} %>exchange.options[i] = null;
34       // blank the current phonenum too
35       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
36           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
37       if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
38         opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
39       }
40
41 %     if ($opt{empty}) {
42         opt(what.form.<% $opt{'prefix'} %>exchange, '', '<% $opt{empty} %>');
43 %     }
44
45       // add the new exchanges
46       var exchangeArray = reply.exchanges;
47       for ( var s = 0; s < exchangeArray.length; s++ ) {
48           var exchangeLabel = exchangeArray[s];
49           if ( exchangeLabel == "" )
50               exchangeLabel = '(n/a)';
51           opt(what.form.<% $opt{'prefix'} %>exchange, exchangeArray[s], exchangeLabel);
52       }
53
54       exchangewait.style.display = 'none';
55       if ( exchangeArray.length >= 1 ) {
56         what.form.<% $opt{'prefix'} %>exchange.disabled = '';
57         what.form.<% $opt{'prefix'} %>exchange.style.display = '';
58       } else {
59         var exchangeerror = document.getElementById('<% $opt{'prefix'} %>exchangeerror');
60         exchangeerror.style.display = 'inline';
61         if ( reply.error ) {
62           exchangeerror.textContent = reply.error;
63         } else {
64           exchangeerror.textContent = 'Select a different area code';
65         }
66
67       }
68
69       //run the callback
70       if ( callback != null ) 
71         callback();
72     }
73
74     // go get the new exchanges
75     <% $opt{'prefix'} %>get_exchanges( areacode, <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_exchanges );
76
77   }
78
79 </SCRIPT>
80
81 <DIV ID="exchangewait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding cities / exchanges</B></DIV>
82
83 <DIV ID="exchangeerror" STYLE="display:none; font-weight: bold"><IMG SRC="<%$fsurl%>images/cross.png"></DIV>
84
85 <SELECT NAME="<% $opt{'prefix'} %>exchange" onChange="<% $opt{'prefix'} %>exchange_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
86   <OPTION VALUE="">Select city / exchange</OPTION>
87 </SELECT>
88
89 <%init>
90
91 my %opt = @_;
92
93 $opt{disabled} = 'disabled' unless exists $opt{disabled};
94
95 </%init>