RT#39115: View SNMP info on svc_broadband service [fix to default value handling]
[freeside.git] / httemplate / edit / elements / part_export / broadband_snmp.html
1 <%doc>
2 </%doc>
3 <& head.html, %opt &>
4 <INPUT TYPE="hidden" NAME="options" VALUE="community,version,ip_addr_change_to_new,timeout">
5 <& /elements/tr-select.html,
6   label   => 'SNMP version',
7   field   => 'version',
8   options => [ '', 'v1', 'v2c' ],
9   labels  => { v1 => '1', v2c => '2c' },
10   curr_value => $part_export->option('version') &>
11 <& /elements/tr-input-text.html,
12   label   => 'Community',
13   field   => 'community',
14   curr_value  => $curr_value->{'community'},
15 &>
16 <& /elements/tr-checkbox.html,
17   label   => 'Send IP address changes to new address',
18   field   => 'ip_addr_change_to_new',
19   value   => 1,
20   curr_value => $part_export->option('ip_addr_change_to_new'),
21 &>
22 <& /elements/tr-input-text.html,
23   label   => 'Timeout (seconds)',
24   field   => 'timeout',
25   curr_value  => $part_export->option('timeout'),
26 &>
27 </TABLE>
28 <script type="text/javascript">
29 function open_select_mib(obj) {
30   nd(1); // if there's already one open, close it
31   var rownum = obj.rownum;
32   var curr_oid = obj.form.elements['oid' + rownum].value || '';
33   var url = '<%$fsurl%>misc/select-mib-popup.html?' +
34             'callback=receive_mib;' +
35             'arg=' + rownum +
36             ';curr_value=' + curr_oid;
37   overlib(
38     OLiframeContent(url, 550, 450, '<% $popup_name %>', 0, 'auto'),
39     CAPTION, 'Select MIB object', STICKY, AUTOSTATUSCAP,
40     MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK,
41     BGCOLOR, '#333399', CGCOLOR, '#333399',
42     CLOSETEXT, 'Close'
43   );
44 }
45 function receive_mib(obj, rownum) {
46   //console.log(JSON.stringify(obj));
47   // we don't really need the numeric OID or any of the other properties
48   var oidfield =   document.getElementById('oid'+rownum);
49   oidfield.value = obj.fullname;
50   document.getElementById('datatype'+rownum).value = obj.type;
51   oidfield.onchange(); //should be same as datatype, only need to run one
52 }
53 </script>
54
55 <table bgcolor="#cccccc" border=0 cellspacing=3>
56 <TR>
57   <TH>Action</TH>
58   <TH>Object</TH>
59   <TH>Type</TH>
60   <TH>Value</TH>
61 </TR>
62 <TR id="mytemplate">
63   <TD>
64     <SELECT NAME="action">
65 %     foreach ('', qw(insert delete replace suspend unsuspend)) {
66       <OPTION VALUE="<%$_%>"><%$_%></OPTION>
67 %     }
68     </SELECT>
69   </TD>
70   <TD>
71     <INPUT NAME="oid" ID="oid" SIZE="54">
72     <INPUT TYPE="button" VALUE="..." ID="openselector" onclick="open_select_mib(this)">
73   </TD>
74   <TD>
75     <INPUT TYPE="text" NAME="datatype" ID="datatype">
76   </TD>
77   <TD>
78     <INPUT NAME="value" ID="value">
79   </TD>
80 </TR>
81 <& /elements/auto-table.html,
82   template_row  => 'mytemplate',
83   fieldorder    => ['action', 'oid', 'datatype', 'value'],
84   data          => \@data,
85 &>
86 <INPUT TYPE="hidden" NAME="multi_options" VALUE="action,oid,datatype,value">
87 <& foot.html, %opt &>
88 <%init>
89 my %opt = @_;
90 my $part_export = $opt{part_export} || FS::part_export->new;
91 my $curr_value = {};
92 $curr_value->{'community'} = ($opt{'part_export'} && $opt{'part_export'}->exportnum)
93                            ? $part_export->option('community') 
94                            : $opt{'export_info'}->{'options'}->{'community'}->{'default'};
95
96 my @actions = split("\n", $part_export->option('action'));
97 my @oids    = split("\n", $part_export->option('oid'));
98 my @types   = split("\n", $part_export->option('datatype'));
99 my @values  = split("\n", $part_export->option('value'));
100
101 my @data;
102 while (@actions or @oids or @values) {
103   my @thisrow = (shift(@actions), shift(@oids), shift(@types), shift(@values));
104   push @data, \@thisrow if grep length($_), @thisrow;
105 }
106
107 my $popup_name = 'popup-'.time."-$$-".rand() * 2**32;
108 </%init>