diff options
author | levinse <levinse> | 2011-01-22 20:03:50 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-01-22 20:03:50 +0000 |
commit | e87a701dd25a5d20218924057aa0d38def2eefc1 (patch) | |
tree | cff56e9aa5bccc7f75f93b98d4e778edb2c79d2d /httemplate/edit | |
parent | 0259db6a5f67fa8837c18bbaed3e424cccf7a3e0 (diff) |
populate MAC address from inventory for svc_phone devices, RT7794
Diffstat (limited to 'httemplate/edit')
-rw-r--r-- | httemplate/edit/part_device.html | 20 | ||||
-rw-r--r-- | httemplate/edit/phone_device.html | 74 |
2 files changed, 93 insertions, 1 deletions
diff --git a/httemplate/edit/part_device.html b/httemplate/edit/part_device.html index 146070fd9..1317c8d1c 100644 --- a/httemplate/edit/part_device.html +++ b/httemplate/edit/part_device.html @@ -4,7 +4,9 @@ 'labels' => { 'devicepart' => 'Part number', 'devicename' => 'Device name', + 'inventory_classnum' => 'Inventory class', }, + 'fields' => \@fields, 'viewall_dir' => 'browse', 'html_bottom' => $html_bottom_sub, ) @@ -20,6 +22,24 @@ my $extra_sql = ); $extra_sql = $extra_sql ? " WHERE ( $extra_sql ) " : " WHERE 0 = 1 "; +my @inventory_classnums; +push @inventory_classnums, ''; +my %inventory_classnum_labels; +$inventory_classnum_labels{''} = ''; +my @inventory_classes = qsearch('inventory_class', {} ); +foreach my $inventory_class ( @inventory_classes ) { + push @inventory_classnums, $inventory_class->classnum; + $inventory_classnum_labels{$inventory_class->classnum} = $inventory_class->classname; +} + +my @fields; +push @fields, 'devicename', + { field => 'inventory_classnum', + type => 'select', + options => \@inventory_classnums, + labels => \%inventory_classnum_labels, + }; + my $html_bottom_sub = sub { my $part_device = shift; diff --git a/httemplate/edit/phone_device.html b/httemplate/edit/phone_device.html index a1aa16620..c42e714e2 100644 --- a/httemplate/edit/phone_device.html +++ b/httemplate/edit/phone_device.html @@ -10,10 +10,13 @@ 'type' => 'select-table', 'table' => 'part_device', 'name_col' => 'devicename', + 'onchange' => 'devicepart_changed', 'empty_label' =>'Select device type', #'hashref' =>{ disabled => '' }, }, - 'mac_addr', + { field => 'mac_addr', + type => 'select-mac', + }, { 'field' => 'svcnum', 'type' => 'hidden', }, @@ -24,10 +27,79 @@ my( $cgi, $object ) = @_; $object->svcnum( $cgi->param('svcnum') ); }, + 'html_foot' => $html_foot, ) %> <%init> +my @deviceparts_with_inventory; +my @part_device = qsearch('part_device', {} ); +foreach my $part_device ( @part_device ) { + push @deviceparts_with_inventory, $part_device->devicepart + if $part_device->inventory_classnum; +} + +my $html_foot = sub { + my $js = " +<SCRIPT TYPE=\"text/javascript\"> + + function opt(what,value,text) { + var optionName = new Option(text, value, false, false); + var length = what.length; + what.options[length] = optionName; + } + + function devicepart_changed(what){ + + var macsel = document.getElementById('sel_mac_addr'); + var mac = document.getElementById('mac_addr'); + + function update_macs(macs) { + for ( var i = macsel.length; i >= 0; i-- ) + macsel.options[i] = null; + + var macArray = eval('(' + macs + ')' ); + if(macArray.length == 0) + opt(macsel,'','No MAC addresses found in inventory for this device type'); + else + opt(macsel,'','Select MAC address'); + + for ( var i = 0; i < macArray.length; i++ ) { + opt(macsel,macArray[i],macArray[i]); + } + + } + + var devicepart = what.options[what.selectedIndex].value; + + var deviceparts_with_inventory = new Array(\""; +$js .= join("\",\"",@deviceparts_with_inventory); +$js .= "\"); + + var hasInventory = false; + for ( i = 0; i < deviceparts_with_inventory.length; i++ ) { + if ( deviceparts_with_inventory[i] == devicepart ) + hasInventory = true; + } + + + if(hasInventory) { // do the AJAX thing, disable text field + macsel.style.display = 'inline'; + mac.style.display = 'none'; + mac.value = ''; + get_macs( devicepart, update_macs ); + } else { // clear & display text field only, clear/hide select + mac.style.display = 'inline'; + macsel.style.display = 'none'; + macsel.selectedIndex = 0; + } + + } +</SCRIPT>"; + + $js; +}; + # :/ needs agent-virt so you can't futz with arbitrary devices die "access denied" |