]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/DeviceEdit.js
ui: lxc: add edit window for device passthrough
[pve-manager.git] / www / manager6 / lxc / DeviceEdit.js
1 Ext.define('PVE.lxc.DeviceInputPanel', {
2 extend: 'Proxmox.panel.InputPanel',
3 mixins: ['Proxmox.Mixin.CBind'],
4
5 autoComplete: false,
6
7 controller: {
8 xclass: 'Ext.app.ViewController',
9 },
10
11 setVMConfig: function(vmconfig) {
12 let me = this;
13 me.vmconfig = vmconfig;
14
15 if (me.isCreate) {
16 PVE.Utils.forEachLxcDev((i) => {
17 let name = "dev" + i.toString();
18 if (!Ext.isDefined(vmconfig[name])) {
19 me.confid = name;
20 me.down('field[name=devid]').setValue(i);
21 return false;
22 }
23 return undefined;
24 });
25 }
26 },
27
28 onGetValues: function(values) {
29 let me = this;
30 let confid = me.isCreate ? "dev" + values.devid : me.confid;
31 delete values.devid;
32 let val = PVE.Parser.printPropertyString(values, 'path');
33 let ret = {};
34 ret[confid] = val;
35 return ret;
36 },
37
38 items: [
39 {
40 xtype: 'proxmoxintegerfield',
41 name: 'devid',
42 fieldLabel: gettext('Passthrough ID'),
43 minValue: 0,
44 maxValue: PVE.Utils.dev_count - 1,
45 hidden: true,
46 allowBlank: false,
47 disabled: true,
48 labelAlign: 'right',
49 cbind: {
50 hidden: '{!isCreate}',
51 disabled: '{!isCreate}',
52 },
53 validator: function(value) {
54 let view = this.up('inputpanel');
55 if (!view.vmconfig) {
56 return undefined;
57 }
58 if (Ext.isDefined(view.vmconfig["dev" + value])) {
59 return "Device passthrough is already in use.";
60 }
61 return true;
62 },
63 },
64 {
65 xtype: 'textfield',
66 type: 'device',
67 name: 'path',
68 editable: true,
69 allowBlank: false,
70 fieldLabel: gettext('Device Path'),
71 emptyText: '/dev/xyz',
72 labelAlign: 'right',
73 validator: function(value) {
74 if (value.startsWith('/dev/')) {
75 return true;
76 }
77
78 return "Path has to start with /dev/";
79 },
80 },
81 ],
82
83 advancedColumn1: [
84 {
85 xtype: 'proxmoxintegerfield',
86 name: 'uid',
87 editable: true,
88 fieldLabel: 'UID',
89 emptyText: '0',
90 minValue: 0,
91 labelAlign: 'right',
92 },
93 {
94 xtype: 'proxmoxintegerfield',
95 name: 'gid',
96 editable: true,
97 fieldLabel: 'GID',
98 emptyText: '0',
99 minValue: 0,
100 labelAlign: 'right',
101 },
102 ],
103
104 advancedColumn2: [
105 {
106 xtype: 'textfield',
107 name: 'mode',
108 editable: true,
109 fieldLabel: gettext('Access Mode'),
110 emptyText: '0660',
111 labelAlign: 'right',
112 validator: function(value) {
113 if (/^0[0-7]{3}$|^$/i.test(value)) {
114 return true;
115 }
116
117 return "Access mode has to be an octal number";
118 },
119 },
120 ],
121 });
122
123 Ext.define('PVE.lxc.DeviceEdit', {
124 extend: 'Proxmox.window.Edit',
125
126 vmconfig: undefined,
127
128 isAdd: true,
129 width: 400,
130
131 initComponent: function() {
132 let me = this;
133
134 me.isCreate = !me.confid;
135
136 let ipanel = Ext.create('PVE.lxc.DeviceInputPanel', {
137 confid: me.confid,
138 isCreate: me.isCreate,
139 pveSelNode: me.pveSelNode,
140 });
141
142 let subject;
143 if (me.isCreate) {
144 subject = gettext('Device');
145 } else {
146 subject = gettext('Device') + ' (' + me.confid + ')';
147 }
148
149 Ext.apply(me, {
150 subject: subject,
151 items: [ipanel],
152 });
153
154 me.callParent();
155
156 me.load({
157 success: function(response, options) {
158 ipanel.setVMConfig(response.result.data);
159 if (me.isCreate) {
160 return;
161 }
162
163 let data = PVE.Parser.parsePropertyString(response.result.data[me.confid], 'path');
164
165 let values = {
166 path: data.path,
167 mode: data.mode,
168 uid: data.uid,
169 gid: data.gid,
170 };
171
172 ipanel.setValues(values);
173 },
174 });
175 },
176 });