2 Sets up the xmlhttp, javascript and initial (empty) table for selecting cust_pkg_usageprice.
3 Available values are based on pkgpart, and can be updated when changing pkgpart
4 by passing the new pkgpart to the following javascript:
6 usageprice_pkg_changed( pkgpart, pkgnum )
8 The pkgnum input is optional, and will be used to set initial selected values.
10 If pkgpart is passed as an option to this element, will run usageprice_pkg_changed
11 once to initialize table; pkgnum can be passed as an option along with this.
13 You can disable usageprice selection temporarily (remove the fields from the form)
14 with the javascript usageprice_disable(1), and restore it with usageprice_disable(0,pkgnum).
15 While disabled, calling usageprice_pkg_changed will have no effect.
18 <& /elements/xmlhttp.html,
19 'url' => $p.'misc/xmlhttp-part_pkg_usageprice.html',
20 'subs' => [ 'get_part_pkg_usageprice' ],
23 <FONT CLASS = "fsinnerbox-title"
24 ID = "cust_pkg_usageprice_title"
25 STYLE = "display:none"
26 ><% mt('Usage add-ons') |h %></FONT>
27 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 ID="cust_pkg_usageprice_table">
30 <BR ID="cust_pkg_usageprice_br" STYLE="display:none">
34 var usagepriceCache = {};
35 var usagepriceDisabled = 0;
37 function usageprice_disable (disabled, pkgpart) {
39 usageprice_pkg_changed(0);
40 usagepriceDisabled = 1;
42 usagepriceDisabled = 0;
43 usageprice_pkg_changed(pkgpart);
47 // main function to invoke when pkgpart changes
48 function usageprice_pkg_changed (pkgpart, pkgnum) {
49 if (usagepriceDisabled) return;
50 clear_part_pkg_usageprice();
53 if (usagepriceCache[pkgpart]) {
54 update_part_pkg_usageprice(pkgpart);
56 get_part_pkg_usageprice( pkgpart || 0, pkgnum || 0, download_part_pkg_usageprice );
61 // removes table rows & hides table title
62 function clear_part_pkg_usageprice () {
63 var table = document.getElementById('cust_pkg_usageprice_table');
64 for ( var r = table.rows.length - 1; r >= 0; r-- ) {
67 document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
68 document.getElementById('cust_pkg_usageprice_br').style.display = 'none';
71 // catches response from xmlhttp request, updates cache & calls update function
72 function download_part_pkg_usageprice (part_pkg_usageprice) {
73 var usagepriceArray = JSON.parse(part_pkg_usageprice);
74 var pkgpart = usagepriceArray[0];
75 usagepriceCache[pkgpart] = usagepriceArray;
76 update_part_pkg_usageprice(pkgpart);
80 function update_part_pkg_usageprice (pkgpart) {
81 if (usagepriceDisabled) return;
82 clear_part_pkg_usageprice();
84 var usagepriceArray = usagepriceCache[pkgpart];
85 var table = document.getElementById('cust_pkg_usageprice_table');
87 // add the new usage price rows
89 for ( var s = 1; s < usagepriceArray.length; s=s+2 ) {
90 var html = usagepriceArray[s];
91 var javascript = usagepriceArray[s+1];
93 var row = table.insertRow(rownum++);
95 var widget_cell = document.createElement('TD');
96 widget_cell.style.paddingTop = "3px";
97 widget_cell.colSpan = "2";
98 widget_cell.innerHTML = html;
99 row.appendChild(widget_cell);
104 document.getElementById('cust_pkg_usageprice_title').style.display = '';
105 document.getElementById('cust_pkg_usageprice_br').style.display = '';
107 document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
108 document.getElementById('cust_pkg_usageprice_br').style.display = 'none';
113 % if ($opt{'pkgpart'}) {
114 <&| /elements/onload.js &>
115 usageprice_pkg_changed(<% $opt{'pkgpart'} %>, <% $opt{'pkgnum'} %>);