diff options
Diffstat (limited to 'httemplate/edit/phone_device.html')
-rw-r--r-- | httemplate/edit/phone_device.html | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/httemplate/edit/phone_device.html b/httemplate/edit/phone_device.html new file mode 100644 index 000000000..4aec63e5a --- /dev/null +++ b/httemplate/edit/phone_device.html @@ -0,0 +1,111 @@ +<% include( 'elements/edit.html', + 'name' => 'Phone device', + 'table' => 'phone_device', + 'labels' => { + 'devicenum' => 'Device', + 'devicepart' => 'Device type', + 'mac_addr' => 'MAC address', + }, + 'fields' => [ { 'field' => 'devicepart', + 'type' => 'select-table', + 'table' => 'part_device', + 'name_col' => 'devicename', + 'onchange' => 'devicepart_changed', + 'empty_label' =>'Select device type', + #'hashref' =>{ disabled => '' }, + }, + { field => 'mac_addr', + type => 'select-mac', + }, + { 'field' => 'svcnum', + 'type' => 'hidden', + }, + ], + 'menubar' => [], #disable viewall + #'viewall_dir' => 'browse', + 'new_callback' => sub { + 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; + } + + } + + devicepart_changed(document.getElementById('devicepart')); +</SCRIPT>"; + + $js; +}; + +# :/ needs agent-virt so you can't futz with arbitrary devices + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific? + + +</%init> |