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