]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/USBEdit.js
update shipped appliance info index
[pve-manager.git] / www / manager6 / qemu / USBEdit.js
1 Ext.define('PVE.qemu.USBInputPanel', {
2 extend: 'Proxmox.panel.InputPanel',
3 mixins: ['Proxmox.Mixin.CBind'],
4
5 autoComplete: false,
6 onlineHelp: 'qm_usb_passthrough',
7
8 viewModel: {
9 data: {},
10 },
11
12 setVMConfig: function(vmconfig) {
13 var me = this;
14 me.vmconfig = vmconfig;
15 let max_usb = PVE.Utils.get_max_usb_count(me.vmconfig.ostype, me.vmconfig.machine);
16 if (max_usb > PVE.Utils.hardware_counts.usb_old) {
17 me.down('field[name=usb3]').setDisabled(true);
18 }
19 },
20
21 onGetValues: function(values) {
22 var me = this;
23 if (!me.confid) {
24 let max_usb = PVE.Utils.get_max_usb_count(me.vmconfig.ostype, me.vmconfig.machine);
25 for (let i = 0; i < max_usb; i++) {
26 let id = 'usb' + i.toString();
27 if (!me.vmconfig[id]) {
28 me.confid = id;
29 break;
30 }
31 }
32 }
33 var val = "";
34 var type = me.down('radiofield').getGroupValue();
35 switch (type) {
36 case 'spice':
37 val = 'spice';
38 break;
39 case 'hostdevice':
40 case 'port':
41 val = 'host=' + values[type];
42 delete values[type];
43 break;
44 default:
45 throw "invalid type selected";
46 }
47
48 if (values.usb3) {
49 delete values.usb3;
50 val += ',usb3=1';
51 }
52 values[me.confid] = val;
53 return values;
54 },
55
56 items: [
57 {
58 xtype: 'fieldcontainer',
59 defaultType: 'radiofield',
60 layout: 'fit',
61 items: [
62 {
63 name: 'usb',
64 inputValue: 'spice',
65 boxLabel: gettext('Spice Port'),
66 submitValue: false,
67 checked: true,
68 },
69 {
70 name: 'usb',
71 inputValue: 'hostdevice',
72 boxLabel: gettext('Use USB Vendor/Device ID'),
73 reference: 'hostdevice',
74 submitValue: false,
75 },
76 {
77 xtype: 'pveUSBSelector',
78 disabled: true,
79 type: 'device',
80 name: 'hostdevice',
81 cbind: { pveSelNode: '{pveSelNode}' },
82 bind: { disabled: '{!hostdevice.checked}' },
83 editable: true,
84 allowBlank: false,
85 fieldLabel: gettext('Choose Device'),
86 labelAlign: 'right',
87 },
88 {
89 name: 'usb',
90 inputValue: 'port',
91 boxLabel: gettext('Use USB Port'),
92 reference: 'port',
93 submitValue: false,
94 },
95 {
96 xtype: 'pveUSBSelector',
97 disabled: true,
98 name: 'port',
99 cbind: { pveSelNode: '{pveSelNode}' },
100 bind: { disabled: '{!port.checked}' },
101 editable: true,
102 type: 'port',
103 allowBlank: false,
104 fieldLabel: gettext('Choose Port'),
105 labelAlign: 'right',
106 },
107 {
108 xtype: 'checkbox',
109 name: 'usb3',
110 inputValue: true,
111 checked: true,
112 reference: 'usb3',
113 fieldLabel: gettext('Use USB3'),
114 },
115 ],
116 },
117 ],
118 });
119
120 Ext.define('PVE.qemu.USBEdit', {
121 extend: 'Proxmox.window.Edit',
122
123 vmconfig: undefined,
124
125 isAdd: true,
126 width: 400,
127 subject: gettext('USB Device'),
128
129 initComponent: function() {
130 var me = this;
131
132 me.isCreate = !me.confid;
133
134 var ipanel = Ext.create('PVE.qemu.USBInputPanel', {
135 confid: me.confid,
136 pveSelNode: me.pveSelNode,
137 });
138
139 Ext.apply(me, {
140 items: [ipanel],
141 });
142
143 me.callParent();
144
145 me.load({
146 success: function(response, options) {
147 ipanel.setVMConfig(response.result.data);
148 if (me.isCreate) {
149 return;
150 }
151
152 var data = response.result.data[me.confid].split(',');
153 var port, hostdevice, usb3 = false;
154 var type = 'spice';
155
156 for (let i = 0; i < data.length; i++) {
157 if (/^(host=)?(0x)?[a-zA-Z0-9]{4}:(0x)?[a-zA-Z0-9]{4}$/.test(data[i])) {
158 hostdevice = data[i];
159 hostdevice = hostdevice.replace('host=', '').replace('0x', '');
160 type = 'hostdevice';
161 } else if (/^(host=)?(\d+)-(\d+(\.\d+)*)$/.test(data[i])) {
162 port = data[i];
163 port = port.replace('host=', '');
164 type = 'port';
165 }
166
167 if (/^usb3=(1|on|true)$/.test(data[i])) {
168 usb3 = true;
169 }
170 }
171 var values = {
172 usb: type,
173 hostdevice: hostdevice,
174 port: port,
175 usb3: usb3,
176 };
177
178 ipanel.setValues(values);
179 },
180 });
181 },
182 });