Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / edit / radius_group.html
1 <& elements/edit.html,
2   'name'   => 'RADIUS Group',
3   'table'  => 'radius_group',
4   'labels' => { 
5     'groupnum'  => 'Group',
6     'groupname' => 'RADIUS Group',
7     'description' => 'Description',
8     'attrnum'   => 'Attribute',
9     'priority'  => 'Priority',
10   },
11   'viewall_dir' => 'browse',
12   'menubar' => \@menubar,
13   'edit_callback' => $edit_callback,
14   'error_callback' => $edit_callback,
15   'fields' => [
16     { 'field'     => 'groupname',
17       'type'      => 'text',
18       'size'      => 20,
19       'colspan'   => 6, # just to not interfere with radius_attr columns
20     },
21     { 'field'     => 'description',
22       'type'      => 'text',
23       'size'      => 40,
24       'colspan'   => 6,
25     },
26     { 'field'     => 'priority',
27       'type'      => 'text',
28       'size'      => 2,
29       'colspan'   => 6, # just to not interfere with radius_attr columns
30     },
31     {
32       'field'     => 'attrnum',
33       'type'      => 'radius_attr',
34       'o2m_table' => 'radius_attr',
35       'm2_label'  => 'Attribute',
36       'm2_error_callback' => $m2_error_callback,
37     },
38   ],
39   #debug => 1
40 &>
41 <%init>
42
43 die "access denied"
44   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
45
46 my @menubar = ('View all RADIUS Groups' => $p.'browse/radius_group.html');
47
48 my $edit_callback = sub {
49   my ($cgi, $object) = @_;
50   if ( $object->groupnum ) {
51     my $link = $p.'misc/delete-radius_group.html?'.$object->groupnum;
52     push @menubar, 'Delete this Group', $link;
53   }
54 };
55
56 my $m2_error_callback = sub { # reconstruct the list
57   my ($cgi, $object) = @_;
58
59   my @fields = qw(attrname attrtype op value);
60   map {
61     my $k = $_;
62     next if !length($cgi->param($k.'_attrname'));
63     new FS::radius_attr {
64       'groupnum' => $object->groupnum,
65       'attrnum'  => scalar( $cgi->param($k) ),
66       map {  $_  => scalar( $cgi->param($k.'_'.$_) ) } @fields,
67     };
68   } grep /^attrnum\d+$/, ($cgi->param);
69 };
70 </%init>