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">
33 var usagepriceCache = {};
34 var usagepriceDisabled = 0;
36 function usageprice_disable (disabled, pkgpart) {
38 usageprice_pkg_changed(0);
39 usagepriceDisabled = 1;
41 usagepriceDisabled = 0;
42 usageprice_pkg_changed(pkgpart);
46 // main function to invoke when pkgpart changes
47 function usageprice_pkg_changed (pkgpart, pkgnum) {
48 if (usagepriceDisabled) return;
49 clear_part_pkg_usageprice();
52 if (usagepriceCache[pkgpart]) {
53 update_part_pkg_usageprice(pkgpart);
55 get_part_pkg_usageprice( pkgpart || 0, pkgnum || 0, download_part_pkg_usageprice );
60 // removes table rows & hides table title
61 function clear_part_pkg_usageprice () {
62 var table = document.getElementById('cust_pkg_usageprice_table');
63 for ( var r = table.rows.length - 1; r >= 0; r-- ) {
66 document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
69 // catches response from xmlhttp request, updates cache & calls update function
70 function download_part_pkg_usageprice (part_pkg_usageprice) {
71 var usagepriceArray = JSON.parse(part_pkg_usageprice);
72 var pkgpart = usagepriceArray[0];
73 usagepriceCache[pkgpart] = usagepriceArray;
74 update_part_pkg_usageprice(pkgpart);
78 function update_part_pkg_usageprice (pkgpart) {
79 if (usagepriceDisabled) return;
80 clear_part_pkg_usageprice();
82 var usagepriceArray = usagepriceCache[pkgpart];
83 var table = document.getElementById('cust_pkg_usageprice_table');
85 // add the new usage price rows
87 for ( var s = 1; s < usagepriceArray.length; s=s+2 ) {
88 var html = usagepriceArray[s];
89 var javascript = usagepriceArray[s+1];
91 var row = table.insertRow(rownum++);
93 var widget_cell = document.createElement('TD');
94 widget_cell.style.paddingTop = "3px";
95 widget_cell.colSpan = "2";
96 widget_cell.innerHTML = html;
97 row.appendChild(widget_cell);
102 document.getElementById('cust_pkg_usageprice_title').style.display = '';
104 document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
109 % if ($opt{'pkgpart'}) {
110 <&| /elements/onload.js &>
111 usageprice_pkg_changed(<% $opt{'pkgpart'} %>, <% $opt{'pkgnum'} %>);