event refactor, landing on HEAD!
[freeside.git] / httemplate / elements / checkboxes-table-name.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/checkboxes-table-name.html',
6
7     ###
8     # required
9     ###
10     'link_table'      => 'table_name',
11    
12     'name_col' => 'name_column',
13     #or
14     'name_callback' => sub { },
15    
16     'names_list' => [ 'value',
17                       'other value',
18                       [ 'complex value' => { 'desc' => "Add'l description",
19                                              'note' => '&nbsp;*',
20                                            }
21                       ],
22                     ],
23    
24     ###
25     # recommended (required?)
26     ###
27     'source_obj'   => $obj,
28     #or?
29     #'source_table' => 'table_name',
30     #'sourcenum'    => '4', #current value of primary key in source_table
31     #                       # (none is okay, just pass it if you have it)
32
33     ###
34     # optional
35     ###
36     'num_col' => 'col_name' #if column name is different in link_table than
37                             #source_table
38     'link_static' => { 'column' => 'value' },
39
40   )
41
42 </%doc>
43
44 <TABLE CELLSPACING=0 CELLPADDING=0>
45
46 % foreach my $item ( @{ $opt{'names_list'} } ) {
47 %
48 %     my $name = ref($item) ? $item->[0] : $item;
49 %     ( my $display = $name ) =~ s/ /&nbsp;/g;
50 %     $display .= $item->[1]{note} if ref($item) && $item->[1]{note};
51 %     my $desc = ref($item) && $item->[1]{desc} ? $item->[1]{desc} : '';
52 %
53 %     my $checked;
54 %     if ( $cgi->param('error') ) {
55 %
56 %       $checked = $cgi->param($opt{'link_table'}. ".$name" )
57 %                    ? 'CHECKED'
58 %                    : '';
59 %
60 %     } else {
61 %
62 %       $checked =
63 %         qsearchs( $opt{'link_table'}, {
64 %                                         $source_pkey     => $sourcenum,
65 %                                         $opt{'name_col'} => $name,
66 %                                         %$link_static,
67 %                                       }                                 )
68 %                    ? 'CHECKED'
69 %                    : ''
70 %
71 %     }
72
73   <TR>
74     <TD VALIGN="top">
75       <INPUT TYPE="checkbox" NAME="<% $opt{'link_table'}. ".$name" %>" <% $checked %> VALUE="ON">
76     </TD>
77     <TD><% $display %>
78 %     if ( $desc ) {
79         <BR><FONT SIZE="-2"><% $desc %></FONT>
80 %     }
81     </TD>
82   </TR>
83
84 % } 
85
86 </TABLE>
87
88 <%init>
89
90 my( %opt ) = @_;
91
92 my( $source_pkey, $sourcenum, $source_obj );
93 if ( $opt{'source_obj'} ) {
94
95   $source_obj = $opt{'source_obj'};
96   #$source_table = $source_obj->dbdef_table->table;
97   $source_pkey = $source_obj->dbdef_table->primary_key;
98   $sourcenum = $source_obj->$source_pkey();
99
100 } else {
101
102   #$source_obj?
103   $source_pkey = $opt{'source_table'}
104                    ? dbdef->table($opt{'source_table'})->primary_key
105                    : '';
106   $sourcenum = $opt{'sourcenum'};
107 }
108
109 $source_pkey = $opt{'num_col'} || $source_pkey;
110
111 my $link_static = $opt{'link_static'} || {};
112
113 </%init>