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