This commit was generated by cvs2svn to compensate for changes in r6252,
[freeside.git] / httemplate / elements / tr-select-reason.html
1 <SCRIPT TYPE="text/javascript">
2   function sh_add<% $func_suffix %>()
3   {
4
5     if (document.getElementById('<% $id %>').selectedIndex == 0){
6       <% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
7     }else{
8       <% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
9     }
10
11 %if ($curuser->access_right($add_access_right)){
12
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';
21     } else {
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';
28     }
29
30 %}
31
32   }
33 </SCRIPT>
34
35 <TR>
36   <TD ALIGN="right">Reason</TD>
37   <TD>
38     <SELECT id="<% $id %>" name="<% $name %>" onFocus="sh_add<% $func_suffix %>()" onChange="sh_add<% $func_suffix %>()">
39       <OPTION VALUE="" <% ($init_reason eq "") ? 'SELECTED' : '' %>>Select Reason...</OPTION>
40 %    foreach my $reason (@reasons) {
41       <OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reasontype->type %> : <% $reason->reason %></OPTION>
42 %    }
43 %    if ($curuser->access_right($add_access_right)) {
44       <OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>>Add new reason</OPTION>
45 %    }
46 %
47     </SELECT>
48   </TD>
49 </TR>
50
51 %   my @types = qsearch( 'reason_type', { 'class' => $class } );
52 %   if (scalar(@types) < 1) {  # we should never reach this
53 <TR>
54   <TD ALIGN="right">
55     <P>No reason types.  Go add some. </P>
56   </TD>
57 </TR>
58 %   }elsif (scalar(@types) == 1) {
59 <TR>
60   <TD ALIGN="right">
61     <P id="new<% $name %>TLabel" style="display:<% $display %>">Reason Type</P>
62   </TD>
63   <TD>
64     <P id="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>"><% $types[0]->type %>
65     <INPUT type="hidden" name="new<% $name %>T" value="<% $types[0]->typenum %>">
66   </TD>
67 </TR>
68
69 %   }else{
70
71 <TR>
72   <TD ALIGN="right">
73     <P id="new<% $id %>TLabel" style="display:<% $display %>">Reason Type</P>
74   </TD>
75   <TD>
76     <SELECT id="new<% $id %>T" name="new<% $name %>T" "<% $disabled %>" style="display:<% $display %>">
77 %     for my $type (@types) {
78         <OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
79 %     }
80     </SELECT>
81   </TD>
82 </TR>
83 %   }
84
85 <TR>
86   <TD ALIGN="right">
87     <P id="new<% $id %>Label" style="display:<% $display %>">New Reason</P>
88   </TD>
89   <TD><INPUT id="new<% $id %>" name="new<% $name %>" type="text" value="<% $init_newreason |h %>" "<% $disabled %>" style="display:<% $display %>"></TD>
90 </TR>
91
92 <%init>
93
94 my %opt = @_;
95
96 my $name = $opt{'field'};
97 my $class = $opt{'reason_class'};
98 my $init_reason = $opt{'curr_value'};
99
100 my $controlledbutton = $opt{'control_button'};
101
102 ( my $func_suffix = $name ) =~ s/\./_/g;
103
104 my $id = $opt{'id'} || $func_suffix;
105
106 my( $add_access_right, $access_right ); 
107 if ($class eq 'C') {
108   $access_right = 'Cancel customer';
109   $add_access_right = 'Add on-the-fly cancel reason';
110 } elsif ($class eq 'S') {
111   $access_right = 'Suspend customer package';
112   $add_access_right = 'Add on-the-fly suspend reason';
113 } elsif ($class eq 'R') {
114   $access_right = 'Post credit';
115   $add_access_right = 'Add on-the-fly credit reason';
116 } else {
117   die "illegal class: $class";
118 }
119
120 my( $display, $disabled ) = ( 'none', 'DISABLED' );
121 my( $init_type, $init_newreason ) = ( '', '' );
122 if ($init_reason == -1 || ref($init_reason) ) {
123
124   $display = 'inline';
125   $disabled = '';
126
127   if ( ref($init_reason) ) {
128     $init_type      = $init_reason->{'typenum'};
129     $init_newreason = $init_reason->{'reason'};
130     $init_reason = -1;
131   }
132
133 }
134
135 my $extra_sql =
136   "WHERE class = '$class' and (disabled = '' OR disabled is NULL)";
137
138 my @reasons = qsearch({
139   table     => 'reason', 
140   hashref   => {},
141   extra_sql => $extra_sql,
142   addl_from => 'LEFT JOIN reason_type '.
143                ' ON reason_type.typenum = reason.reason_type',
144   order_by  => 'ORDER BY reason_type.type ASC, reason.reason ASC',
145 });
146
147 my $curuser = $FS::CurrentUser::CurrentUser;
148
149 </%init>