-<TR>
- <TD ALIGN="right"><% mt('Reason') |h %></TD>
- <TD>
- <SELECT id="<% $id %>" name="<% $name %>" onFocus="sh_add<% $func_suffix %>()" onChange="sh_add<% $func_suffix %>()">
- <OPTION VALUE="" <% ($init_reason eq '') ? 'SELECTED' : '' %>><% mt('Select Reason...') |h %></OPTION>
-% foreach my $reason (@reasons) {
- <OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reasontype->type %> : <% $reason->reason %></OPTION>
-% }
-% if ($curuser->access_right($add_access_right)) {
- <OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>><% mt('Add new reason') |h %></OPTION>
-% }
-%
- </SELECT>
- </TD>
-</TR>
-
-% 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>
- <TD ALIGN="right">
- <P id="new<% $name %>TLabel" style="display:<% $display %>"><% mt('Reason Type') |h %></P>
- </TD>
- <TD>
- <P id="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>"><% $types[0]->type %>
- <INPUT type="hidden" name="new<% $name %>T" value="<% $types[0]->typenum %>">
- </TD>
-</TR>
-
-% }else{
-
-<TR>
- <TD ALIGN="right">
- <P id="new<% $id %>TLabel" style="display:<% $display %>"><% mt('Reason Type') |h %></P>
- </TD>
- <TD>
- <SELECT id="new<% $id %>T" name="new<% $name %>T" "<% $disabled %>" style="display:<% $display %>">
-% for my $type (@types) {
- <OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
-% }
- </SELECT>
- </TD>
-</TR>
-% }
+%# 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)