fix A/R report
[freeside.git] / httemplate / misc / part_pkg_fcc_options.html
1 <& /elements/header-popup.html &>
2
3 <STYLE>
4   fieldset {
5     border: 1px solid #7e0079;
6     border-radius: 8px;
7     background-color: #fff;
8   }
9   fieldset.inv {
10     border: none;
11   }
12   fieldset:disabled {
13     display: none;
14   } 
15 </STYLE>
16
17 <%def .checkbox>
18 % my $field = shift;
19 % my $extra = shift || '';
20 <INPUT TYPE="checkbox" NAME="<% $field %>" ID="<% $field %>" VALUE="1" <%$extra%>>
21 </%def>
22
23 <FORM NAME="fcc_option_form">
24 % # The option structure is hardcoded.  The FCC rules changed enough from 
25 % # the original 477 report to the 2013 revision that any data-driven 
26 % # mechanism for expressing the original rules would likely fail to 
27 % # accommodate the new ones.  Therefore, we assume that whatever the FCC
28 % # does NEXT will also require a rewrite of this form, and we'll deal with
29 % # that when it arrives.
30   <P>
31     <LABEL FOR="media">Media type</LABEL>
32     <SELECT NAME="media" ID="media">
33       <OPTION VALUE=""></OPTION>
34 % foreach (keys(%$media_types)) {
35       <OPTION VALUE="<% $_ %>"><% $_ %></OPTION>
36 % }
37     </SELECT>
38   </P>
39   <P>
40     <& .checkbox, 'is_consumer' &>
41     <LABEL FOR="is_consumer">This is a consumer-grade package</LABEL>
42   </P>
43   <P>
44     <& .checkbox, 'is_broadband' &>
45     <LABEL FOR="is_broadband">This package provides broadband service</LABEL>
46     <FIELDSET ID="broadband">
47       <LABEL FOR="technology">Technology of transmission</LABEL>
48       <SELECT NAME="technology" ID="technology"> </SELECT>
49       <BR>
50       <LABEL FOR="broadband_downstream">Downstream speed (Mbps)</LABEL>
51       <INPUT NAME="broadband_downstream" ID="broadband_downstream">
52       <BR>
53       <LABEL FOR="broadband_upstream">Upstream speed (Mbps)</LABEL>
54       <INPUT NAME="broadband_upstream" ID="broadband_upstream">
55     </FIELDSET>
56   </P>
57   <P>
58     <& .checkbox, 'is_phone' &>
59     <LABEL FOR="is_phone">This package provides local telephone service</LABEL>
60     <FIELDSET ID="phone">
61       <LABEL FOR="phone_wholesale">Marketed as</LABEL>
62       <SELECT NAME="phone_wholesale" ID="phone_wholesale">
63         <OPTION VALUE="">end user</OPTION>
64         <OPTION VALUE="1">wholesale</OPTION>
65       </SELECT>
66       <FIELDSET CLASS="inv" ID="phone0" DISABLED="1">
67         <LABEL FOR="phone_lines">Number of voice-grade equivalents</LABEL>
68         <INPUT NAME="phone_lines" ID="phone_lines">
69         <BR>
70         <LABEL FOR="phone_longdistance">Are you the presubscribed long-distance carrier?</LABEL>
71         <& .checkbox, 'phone_longdistance' &>
72         <BR>
73         <LABEL FOR="phone_localloop">Local loop arrangement</LABEL>
74         <SELECT NAME="phone_localloop" ID="phone_localloop">
75           <OPTION VALUE="owned">You own the local loop</OPTION>
76           <OPTION VALUE="leased">You lease UNE-L from another carrier</OPTION>
77           <OPTION VALUE="resale">You resell another carrier's service</OPTION>
78         </SELECT>
79       </FIELDSET>
80       <FIELDSET CLASS="inv" ID="phone1" DISABLED="1">
81         <LABEL FOR="phone_vges">Number of voice-grade equivalents (if any)</LABEL>
82         <INPUT NAME="phone_vges" ID="phone_vges">
83         <BR>
84         <LABEL FOR="phone_circuits">Number of unswitched circuits (if any)</LABEL>
85         <INPUT NAME="phone_circuits" ID="phone_circuits">
86       </FIELDSET>
87     </FIELDSET>
88   </P>
89   <P>
90     <& .checkbox, 'is_voip' &>
91     <LABEL FOR="is_voip">This package provides VoIP telephone service</LABEL>
92     <FIELDSET ID="voip">
93       <LABEL FOR="voip_sessions">Number of simultaneous calls possible</LABEL>
94       <INPUT NAME="voip_sessions" ID="voip_sessions">
95       <BR>
96       <& .checkbox, 'voip_lastmile' &>
97       <LABEL FOR="voip_lastmile">Do you also provide last-mile connectivity?</LABEL>
98     </FIELDSET>
99   </P>
100   <P>
101     <& .checkbox, 'is_mobile' &>
102     <LABEL FOR="is_mobile">This package provides mobile telephone service</LABEL>
103     <FIELDSET ID="mobile">
104       <LABEL FOR="mobile_direct">Do you bill the customer directly?</LABEL>
105       <& .checkbox, 'mobile_direct' &>
106     </FIELDSET>
107   </P>
108   <DIV WIDTH="100%" STYLE="text-align:center">
109     <INPUT TYPE="submit" VALUE="Save changes">
110   </DIV>
111 </FORM>
112
113 <SCRIPT TYPE="text/javascript">
114 // this form is invoked as a popup; the current values of the parent 
115 // object are in the form field ID passed as the 'id' param
116
117 var parent_input = window.parent.document.getElementById('<% $parent_id %>');
118 var curr_values = JSON.parse(window.parent_input.value);
119 var form = document.forms['fcc_option_form'];
120 var media_types = <% encode_json($media_types) %>
121 var technology_labels = <% encode_json($technology_labels) %>
122
123 function set_tech_options() {
124   var form = document.forms['fcc_option_form'];
125   var curr_type = form.elements['media'].value;
126   var technology_obj = form.elements['technology'];
127   technology_obj.options.length = 0;
128   if (media_types[curr_type]) {
129     for( var i = 0; i < media_types[curr_type].length; i++ ) {
130       var value = media_types[curr_type][i];
131       var o = document.createElement('OPTION');
132       o.text = technology_labels[value]
133       o.value = value;
134       technology_obj.add(o);
135     }
136   }
137 }
138   
139 function save_changes() {
140   var form = document.forms['fcc_option_form'];
141   var data = {};
142   for (var i = 0; i < form.elements.length; i++) {
143     if (form.elements[i].type == 'submit')
144       continue;
145
146     // quick and dirty test for whether the element is displayed
147     if (form.elements[i].clientHeight > 0) {
148       if (form.elements[i].type == 'checkbox') {
149         if (form.elements[i].checked) {
150           data[ form.elements[i].name ] = 1;
151         }
152       } else {
153         data[ form.elements[i].name ] = form.elements[i].value;
154       }
155     }
156   }
157   parent_input.value = JSON.stringify(data);
158   // update the display
159   parent.finish_edit_fcc(parent_input.id);
160 }
161
162 function enable_fieldset(fieldset_id) {
163   var fieldset = document.getElementById(fieldset_id);
164   return function () { fieldset.disabled = !this.checked; };
165 }
166
167 <&| /elements/onload.js &>
168   function addEventListener(target, action, listener) {
169     if (target.addEventListener) {
170       target.addEventListener(action, listener);
171     } else if (target.attachEvent) { // IE 8 fails at everything
172       target.attachEvent('on'+action, listener);
173     }
174   }
175
176   // set up all event handlers
177   addEventListener(form, 'submit', save_changes);
178
179   var sections = [ 'broadband', 'phone', 'voip', 'mobile' ];
180   for(var i = 0; i < sections.length; i++) {
181     var toggle = form.elements['is_'+sections[i]];
182     addEventListener(toggle, 'change', enable_fieldset(sections[i]));
183   }
184
185   addEventListener(form.elements['media'], 'change', set_tech_options);
186   addEventListener(form.elements['phone_wholesale'], 'change',
187     function () {
188       form.elements['phone0'].disabled = (this.value == 1);
189       form.elements['phone1'].disabled = (this.value == '');
190     }
191   );
192   addEventListener(form.elements['is_phone'], 'change', 
193     function() {
194       form.elements['phone_wholesale'].dispatchEvent( new Event('change') );
195     }
196   );
197
198   // load data from the parent form and trigger handlers
199   for(var i = 0; i < form.elements.length; i++) {
200     var input_obj = form.elements[i];
201     if (input_obj.type == 'submit') {
202       //nothing
203     } else if (input_obj.type == 'checkbox') {
204       input_obj.checked = (curr_values[input_obj.name] > 0);
205     } else {
206       input_obj.value = curr_values[input_obj.name] || '';
207     }
208     input_obj.dispatchEvent( new Event('change') );
209   }
210
211 </&>
212
213 </SCRIPT>
214 <& /elements/footer.html &>
215 <%init>
216 my $media_types = FS::part_pkg_fcc_option->media_types;
217 my $technology_labels = FS::part_pkg_fcc_option->technology_labels;
218
219 my $parent_id = $cgi->param('id');
220 </%init>