2017-05-29 10:46:33 +02:00
Ext . define ( 'PVE.qemu.USBInputPanel' , {
2017-12-11 16:10:13 +01:00
extend : 'Proxmox.panel.InputPanel' ,
2021-01-19 17:39:15 +01:00
mixins : [ 'Proxmox.Mixin.CBind' ] ,
2017-05-29 10:46:33 +02:00
autoComplete : false ,
onlineHelp : 'qm_usb_passthrough' ,
2019-09-23 08:18:09 +02:00
viewModel : {
2021-01-19 17:31:03 +01:00
data : { } ,
2019-09-23 08:18:09 +02:00
} ,
2017-05-29 10:46:33 +02:00
setVMConfig : function ( vmconfig ) {
var me = this ;
me . vmconfig = vmconfig ;
2022-11-10 15:36:00 +01:00
let max _usb = PVE . Utils . get _max _usb _count ( me . vmconfig . ostype , me . vmconfig . machine ) ;
if ( max _usb > PVE . Utils . hardware _counts . usb _old ) {
me . down ( 'field[name=usb3]' ) . setDisabled ( true ) ;
}
2017-05-29 10:46:33 +02:00
} ,
onGetValues : function ( values ) {
var me = this ;
2019-09-23 10:01:27 +02:00
if ( ! me . confid ) {
2022-11-10 15:36:00 +01:00
let max _usb = PVE . Utils . get _max _usb _count ( me . vmconfig . ostype , me . vmconfig . machine ) ;
for ( let i = 0 ; i < max _usb ; i ++ ) {
2019-09-23 10:01:27 +02:00
let id = 'usb' + i . toString ( ) ;
if ( ! me . vmconfig [ id ] ) {
me . confid = id ;
2017-05-29 10:46:33 +02:00
break ;
}
}
}
var val = "" ;
var type = me . down ( 'radiofield' ) . getGroupValue ( ) ;
switch ( type ) {
case 'spice' :
2019-09-23 17:06:21 +02:00
val = 'spice' ;
break ;
2017-05-29 10:46:33 +02:00
case 'hostdevice' :
case 'port' :
2019-09-23 17:06:21 +02:00
val = 'host=' + values [ type ] ;
delete values [ type ] ;
2017-05-29 10:46:33 +02:00
break ;
default :
throw "invalid type selected" ;
}
2019-09-11 14:43:34 +02:00
if ( values . usb3 ) {
delete values . usb3 ;
val += ',usb3=1' ;
}
2017-05-29 10:46:33 +02:00
values [ me . confid ] = val ;
return values ;
} ,
2018-05-16 10:38:35 +02:00
items : [
{
xtype : 'fieldcontainer' ,
defaultType : 'radiofield' ,
2019-09-26 16:39:02 +02:00
layout : 'fit' ,
items : [
2018-05-16 10:38:35 +02:00
{
name : 'usb' ,
inputValue : 'spice' ,
boxLabel : gettext ( 'Spice Port' ) ,
submitValue : false ,
2021-01-19 17:31:03 +01:00
checked : true ,
2018-05-16 10:38:35 +02:00
} ,
{
name : 'usb' ,
inputValue : 'hostdevice' ,
boxLabel : gettext ( 'Use USB Vendor/Device ID' ) ,
2019-09-23 08:18:09 +02:00
reference : 'hostdevice' ,
2021-01-19 17:31:03 +01:00
submitValue : false ,
2018-05-16 10:38:35 +02:00
} ,
{
xtype : 'pveUSBSelector' ,
disabled : true ,
type : 'device' ,
name : 'hostdevice' ,
cbind : { pveSelNode : '{pveSelNode}' } ,
2019-09-23 08:18:09 +02:00
bind : { disabled : '{!hostdevice.checked}' } ,
2018-05-16 10:38:35 +02:00
editable : true ,
allowBlank : false ,
2019-09-25 14:30:54 +02:00
fieldLabel : gettext ( 'Choose Device' ) ,
2018-05-16 10:38:35 +02:00
labelAlign : 'right' ,
} ,
{
name : 'usb' ,
inputValue : 'port' ,
boxLabel : gettext ( 'Use USB Port' ) ,
2019-09-23 08:18:09 +02:00
reference : 'port' ,
2021-01-19 17:31:03 +01:00
submitValue : false ,
2018-05-16 10:38:35 +02:00
} ,
{
xtype : 'pveUSBSelector' ,
disabled : true ,
name : 'port' ,
cbind : { pveSelNode : '{pveSelNode}' } ,
2019-09-23 08:18:09 +02:00
bind : { disabled : '{!port.checked}' } ,
2018-05-16 10:38:35 +02:00
editable : true ,
type : 'port' ,
allowBlank : false ,
fieldLabel : gettext ( 'Choose Port' ) ,
labelAlign : 'right' ,
} ,
{
xtype : 'checkbox' ,
name : 'usb3' ,
2019-09-11 14:43:34 +02:00
inputValue : true ,
2019-09-26 15:03:17 +02:00
checked : true ,
2018-05-16 10:38:35 +02:00
reference : 'usb3' ,
2021-01-19 17:31:03 +01:00
fieldLabel : gettext ( 'Use USB3' ) ,
} ,
] ,
} ,
] ,
2017-05-29 10:46:33 +02:00
} ) ;
Ext . define ( 'PVE.qemu.USBEdit' , {
2017-12-06 18:12:41 +01:00
extend : 'Proxmox.window.Edit' ,
2017-05-29 10:46:33 +02:00
vmconfig : undefined ,
isAdd : true ,
2019-09-26 16:39:02 +02:00
width : 400 ,
2017-05-29 10:46:33 +02:00
subject : gettext ( 'USB Device' ) ,
2021-01-19 17:39:15 +01:00
initComponent : function ( ) {
2017-05-29 10:46:33 +02:00
var me = this ;
me . isCreate = ! me . confid ;
var ipanel = Ext . create ( 'PVE.qemu.USBInputPanel' , {
confid : me . confid ,
2021-01-19 17:31:03 +01:00
pveSelNode : me . pveSelNode ,
2017-05-29 10:46:33 +02:00
} ) ;
Ext . apply ( me , {
2021-01-19 17:39:15 +01:00
items : [ ipanel ] ,
2017-05-29 10:46:33 +02:00
} ) ;
me . callParent ( ) ;
me . load ( {
success : function ( response , options ) {
ipanel . setVMConfig ( response . result . data ) ;
2019-09-23 10:01:27 +02:00
if ( me . isCreate ) {
return ;
}
2017-05-29 10:46:33 +02:00
2019-09-23 10:01:27 +02:00
var data = response . result . data [ me . confid ] . split ( ',' ) ;
var port , hostdevice , usb3 = false ;
var type = 'spice' ;
for ( let i = 0 ; i < data . length ; i ++ ) {
2021-05-18 14:12:16 +02:00
if ( /^(host=)?(0x)?[a-zA-Z0-9]{4}:(0x)?[a-zA-Z0-9]{4}$/ . test ( data [ i ] ) ) {
2019-09-23 10:01:27 +02:00
hostdevice = data [ i ] ;
2021-01-19 17:31:03 +01:00
hostdevice = hostdevice . replace ( 'host=' , '' ) . replace ( '0x' , '' ) ;
2019-09-23 10:01:27 +02:00
type = 'hostdevice' ;
2021-05-18 14:12:16 +02:00
} else if ( /^(host=)?(\d+)-(\d+(\.\d+)*)$/ . test ( data [ i ] ) ) {
2019-09-23 10:01:27 +02:00
port = data [ i ] ;
port = port . replace ( 'host=' , '' ) ;
type = 'port' ;
}
if ( /^usb3=(1|on|true)$/ . test ( data [ i ] ) ) {
usb3 = true ;
2017-05-29 10:46:33 +02:00
}
}
2019-09-23 10:01:27 +02:00
var values = {
2021-01-19 17:39:15 +01:00
usb : type ,
2019-09-23 10:01:27 +02:00
hostdevice : hostdevice ,
port : port ,
2021-01-19 17:31:03 +01:00
usb3 : usb3 ,
2019-09-23 10:01:27 +02:00
} ;
ipanel . setValues ( values ) ;
2021-01-19 17:31:03 +01:00
} ,
2017-05-29 10:46:33 +02:00
} ) ;
2021-01-19 17:31:03 +01:00
} ,
2017-05-29 10:46:33 +02:00
} ) ;