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