4.x style
[freeside.git] / httemplate / elements / tr-select-table.html
1 <%doc>
2
3 Example:
4
5   <& /elements/tr-select-table,
6
7        'add_inline' => 0, #enable "on the fly" adding
8  
9        #options passed to tr-td-label.html and select-$table.html (or
10        #select-table.html if that does not exist)
11   &>
12
13 </%doc>
14 % unless ( $opt{'js_only'} ) {
15
16     <% include('tr-td-label.html', @_ ) %>
17
18       <TD <% $style %>>
19 % }
20
21 % my $element = '/elements/select-'.$opt{table}.'.html';
22 % if ( $m->interp->comp_exists($element) ) {
23         <& $element, %opt &>
24 % } else {
25         <& /elements/select-table.html, %opt &>
26 % }
27
28 % unless ( $opt{'js_only'} ) {
29       </TD>
30     </TR>
31 % }
32
33 % if ( $opt{'add_inline'} ) {
34
35 %   foreach my $add_field ( @{ $opt{'add_fields'} } ) {
36 %     my $label = scalar(@{ $opt{'add_fields'} }) > 1
37 %                   ? $add_field : $opt{'label'};
38
39       <& /elements/tr-input-text.html,
40            'label'   => "New $label",
41            'field'   => $field."_$add_field",
42            'id'      => $field."_$add_field",
43            'colspan' => $opt{'colspan'},
44       &>
45
46 %   }
47
48
49 %   unless ( $opt{'html_only'} ) {
50
51       <SCRIPT TYPE="text/javascript">
52
53 %       my $ge = 'document.getElementById';
54
55         function <% $field %>_changed(what) {
56
57           var value = what.options[what.selectedIndex].value;
58
59           var display = 'none';
60           var visibility = 'hidden';
61           if ( value == '-1' && ! what.disabled ) {
62             display = '';
63             visibility = '';
64           }
65
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;
72 %         }
73
74         }
75
76         <% $field %>_changed(<% $ge %>('<% $field %>'));
77
78       </SCRIPT>
79
80 %   }
81
82 % }
83
84 <%init>
85
86 my( %opt ) = @_;
87
88 my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
89
90 my $curuser = $FS::CurrentUser::CurrentUser;
91
92 my $field = '';
93 if ( $opt{'add_inline'} && $curuser->access_right($opt{'add_right'}) ) {
94
95   push @{ $opt{'post_options'} }, '-1' => 'Add new '. lc($opt{'label'});
96
97   $field = $opt{'field'} || dbdef->table($opt{'table'})->primary_key;
98
99   my $onchange = ( $opt{'onchange'} ? delete($opt{'onchange'}).';' : '' ).
100                  $field.'_changed(this);';
101   $opt{'onchange'} = $onchange;
102
103 }
104
105 </%init>