v4 style
[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     #not yet '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 <% include('checkboxes.html',
45              'names_list'             => $opt{'names_list'},
46              'checked_callback'       => $checked_callback,
47              'element_name_prefix'    => $opt{'link_table'}. '.',
48              'disable_links'          => $opt{'disable_links'},
49           )
50 %>
51
52 <%init>
53
54 my( %opt ) = @_;
55
56 my @pset = ( 'a'..'z', 'A'..'Z', '0'..'9' );
57
58 my $prefix = $opt{prefix}
59              || join('', map $pset[ int(rand $#pset) ], (0..20) );
60
61 my( $source_pkey, $sourcenum, $source_obj );
62 if ( $opt{'source_obj'} ) {
63
64   $source_obj = $opt{'source_obj'};
65   #$source_table = $source_obj->dbdef_table->table;
66   $source_pkey = $source_obj->dbdef_table->primary_key;
67   $sourcenum = $source_obj->$source_pkey();
68
69 } else {
70
71   #$source_obj?
72   $source_pkey = $opt{'source_table'}
73                    ? dbdef->table($opt{'source_table'})->primary_key
74                    : '';
75   $sourcenum = $opt{'sourcenum'};
76 }
77
78 $source_pkey = $opt{'num_col'} || $source_pkey;
79
80 my $link_static = $opt{'link_static'} || {};
81
82 my $checked_callback = sub {
83   my( $cgi, $name ) = @_;
84   qsearchs( $opt{'link_table'}, {
85     $source_pkey     => $sourcenum,
86     $opt{'name_col'} => $name,
87     %$link_static,
88   });
89 };
90
91 </%init>