Option to ignore old CDRs, RT#81480
[freeside.git] / httemplate / elements / table-cust_pkg_usageprice.html
1 <%doc>
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:
5
6   usageprice_pkg_changed( pkgpart, pkgnum )
7
8 The pkgnum input is optional, and will be used to set initial selected values.
9
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.
12
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.
16 </%doc>
17
18 <& /elements/xmlhttp.html,
19               'url'  => $p.'misc/xmlhttp-part_pkg_usageprice.html',
20               'subs' => [ 'get_part_pkg_usageprice' ],
21 &>
22
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">
28
29 </TABLE>
30 <BR ID="cust_pkg_usageprice_br" STYLE="display:none">
31
32 <SCRIPT>
33
34 var usagepriceCache = {};
35 var usagepriceDisabled = 0;
36
37 function usageprice_disable (disabled, pkgpart) {
38   if (disabled) {
39     usageprice_pkg_changed(0);
40     usagepriceDisabled = 1;
41   } else {
42     usagepriceDisabled = 0;
43     usageprice_pkg_changed(pkgpart);
44   }
45 }
46
47 // main function to invoke when pkgpart changes
48 function usageprice_pkg_changed (pkgpart, pkgnum) {
49   if (usagepriceDisabled) return;
50   clear_part_pkg_usageprice();
51
52   if (pkgpart) {
53     if (usagepriceCache[pkgpart]) {
54       update_part_pkg_usageprice(pkgpart);
55     } else {
56       get_part_pkg_usageprice( pkgpart || 0, pkgnum || 0, download_part_pkg_usageprice );
57     }
58   }
59 }
60
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-- ) {
65     table.deleteRow(r);
66   }
67   document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
68   document.getElementById('cust_pkg_usageprice_br').style.display = 'none';
69 }
70
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);
77 }
78
79 // updates from cache
80 function update_part_pkg_usageprice (pkgpart) {
81   if (usagepriceDisabled) return;
82   clear_part_pkg_usageprice();
83
84   var usagepriceArray = usagepriceCache[pkgpart];
85   var table = document.getElementById('cust_pkg_usageprice_table');
86
87   // add the new usage price rows
88   var rownum = 0;
89   for ( var s = 1; s < usagepriceArray.length; s=s+2 ) {
90     var html = usagepriceArray[s];
91     var javascript = usagepriceArray[s+1];
92
93     var row = table.insertRow(rownum++);
94
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);
100
101   }
102
103   if ( rownum > 0 ) {
104     document.getElementById('cust_pkg_usageprice_title').style.display = '';
105     document.getElementById('cust_pkg_usageprice_br').style.display = '';
106   } else {
107     document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
108     document.getElementById('cust_pkg_usageprice_br').style.display = 'none';
109   }
110
111 }
112
113 % if ($opt{'pkgpart'}) {
114 <&| /elements/onload.js &>
115 usageprice_pkg_changed(<% $opt{'pkgpart'} %>, <% $opt{'pkgnum'} %>);
116 </&>
117 % }
118
119 </SCRIPT>
120
121 <%init>
122 my %opt = @_;
123 </%init>
124
125