+ // toggle submit button state
+ var submit_button = document.getElementById(<% $opt{control_button} |js_string %>);
+ if (submit_button) {
+ submit_button.disabled = ( select_reason.value == 0 );
+ }
+
+ // toggle visibility of 'new reason' fields
+ var new_fields = document.getElementById('<% $id %>_new_fields');
+ if ( select_reason.value == -1 ) {
+ new_fields.disabled = false;
+ new_fields.style.display = '';
+ } else {
+ new_fields.disabled = true;
+ new_fields.style.display = 'none';
+ }
+
+ }
+ <&| onload.js &> <% $id %>_changed(); </&>
+</SCRIPT>
+
+%# sadly can't just use add_inline here, as we have non-text fields
+<& tr-select-table.html,
+ 'label' => 'Reason',
+ 'field' => $name,
+ 'id' => $id,
+ 'table' => 'reason',
+ 'records' => \@reasons,
+ 'label_callback' => sub { my $reason = shift;
+ $reason->type . ' : ' . $reason->reason },
+ 'disable_empty' => 1,
+ 'pre_options' => [ 0 => 'Select reason...' ],
+ 'post_options' => [ -1 => 'Add new reason' ],
+ 'curr_value' => $init_reason,
+ 'onchange' => $id.'_changed()',
+&>
+
+% # "add new reason" fields
+% # should be a <fieldset>, but that doesn't fit well into the table
+
+<TR id="<% $id %>_new_fields">
+ <TD COLSPAN=2>
+ <TABLE CLASS="inv" STYLE="text-align: left">
+
+ <& tr-input-text.html,
+ label => 'New reason',
+ field => $id.'_new_reason'
+ &>
+
+% my @types = qsearch( 'reason_type', { 'class' => $class } );
+% if (scalar(@types) < 1) { # we should never reach this
+ <TR>
+ <TD ALIGN="right">
+ <P><% mt('No reason types. Please add some.') |h %></P>
+ </TD>
+ </TR>
+% } elsif (scalar(@types) == 1) {
+ <& tr-fixed.html,
+ label => 'Reason type',
+ field => $id.'_new_reason_type',
+ curr_value => $types[0]->typenum,
+ formatted_value => $types[0]->type,
+ &>
+% } else { # more than one type, the normal case
+ <& tr-select-table.html,
+ label => 'Reason type',
+ field => $id.'_new_reason_type',
+ table => 'reason_type',
+ name_col => 'type',
+ hashref => { 'class' => $class },
+ disable_empty => 1,
+ &>
+% } # scalar(@types)
+
+% if ( $class eq 'S' ) {
+ <& tr-checkbox.html,
+ label => 'Credit the unused portion of service when suspending',
+ field => $id.'_new_unused_credit',
+ value => 'Y'
+ &>
+ <& tr-select-part_pkg.html,
+ label => 'Charge this fee when unsuspending',
+ field => $id.'_new_unsuspend_pkgpart',
+ hashref => { disabled => '', freq => '0' },
+ empty_label => 'none',
+ &>
+ <& tr-checkbox.html,
+ label => 'Hold unsuspension fee until the next bill',
+ field => $id.'_new_unsuspend_hold',
+ value => 'Y',
+ &>
+% }
+ </table>
+ </td>
+</tr>
+
+% # container for hints