1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<% 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 =
map $_->devicepart,
qsearch({ 'table' => 'part_device',
'extra_sql' => 'WHERE inventory_classnum IS NOT NULL',
});
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(',', map qq("$_"), @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>
|