"on hold" package ordering and status, RT#28508
[freeside.git] / httemplate / elements / order_pkg.js
1 function pkg_changed () {
2   var form = document.OrderPkgForm;
3   var discountnum = form.discountnum;
4
5   if ( form.pkgpart.selectedIndex > 0 ) {
6
7     var opt = form.pkgpart.options[form.pkgpart.selectedIndex];
8     var date_button = document.getElementById('start_date_button');
9     var date_button_disabled = document.getElementById('start_date_disabled');
10     var date_text = document.getElementById('start_date_text');
11
12     var radio_now = document.getElementById('start_now');
13     //var radio_on_hold = document.getElementById('start_on_hold');
14     var radio_on_date = document.getElementById('start_on_date');
15
16     form.submitButton.disabled = false;
17     if ( discountnum ) {
18       if ( opt.getAttribute('data-can_discount') == 1 ) {
19         form.discountnum.disabled = false;
20         discountnum_changed(form.discountnum);
21       } else {
22         form.discountnum.disabled = true;
23         discountnum_changed(form.discountnum);
24       }
25     }
26
27     // if this form element exists, then the start date is a future
28     // package change date; don't replace it
29     if ( form.delay ) {
30       return;
31     }
32     form.start_date_text.value = opt.getAttribute('data-start_date');
33     if ( opt.getAttribute('data-can_start_date') == 1 ) {
34       date_text.style.backgroundColor = '#ffffff';
35       date_text.disabled = false;
36       date_button.style.display = '';
37       date_button_disabled.style.display = 'none';
38       if ( radio_on_date ) {
39         radio_on_date.disabled = false;
40         if ( form.start_date_text.value.length > 0 && radio_now.checked ) {
41           radio_now.checked = false;
42           radio_on_date.checked = true;
43         }
44       }
45     } else {
46       date_text.style.backgroundColor = '#dddddd';
47       date_text.disabled = true;
48       date_button.style.display = 'none';
49       date_button_disabled.style.display = '';
50       if ( radio_on_date ) {
51         if ( radio_on_date.checked ) {
52           radio_on_date.checked = false;
53           radio_now.checked = true;
54         }
55         radio_on_date.disabled = true;
56       }
57     }
58
59     get_part_pkg_usageprice( opt.value, update_part_pkg_usageprice );
60
61   } else {
62     form.submitButton.disabled = true;
63     if ( discountnum ) { form.discountnum.disabled = true; }
64     discountnum_changed(form.discountnum);
65   }
66 }
67
68 function update_part_pkg_usageprice(part_pkg_usageprice) {
69
70   var table = document.getElementById('cust_pkg_usageprice_table');
71
72   // black the current usage price rows
73   for ( var r = table.rows.length - 1; r >= 0; r-- ) {
74     table.deleteRow(r);
75   }
76
77   // add the new usage price rows
78   var rownum = 0;
79   var usagepriceArray = eval('(' + part_pkg_usageprice + ')' );
80   for ( var s = 0; s < usagepriceArray.length; s=s+2 ) {
81     //surely this should be some kind of JSON structure
82     var html       = usagepriceArray[s+0];
83     var javascript = usagepriceArray[s+1];
84
85     // a lot like ("inspiried by") edit/elements/edit.html function spawn_<%$field%>
86
87     // XXX evaluate the javascript
88     //if (window.ActiveXObject) {
89     //  window.execScript(newfunc);
90     //} else { /* (window.XMLHttpRequest) */
91     //  //window.eval(newfunc);
92     //  setTimeout(newfunc, 0);
93     //}
94
95     var row = table.insertRow(rownum++);
96
97     //var label_cell = document.createElement('TD');
98
99     //label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
100
101     //label_cell.style.textAlign = "right";
102     //label_cell.style.verticalAlign = "top";
103     //label_cell.style.borderTop = "1px solid black";
104     //label_cell.style.paddingTop = "5px";
105
106     //label_cell.innerHTML = '<% $label %>';
107
108     //row.appendChild(label_cell);
109           
110     var widget_cell = document.createElement('TD');
111
112     //widget_cell.style.borderTop = "1px solid black";
113     widget_cell.style.paddingTop = "3px";
114     widget_cell.colSpan = "2";
115
116     widget_cell.innerHTML = html;
117
118     row.appendChild(widget_cell);
119
120   }
121
122   if ( rownum > 0 ) {
123     document.getElementById('cust_pkg_usageprice_title').style.display = '';
124   } else {
125     document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
126   }
127
128 }
129
130
131 function standardize_new_location() {
132   var form = document.OrderPkgForm;
133   var loc = form.locationnum;
134   if (loc.type == 'select-one' && loc.options[loc.selectedIndex].value == -1){
135     standardize_locations();
136   } else {
137     form.submit();
138   }
139 }
140
141 function submit_abort() {
142   document.OrderPkgForm.submitButton.disabled = false;
143   nd(1);
144 }