RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / elements / radius_attr.html
1 % if ( $first_row ) {
2 %   $first_row = '';
3 <SCRIPT TYPE="text/javascript">
4 var ops_for_type = {
5 %   foreach my $type ('C','R') {
6 '<%$type%>': [<% join(',', map {"'$_'"} FS::radius_attr->ops($type)) %>],
7 %   }
8 };
9 function change_attrtype(what) {
10   var new_type = what.value;
11   var select_op = document.getElementById(
12     what.id.replace(/_attrtype$/, '_op')
13   );
14   if ( select_op ) {
15     var options = select_op.options;
16     var new_ops = ops_for_type[new_type];
17     while ( options.length > 0 )
18       options.remove(0);
19     for ( var x in new_ops ) {
20       // Option(text, value, defaultSelected)
21       options.add(new Option(new_ops[x], new_ops[x], (options.length == 0)));
22     }
23   }
24   <% $onchange %>(what);
25 }
26 </SCRIPT>
27 % } #if $first_row
28 <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
29 <& select.html,
30   field       => $name.'_attrtype',
31   id          => $name.'_attrtype',
32   options     => ['C','R'],
33   labels      => { 'C' => 'Check', 'R' => 'Reply' },
34   curr_value  => $radius_attr->attrtype,
35   onchange    => 'change_attrtype(this)',
36 &>
37 <& input-text.html,
38   field       => $name.'_attrname',
39   curr_value  => $radius_attr->attrname,
40   onchange    => $onchange,
41   size        => 40, #longest attribute name in freeradius dict = 46
42 &>
43 <& select.html,
44   field       => $name.'_op',
45   id          => $name.'_op',
46   options     => [ FS::radius_attr->ops($radius_attr->attrtype) ],
47   curr_value  => $radius_attr->op,
48   onchange    => $onchange,
49 &>
50 <& input-text.html,
51   field       => $name.'_value',
52   curr_value  => $radius_attr->value,
53   onchange    => $onchange,
54   size        => 20, #tend to be shorter than attribute names
55 &>
56 <%shared>
57 my $first_row = 1;
58 </%shared>
59 <%init>
60
61 my( %opt ) = @_;
62
63 # for an 'onchange' option that will work in both select.html and 
64 # input-text.html:
65 # - don't start with "onchange="
66 # - don't end with (what) or (this)
67 # - don't end with a semicolon
68 # - don't have quotes
69 my $onchange = $opt{'onchange'} || '';
70 $onchange =~ s/\((what|this)\);?$//;
71
72 my $name = $opt{'element_name'} || $opt{'field'} || 'attrnum';
73 my $id = $opt{'id'} || 'attrnum';
74
75 my $curr_value = $opt{'curr_value'} || $opt{'value'};
76 my $radius_attr;
77
78 if ( $curr_value ) {
79   $radius_attr = qsearchs('radius_attr', { 'attrnum' => $curr_value })  
80     or die "attrnum $curr_value not found";
81 }
82 else {
83   $radius_attr = new FS::radius_attr {
84     'attrtype' => 'C',
85     'op'       => '==',
86   };
87 }
88
89 </%init>