1 <% include( 'elements/edit.html',
2 'name' => 'Phone device',
3 'table' => 'phone_device',
5 'devicenum' => 'Device',
6 'devicepart' => 'Device type',
7 'mac_addr' => 'MAC address',
9 'fields' => [ { 'field' => 'devicepart',
10 'type' => 'select-table',
11 'table' => 'part_device',
12 'name_col' => 'devicename',
13 'onchange' => 'devicepart_changed',
14 'empty_label' =>'Select device type',
15 #'hashref' =>{ disabled => '' },
17 { field => 'mac_addr',
20 { 'field' => 'svcnum',
24 'menubar' => [], #disable viewall
25 #'viewall_dir' => 'browse',
26 'new_callback' => sub {
27 my( $cgi, $object ) = @_;
28 $object->svcnum( $cgi->param('svcnum') );
30 'html_foot' => $html_foot,
35 my @deviceparts_with_inventory =
37 qsearch({ 'table' => 'part_device',
38 'extra_sql' => 'WHERE inventory_classnum IS NOT NULL',
43 <SCRIPT TYPE=\"text/javascript\">
45 function opt(what,value,text) {
46 var optionName = new Option(text, value, false, false);
47 var length = what.length;
48 what.options[length] = optionName;
51 function devicepart_changed(what){
53 var macsel = document.getElementById('sel_mac_addr');
54 var mac = document.getElementById('mac_addr');
56 function update_macs(macs) {
57 for ( var i = macsel.length; i >= 0; i-- )
58 macsel.options[i] = null;
60 var macArray = eval('(' + macs + ')' );
61 if(macArray.length == 0)
62 opt(macsel,'','No MAC addresses found in inventory for this device type');
64 opt(macsel,'','Select MAC address');
66 for ( var i = 0; i < macArray.length; i++ ) {
67 opt(macsel,macArray[i],macArray[i]);
72 var devicepart = what.options[what.selectedIndex].value;
74 var deviceparts_with_inventory = new Array(";
75 $js .= join(',', map qq("$_"), @deviceparts_with_inventory);
78 var hasInventory = false;
79 for ( i = 0; i < deviceparts_with_inventory.length; i++ ) {
80 if ( deviceparts_with_inventory[i] == devicepart )
85 if(hasInventory) { // do the AJAX thing, disable text field
86 macsel.style.display = 'inline';
87 mac.style.display = 'none';
89 get_macs( devicepart, update_macs );
90 } else { // clear & display text field only, clear/hide select
91 mac.style.display = 'inline';
92 macsel.style.display = 'none';
93 macsel.selectedIndex = 0;
98 devicepart_changed(document.getElementById('devicepart'));
104 # :/ needs agent-virt so you can't futz with arbitrary devices
107 unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?