RT#39115 - added a optional display name for oid
[freeside.git] / httemplate / edit / elements / part_export / broadband_snmp_get.html
1 <%doc>
2 Quite a bit of false laziness with edit/elements/part_export/broadband_snmp.html
3 </%doc>
4 <& head.html, %opt &>
5 <INPUT TYPE="hidden" NAME="options" VALUE="snmp_community,snmp_version,snmp_timeout">
6 <& /elements/tr-select.html,
7   label   => 'SNMP version',
8   field   => 'snmp_version',
9   options => [ '1', '2c' ],
10   curr_value => $curr_value->{'snmp_version'} 
11 &>
12 <& /elements/tr-input-text.html,
13   label   => 'Community',
14   field   => 'snmp_community',
15   curr_value  => $curr_value->{'snmp_community'},
16 &>
17 <& /elements/tr-input-text.html,
18   label   => 'Timeout (seconds)',
19   field   => 'snmp_timeout',
20   curr_value  => $curr_value->{'snmp_timeout'},
21 &>
22 </TABLE>
23 <script type="text/javascript">
24 function open_select_mib_get(obj) {
25   nd(1); // if there's already one open, close it
26   var rownum = obj.rownum;
27   var curr_oid = obj.form.elements['snmp_oid' + rownum].value || '';
28   var url = '<%$fsurl%>misc/select-mib-popup.html?' +
29             'callback=receive_mib_get;' +
30             'arg=' + rownum +
31             ';curr_value=' + curr_oid;
32   overlib(
33     OLiframeContent(url, 550, 450, '<% $popup_name %>', 0, 'auto'),
34     CAPTION, 'Select MIB object', STICKY, AUTOSTATUSCAP,
35     MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK,
36     BGCOLOR, '#333399', CGCOLOR, '#333399',
37     CLOSETEXT, 'Close'
38   );
39 }
40 function receive_mib_get(obj, rownum) {
41   var oidfield = document.getElementById('snmp_oid'+rownum);
42   oidfield.value = obj.fullname;
43   oidfield.onchange();
44 }
45 </script>
46
47 <table bgcolor="#cccccc" border=0 cellspacing=3>
48 <TR><TH>Object Name</TH><TH>Object ID</TH></TR>
49 <TR id="broadband_snmp_get_template">
50   <TD>
51     <INPUT NAME="oid_name" ID="oid_name" SIZE="25">
52   </TD>
53   <TD>
54     <INPUT NAME="oid" ID="oid" SIZE="54">
55     <INPUT TYPE="button" VALUE="..." ID="openselector" onclick="open_select_mib_get(this)">
56   </TD>
57 </TR>
58 <& /elements/auto-table.html,
59   template_row  => 'broadband_snmp_get_template',
60   fieldorder    => ['oid_name','oid'],
61   data          => \@data,
62   table         => 'snmp',
63 &>
64 <INPUT TYPE="hidden" NAME="multi_options" VALUE="snmp_oid,snmp_oid_name">
65 <& foot.html, %opt &>
66 <%init>
67 my %opt = @_;
68
69 my $part_export = $opt{part_export} || FS::part_export->new;
70
71 my $curr_value = {};
72 foreach my $field ( qw(snmp_version snmp_community snmp_timeout) ) {
73   $curr_value->{$field} = ($opt{'part_export'} && $opt{'part_export'}->exportnum)
74                           ? $part_export->option($field) 
75                           : $opt{'export_info'}->{'options'}->{$field}->{'default'};
76 }
77
78 my @oids    = split("\n", $part_export->option('snmp_oid'));
79 my @oid_names    = split("\n", $part_export->option('snmp_oid_name'));
80
81 my @data;
82 while (@oids) {
83   my @thisrow = (shift(@oids));
84   my $name = shift(@oid_names);
85   push @data, [$name, \@thisrow] if grep length($_), @thisrow;
86 }
87
88 my $popup_name = 'popup-'.time."-$$-".rand() * 2**32;
89 </%init>