5 <& /elements/tr-select-table,
7 'add_inline' => 0, #enable "on the fly" adding
9 #options passed to tr-td-label.html and select-$table.html (or
10 #select-table.html if that does not exist)
14 % unless ( $opt{'js_only'} ) {
16 <% include('tr-td-label.html', @_ ) %>
21 % my $element = '/elements/select-'.$opt{table}.'.html';
22 % if ( $m->interp->comp_exists($element) ) {
25 <& /elements/select-table.html, %opt &>
28 % unless ( $opt{'js_only'} ) {
33 % if ( $opt{'add_inline'} ) {
35 % foreach my $add_field ( @{ $opt{'add_fields'} } ) {
36 % my $label = scalar(@{ $opt{'add_fields'} }) > 1
37 % ? $add_field : $opt{'label'};
39 <& /elements/tr-input-text.html,
40 'label' => "New $label",
41 'field' => $field."_$add_field",
42 'id' => $field."_$add_field",
43 'colspan' => $opt{'colspan'},
49 % unless ( $opt{'html_only'} ) {
51 <SCRIPT TYPE="text/javascript">
53 % my $ge = 'document.getElementById';
55 function <% $field %>_changed(what) {
57 var value = what.options[what.selectedIndex].value;
60 var visibility = 'hidden';
61 if ( value == '-1' && ! what.disabled ) {
66 % foreach my $add_field ( @{ $opt{'add_fields'} } ) {
67 % my $ge_f = "$ge('${field}_$add_field";
68 <% $ge_f %>_label0').style.display = display;
69 <% $ge_f %>_label0').style.visibility = visibility;
70 <% $ge_f %>_input0').style.display = display;
71 <% $ge_f %>_input0').style.visibility = visibility;
76 <% $field %>_changed(<% $ge %>('<% $field %>'));
88 my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
90 my $curuser = $FS::CurrentUser::CurrentUser;
93 if ( $opt{'add_inline'} && $curuser->access_right($opt{'add_right'}) ) {
95 push @{ $opt{'post_options'} }, '-1' => 'Add new '. lc($opt{'label'});
97 $field = $opt{'field'} || dbdef->table($opt{'table'})->primary_key;
99 my $onchange = ( $opt{'onchange'} ? delete($opt{'onchange'}).';' : '' ).
100 $field.'_changed(this);';
101 $opt{'onchange'} = $onchange;