summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authormark <mark>2011-11-23 18:42:50 +0000
committermark <mark>2011-11-23 18:42:50 +0000
commitd838063ab25f047e88c3e5ae16f77fc4f3481ce9 (patch)
treee4f533d73a30b62522c4e50df9c142a10737e5d2 /httemplate
parentd0008add75bbb6e2ec49e6d40f28965eac0bcfb6 (diff)
RADIUS group attributes, #15017
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/browse/radius_group.html44
-rw-r--r--httemplate/edit/process/radius_group.html23
-rw-r--r--httemplate/edit/radius_group.html58
-rw-r--r--httemplate/elements/radius_attr.html89
-rw-r--r--httemplate/elements/select-table.html2
-rw-r--r--httemplate/elements/select.html7
6 files changed, 194 insertions, 29 deletions
diff --git a/httemplate/browse/radius_group.html b/httemplate/browse/radius_group.html
index e2ac56363..fbf6d3766 100644
--- a/httemplate/browse/radius_group.html
+++ b/httemplate/browse/radius_group.html
@@ -1,18 +1,20 @@
<& elements/browse.html,
- 'title' => 'RADIUS Groups',
- 'name' => 'RADIUS Groups',
- 'menubar' => [ 'Add a RADIUS Group' => $p.'edit/radius_group.html', ],
- 'query' => { 'table' => 'radius_group' },
- 'count_query' => 'SELECT COUNT(*) FROM radius_group',
- 'header' => [ '#', 'RADIUS Group', 'Description' ],
- 'fields' => [ 'groupnum',
- 'groupname',
- 'description',
- ],
- 'links' => [ [ $p.'edit/radius_group.html?', 'groupnum' ],
- '',
- '',
- ],
+ 'title' => 'RADIUS Groups',
+ 'name' => 'RADIUS Groups',
+ 'menubar' => [ 'Add a RADIUS Group' => $p.'edit/radius_group.html', ],
+ 'query' => { 'table' => 'radius_group' },
+ 'count_query' => 'SELECT COUNT(*) FROM radius_group',
+ 'header' => [ '#', 'RADIUS Group', 'Description', 'Priority',
+ 'Check', 'Reply' ],
+ 'fields' => [ 'groupnum',
+ 'groupname',
+ 'description',
+ 'priority',
+ $check_attr, $reply_attr
+ ],
+ 'align' => 'lllcll',
+ 'links' => [ $link, $link, '', '', '', '',
+ ],
&>
<%init>
@@ -21,4 +23,18 @@ my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
unless $curuser->access_right('Configuration');
+my $attr_sub = sub {
+ my $type = shift;
+ my $radius_group = shift;
+ [ map { [ { data => join(' ', $_->attrname, $_->op, $_->value) } ] }
+ grep {$_->attrtype eq $type}
+ $radius_group->radius_attr
+ ];
+};
+
+my $check_attr = sub { &$attr_sub('C', @_) };
+my $reply_attr = sub { &$attr_sub('R', @_) };
+
+my $link = [ $p.'edit/radius_group.html?', 'groupnum' ];
+
</%init>
diff --git a/httemplate/edit/process/radius_group.html b/httemplate/edit/process/radius_group.html
index 706813f2a..884694618 100644
--- a/httemplate/edit/process/radius_group.html
+++ b/httemplate/edit/process/radius_group.html
@@ -1,10 +1,27 @@
<& elements/process.html,
- 'table' => 'radius_group',
- 'viewall_dir' => 'browse',
+ 'table' => 'radius_group',
+ 'viewall_dir' => 'browse',
+ 'process_o2m' => {
+ 'table' => 'radius_attr',
+ 'fields' => [ qw( attrtype attrname op value )],
+ },
+ 'precheck_callback' => $precheck_callback,
&>
<%init>
-
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+my $precheck_callback = sub {
+ my $cgi = shift;
+ my $param = $cgi->Vars;
+ # remove rows with a blank attrname and attrnum
+ foreach my $k (grep /^attrnum\d+$/, keys %$param) {
+ if ( !length($param->{$k}) and !length($param->{$k.'_attrname'}) ) {
+ delete $param->{$k.'_'.$_} foreach qw(attrtype attrname op value);
+ delete $param->{$k};
+ }
+ }
+ '';
+};
+
</%init>
diff --git a/httemplate/edit/radius_group.html b/httemplate/edit/radius_group.html
index 80e17ed83..c9bf52596 100644
--- a/httemplate/edit/radius_group.html
+++ b/httemplate/edit/radius_group.html
@@ -1,16 +1,58 @@
<& elements/edit.html,
- 'name' => 'RADIUS Group',
- 'table' => 'radius_group',
- 'labels' => {
- 'groupnum' => 'Group',
- 'groupname' => 'RADIUS Group',
- 'description' => 'Description',
- },
- 'viewall_dir' => 'browse',
+ 'name' => 'RADIUS Group',
+ 'table' => 'radius_group',
+ 'labels' => {
+ 'groupnum' => 'Group',
+ 'groupname' => 'RADIUS Group',
+ 'description' => 'Description',
+ 'attrnum' => 'Attribute',
+ 'priority' => 'Priority',
+ },
+ 'viewall_dir' => 'browse',
+ 'fields' => [
+ { 'field' => 'groupname',
+ 'type' => 'text',
+ 'size' => 20,
+ 'colspan' => 6, # just to not interfere with radius_attr columns
+ },
+ { 'field' => 'description',
+ 'type' => 'text',
+ 'size' => 40,
+ 'colspan' => 6,
+ },
+ { 'field' => 'priority',
+ 'type' => 'text',
+ 'size' => 2,
+ 'colspan' => 6, # just to not interfere with radius_attr columns
+ },
+ {
+ 'field' => 'attrnum',
+ 'type' => 'radius_attr',
+ 'o2m_table' => 'radius_attr',
+ 'm2_label' => 'Attribute',
+ 'm2_error_callback' => $m2_error_callback,
+ },
+ ],
+ #debug => 1
&>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+my $m2_error_callback = sub { # reconstruct the list
+ my ($cgi, $object) = @_;
+
+ warn Dumper({$cgi->Vars});
+ my @fields = qw(attrname attrtype op value);
+ map {
+ my $k = $_;
+ next if !length($cgi->param($k.'_attrname'));
+ new FS::radius_attr {
+ 'groupnum' => $object->groupnum,
+ 'attrnum' => scalar( $cgi->param($k) ),
+ map { $_ => scalar( $cgi->param($k.'_'.$_) ) } @fields,
+ };
+ } grep /^attrnum\d+$/, ($cgi->param);
+};
</%init>
diff --git a/httemplate/elements/radius_attr.html b/httemplate/elements/radius_attr.html
new file mode 100644
index 000000000..2ebf346a9
--- /dev/null
+++ b/httemplate/elements/radius_attr.html
@@ -0,0 +1,89 @@
+% if ( $first_row ) {
+% $first_row = '';
+<SCRIPT TYPE="text/javascript">
+var ops_for_type = {
+% foreach my $type ('C','R') {
+'<%$type%>': [<% join(',', map {"'$_'"} FS::radius_attr->ops($type)) %>],
+% }
+};
+function change_attrtype(what) {
+ var new_type = what.value;
+ var select_op = document.getElementById(
+ what.id.replace(/_attrtype$/, '_op')
+ );
+ if ( select_op ) {
+ var options = select_op.options;
+ var new_ops = ops_for_type[new_type];
+ while ( options.length > 0 )
+ options.remove(0);
+ for ( var x in new_ops ) {
+ // Option(text, value, defaultSelected)
+ options.add(new Option(new_ops[x], new_ops[x], (options.length == 0)));
+ }
+ }
+ <% $onchange %>(what);
+}
+</SCRIPT>
+% } #if $first_row
+<INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
+<& select.html,
+ field => $name.'_attrtype',
+ id => $name.'_attrtype',
+ options => ['C','R'],
+ labels => { 'C' => 'Check', 'R' => 'Reply' },
+ curr_value => $radius_attr->attrtype,
+ onchange => 'change_attrtype(this)',
+&>
+<& input-text.html,
+ field => $name.'_attrname',
+ curr_value => $radius_attr->attrname,
+ onchange => $onchange,
+ size => 40, #longest attribute name in freeradius dict = 46
+&>
+<& select.html,
+ field => $name.'_op',
+ id => $name.'_op',
+ options => [ FS::radius_attr->ops($radius_attr->attrtype) ],
+ curr_value => $radius_attr->op,
+ onchange => $onchange,
+&>
+<& input-text.html,
+ field => $name.'_value',
+ curr_value => $radius_attr->value,
+ onchange => $onchange,
+ size => 20, #tend to be shorter than attribute names
+&>
+<%shared>
+my $first_row = 1;
+</%shared>
+<%init>
+
+my( %opt ) = @_;
+
+# for an 'onchange' option that will work in both select.html and
+# input-text.html:
+# - don't start with "onchange="
+# - don't end with (what) or (this)
+# - don't end with a semicolon
+# - don't have quotes
+my $onchange = $opt{'onchange'} || '';
+$onchange =~ s/\((what|this)\);?$//;
+
+my $name = $opt{'element_name'} || $opt{'field'} || 'attrnum';
+my $id = $opt{'id'} || 'attrnum';
+
+my $curr_value = $opt{'curr_value'} || $opt{'value'};
+my $radius_attr;
+
+if ( $curr_value ) {
+ $radius_attr = qsearchs('radius_attr', { 'attrnum' => $curr_value })
+ or die "attrnum $curr_value not found";
+}
+else {
+ $radius_attr = new FS::radius_attr {
+ 'attrtype' => 'C',
+ 'op' => '==',
+ };
+}
+
+</%init>
diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html
index 741e51e49..c0dde7414 100644
--- a/httemplate/elements/select-table.html
+++ b/httemplate/elements/select-table.html
@@ -124,7 +124,7 @@ Example:
my( %opt ) = @_;
-warn "elements/select-table.html: \n". Dumper(%opt)
+warn "elements/select-table.html: \n". Dumper(\%opt)
if exists $opt{debug} && $opt{debug};
$opt{'extra_option_attributes'} ||= [];
diff --git a/httemplate/elements/select.html b/httemplate/elements/select.html
index 5249a6dc3..1bf56b5cb 100644
--- a/httemplate/elements/select.html
+++ b/httemplate/elements/select.html
@@ -45,9 +45,10 @@
my %opt = @_;
-my $onchange = $opt{'onchange'}
- ? 'onChange="'. $opt{'onchange'}. '(this)"'
- : '';
+#no-op code...
+#my $onchange = $opt{'onchange'}
+# ? 'onChange="'. $opt{'onchange'}. '(this)"'
+# : '';
my $labels = $opt{'option_labels'} || $opt{'labels'};