svc_circuit, #23879, #25933, #30830
[freeside.git] / httemplate / browse / elements / browse-simple.html
1 <& browse.html,
2   'query'               => { 'table' => $table },
3   'count_query'         => "SELECT COUNT(*) FROM $table",
4   'header'              => [ '#', $opt{name_header} ],
5   'fields'              => [ $table_key, $opt{name_col} ],
6   'links'               => [ '', '' ],
7   'link_onclicks'       => [ '', $sub_edit_popup ],
8   'disableable'         => 1,
9   'disabled_statuspos'  => 2,
10   'html_init'           => $html_init,
11   %opt,
12 &>
13 <%doc>
14 A simple wrapper around search/elements/search.html for browsing/editing
15 tables that only have a primary key, a 'disabled' field, and one other column
16 which is the object's name or description. Usage:
17
18 <& browse-simple.html,
19   # required
20   'table'         => 'mytable',
21   'title'         => 'My Things',
22   'name_singular' => 'thing',
23   'name_col'      => 'thingname',
24   'name_header'   => 'Thing name'
25   'acl'           => 'Configure things',
26 &>
27
28 </%doc>
29 <%init>
30 my %opt = @_;
31
32 my $table = delete $opt{table};
33 my $name_singular = $opt{name_singular};
34
35 die "access denied"
36   unless $FS::CurrentUser::CurrentUser->access_right($opt{acl});
37
38 my $table_key = dbdef->table($table)->primary_key;
39 my $sub_edit_popup = sub {
40   my $pkey = $_[0]->get($table_key);
41   include('/elements/popup_link_onclick.html',
42     'action'      => $p."edit/$table.html?$pkey",
43     'actionlabel' => "Edit $name_singular",
44     'width'       => 350,
45     'height'      => 220,
46   );
47 };
48
49 my $html_init = include('/elements/popup_link.html',
50     'action'      => $p."edit/$table.html?",
51     'actionlabel' => "Add $name_singular",
52     'width'       => 350,
53     'height'      => 220,
54     'label'       => "Add a new $name_singular",
55 ) . '<BR>';
56
57 </%init>