1 <SCRIPT TYPE="text/javascript">
2 function sh_add<% $func_suffix %>()
5 if (document.getElementById('<% $id %>').selectedIndex == 0){
6 <% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
8 <% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
11 %if ($curuser->access_right($add_access_right)){
13 if (document.getElementById('<% $id %>').selectedIndex ==
14 (document.getElementById('<% $id %>').length - 1)) {
15 document.getElementById('new<% $id %>').disabled = false;
16 document.getElementById('new<% $id %>').style.display = 'inline';
17 document.getElementById('new<% $id %>Label').style.display = 'inline';
18 document.getElementById('new<% $id %>T').disabled = false;
19 document.getElementById('new<% $id %>T').style.display = 'inline';
20 document.getElementById('new<% $id %>TLabel').style.display = 'inline';
22 document.getElementById('new<% $id %>').disabled = true;
23 document.getElementById('new<% $id %>').style.display = 'none';
24 document.getElementById('new<% $id %>Label').style.display = 'none';
25 document.getElementById('new<% $id %>T').disabled = true;
26 document.getElementById('new<% $id %>T').style.display = 'none';
27 document.getElementById('new<% $id %>TLabel').style.display = 'none';
36 <TD ALIGN="right">Reason</TD>
38 <SELECT id="<% $id %>" name="<% $name %>" onFocus="sh_add<% $func_suffix %>()" onChange="sh_add<% $func_suffix %>()">
39 % my @reasons = qsearch( { table =>'reason',
41 % extra_sql => $extra_sql,
42 % addl_from => 'LEFT JOIN reason_type ON reason_type.typenum = reason.reason_type',
44 <OPTION VALUE="" <% ($init_reason eq "") ? 'SELECTED' : '' %>>Select Reason...</OPTION>
45 % foreach my $reason (@reasons) {
46 <OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reasontype->type %> : <% $reason->reason %></OPTION>
48 % if ($curuser->access_right($add_access_right)) {
49 <OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>>Add new reason</OPTION>
58 <P id="new<% $id %>TLabel" style="display:<% $display %>">Reason Type</P>
61 <SELECT id="new<% $id %>T" name="new<% $name %>T" "<% $disabled %>" style="display:<% $display %>">
62 % for my $type (qsearch( 'reason_type', { 'class' => $class } )){
63 <OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
71 <P id="new<% $id %>Label" style="display:<% $display %>">New Reason</P>
73 <TD><INPUT id="new<% $id %>" name="new<% $name %>" type="text" value="<% $init_newreason %>" "<% $disabled %>" style="display:<% $display %>"></TD>
80 my $name = $opt{'field'};
81 my $class = $opt{'reason_class'};
82 my $init_reason = $opt{'curr_value'};
84 my $controlledbutton = $opt{'control_button'};
86 ( my $func_suffix = $name ) =~ s/\./_/g;
88 my $id = $opt{'id'} || $func_suffix;
90 my( $add_access_right, $access_right );
92 $access_right = 'Cancel customer';
93 $add_access_right = 'Add on-the-fly cancel reason';
94 } elsif ($class eq 'S') {
95 $access_right = 'Suspend customer package';
96 $add_access_right = 'Add on-the-fly suspend reason';
98 die "illegal class: $class";
101 my( $display, $disabled ) = ( 'none', 'DISABLED' );
102 my( $init_type, $init_newreason ) = ( '', '' );
103 if ($init_reason == -1 || ref($init_reason) ) {
108 if ( ref($init_reason) ) {
109 $init_type = $init_reason->{'typenum'};
110 $init_newreason = $init_reason->{'reason'};
116 my $extra_sql = "WHERE class = '$class' ORDER BY reason_type";
117 my $curuser = $FS::CurrentUser::CurrentUser;