summaryrefslogtreecommitdiff
path: root/httemplate/elements/tr-select-reason.html
blob: 2f8f3a10959dfbb23e1ef5a4fbebcbc41f7e4581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

<SCRIPT TYPE="text/javascript">
  function sh_add<% $name %>()
  {

    if (document.getElementById('<% $name %>').selectedIndex == 0){
      <% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
    }else{
      <% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
    }

%if ($curuser->access_right($access_right)){

    if (document.getElementById('<% $name %>').selectedIndex == 
         (document.getElementById('<% $name %>').length - 1)) {
      document.getElementById('new<% $name %>').disabled = false;
      document.getElementById('new<% $name %>').style.display = 'inline';
      document.getElementById('new<% $name %>Label').style.display = 'inline';
      document.getElementById('new<% $name %>T').disabled = false;
      document.getElementById('new<% $name %>T').style.display = 'inline';
      document.getElementById('new<% $name %>TLabel').style.display = 'inline';
    }else{
      document.getElementById('new<% $name %>').disabled = true;
      document.getElementById('new<% $name %>').style.display = 'none';
      document.getElementById('new<% $name %>Label').style.display = 'none';
      document.getElementById('new<% $name %>T').disabled = true;
      document.getElementById('new<% $name %>T').style.display = 'none';
      document.getElementById('new<% $name %>TLabel').style.display = 'none';
    }

%}

  }
</SCRIPT>

<TR>
  <TD ALIGN="right">Reason</TD>
  <TD>
    <SELECT id="<% $name %>" name="<% $name %>" onFocus="sh_add<% $name %>()" onChange="sh_add<% $name %>()">
%    my @reasons = qsearch( { table =>'reason', 
%                             hashref => {},
%                             extra_sql => $extra_sql,
%                             addl_from => 'LEFT JOIN reason_type ON reason_type.typenum = reason.reason_type',
%			     });
      <OPTION VALUE="" <% ($init_reason eq "") ? 'SELECTED' : '' %>>Select Reason...</OPTION>
%    foreach my $reason (@reasons) {
      <OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reason %></OPTION>
%    }
%    if ($curuser->access_right($access_right)) {
      <OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>>Add new reason</OPTION>
%    }
%
    </SELECT>
  </TD>
</TR>

<TR>
  <TD ALIGN="right">
    <P id="new<% $name %>TLabel" style="display:<% $display %>">Reason Type</P>
  </TD>
  <TD>
    <SELECT id="new<% $name %>T" name="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>">
%     for my $type (qsearch( 'reason_type', { 'class' => $class } )){
        <OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
%     }
    </SELECT>
  </TD>
</TR>

<TR>
  <TD ALIGN="right">
    <P id="new<% $name %>Label" style="display:<% $display %>">New Reason</P>
  </TD>
  <TD><INPUT id="new<% $name %>" name="new<% $name %>" type="text" value="<% $init_newreason %>" disabled="<% $disabled %>" style="display:<% $display %>"></TD>
</TR>

<%init>
my($name, $class, $init_reason, $init_type, $init_newreason, $controlledbutton) = @_;
my($extra_sql, $curuser, $access_right, $display, $disabled); 

if ($class eq 'C') {
  $access_right='Add on-the-fly cancel reason';
}elsif ($class eq 'S') {
  $access_right='Add on-the-fly suspend reason';
}else{
  print "illegal class: $class";
}

if ($init_reason == -1){
  $display = 'inline';
  $disabled = 'false';
}else{
  $display = 'none';
  $disabled = 'true';
}

$extra_sql = "WHERE class = '$class' ORDER BY reason_type";
$curuser = $FS::CurrentUser::CurrentUser;

</%init>