]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/MPEdit.js
drop jslint lines
[pve-manager.git] / www / manager6 / lxc / MPEdit.js
1 /* hidden: boolean and string
2 * bind: function and object
3 * disabled: boolean and string
4 */
5 Ext.define('PVE.lxc.MountPointInputPanel', {
6 extend: 'Proxmox.panel.InputPanel',
7 xtype: 'pveLxcMountPointInputPanel',
8
9 insideWizard: false,
10
11 onlineHelp: 'pct_container_storage',
12
13 unused: false, // add unused disk imaged
14
15 unprivileged: false,
16
17 vmconfig: {}, // used to select unused disks
18
19 setUnprivileged: function(unprivileged) {
20 var me = this;
21 var vm = me.getViewModel();
22 me.unprivileged = unprivileged;
23 vm.set('unpriv', unprivileged);
24 },
25
26 onGetValues: function(values) {
27 var me = this;
28
29 var confid = me.confid || "mp"+values.mpid;
30 me.mp.file = me.down('field[name=file]').getValue();
31
32 if (me.unused) {
33 confid = "mp"+values.mpid;
34 } else if (me.isCreate) {
35 me.mp.file = values.hdstorage + ':' + values.disksize;
36 }
37
38 // delete unnecessary fields
39 delete values.mpid;
40 delete values.hdstorage;
41 delete values.disksize;
42 delete values.diskformat;
43
44 let mountopts = (values.mountoptions || []).join(';');
45 PVE.Utils.propertyStringSet(me.mp, values.mp, 'mp');
46 PVE.Utils.propertyStringSet(me.mp, values.mountoptions, 'mountoptions', mountopts);
47 PVE.Utils.propertyStringSet(me.mp, values.backup, 'backup');
48 PVE.Utils.propertyStringSet(me.mp, values.quota, 'quota');
49 PVE.Utils.propertyStringSet(me.mp, values.ro, 'ro');
50 PVE.Utils.propertyStringSet(me.mp, values.acl, 'acl');
51 PVE.Utils.propertyStringSet(me.mp, values.replicate, 'replicate');
52
53 var res = {};
54 res[confid] = PVE.Parser.printLxcMountPoint(me.mp);
55 return res;
56 },
57
58
59 setMountPoint: function(mp) {
60 var me = this;
61 var vm = this.getViewModel();
62 vm.set('mptype', mp.type);
63 if (mp.mountoptions) {
64 mp.mountoptions = mp.mountoptions.split(';');
65 }
66 me.mp = mp;
67
68 if (this.confid === 'rootfs') {
69 var field = me.down('field[name=mountoptions]');
70 var forbidden = ['nodev', 'noexec'];
71 var filtered = field.comboItems.filter(e => !forbidden.includes(e[0]));
72 field.setComboItems(filtered);
73 }
74
75 me.setValues(mp);
76 },
77
78 setVMConfig: function(vmconfig) {
79 var me = this;
80 var vm = me.getViewModel();
81 me.vmconfig = vmconfig;
82 vm.set('unpriv', vmconfig.unprivileged);
83
84 PVE.Utils.forEachMP(function(bus, i) {
85 var name = "mp" + i.toString();
86 if (!Ext.isDefined(vmconfig[name])) {
87 me.down('field[name=mpid]').setValue(i);
88 return false;
89 }
90 });
91 },
92
93 setNodename: function(nodename) {
94 var me = this;
95 var vm = me.getViewModel();
96 vm.set('node', nodename);
97 me.down('#diskstorage').setNodename(nodename);
98 },
99
100 controller: {
101 xclass: 'Ext.app.ViewController',
102
103 control: {
104 'field[name=mpid]': {
105 change: function(field, value) {
106 field.validate();
107 }
108 },
109 '#hdstorage': {
110 change: function(field, newValue) {
111 var me = this;
112 if (!newValue) {
113 return;
114 }
115
116 var rec = field.store.getById(newValue);
117 if (!rec) {
118 return;
119 }
120
121 var vm = me.getViewModel();
122 vm.set('type', rec.data.type);
123 }
124 }
125 },
126
127 init: function(view) {
128 var me = this;
129 var vm = this.getViewModel();
130 view.mp = {};
131 vm.set('confid', view.confid);
132 vm.set('unused', view.unused);
133 vm.set('node', view.nodename);
134 vm.set('unpriv', view.unprivileged);
135 vm.set('hideStorSelector', view.unused || !view.isCreate);
136
137 // can be array if created from unused disk
138 if (view.isCreate) {
139 vm.set('isIncludedInBackup', true);
140 }
141 }
142 },
143
144 viewModel: {
145 data: {
146 unpriv: false,
147 unused: false,
148 showStorageSelector: false,
149 mptype: '',
150 type: '',
151 confid: '',
152 node: ''
153 },
154
155 formulas: {
156 quota: function(get) {
157 return !(get('type') === 'zfs' ||
158 get('type') === 'zfspool' ||
159 get('unpriv') ||
160 get('isBind'));
161 },
162 hasMP: function(get) {
163 return !!get('confid') && !get('unused');
164 },
165 isRoot: function(get) {
166 return get('confid') === 'rootfs';
167 },
168 isBind: function(get) {
169 return get('mptype') === 'bind';
170 },
171 isBindOrRoot: function(get) {
172 return get('isBind') || get('isRoot');
173 }
174 }
175 },
176
177 column1: [
178 {
179 xtype: 'proxmoxintegerfield',
180 name: 'mpid',
181 fieldLabel: gettext('Mount Point ID'),
182 minValue: 0,
183 maxValue: PVE.Utils.mp_counts.mps - 1,
184 hidden: true,
185 allowBlank: false,
186 disabled: true,
187 bind: {
188 hidden: '{hasMP}',
189 disabled: '{hasMP}'
190 },
191 validator: function(value) {
192 var me = this.up('inputpanel');
193 if (!me.rendered) {
194 return;
195 }
196 if (Ext.isDefined(me.vmconfig["mp"+value])) {
197 return "Mount point is already in use.";
198 }
199 /* returns a string above */
200 return true;
201 }
202 },
203 {
204 xtype: 'pveDiskStorageSelector',
205 itemId: 'diskstorage',
206 storageContent: 'rootdir',
207 hidden: true,
208 autoSelect: true,
209 selectformat: false,
210 defaultSize: 8,
211 bind: {
212 hidden: '{hideStorSelector}',
213 disabled: '{hideStorSelector}',
214 nodename: '{node}'
215 }
216 },
217 {
218 xtype: 'textfield',
219 disabled: true,
220 submitValue: false,
221 fieldLabel: gettext('Disk image'),
222 name: 'file',
223 bind: {
224 hidden: '{!hideStorSelector}'
225 }
226 }
227 ],
228
229 column2: [
230 {
231 xtype: 'textfield',
232 name: 'mp',
233 value: '',
234 emptyText: gettext('/some/path'),
235 allowBlank: false,
236 disabled: true,
237 fieldLabel: gettext('Path'),
238 bind: {
239 hidden: '{isRoot}',
240 disabled: '{isRoot}'
241 }
242 },
243 {
244 xtype: 'proxmoxcheckbox',
245 name: 'backup',
246 fieldLabel: gettext('Backup'),
247 autoEl: {
248 tag: 'div',
249 'data-qtip': gettext('Include volume in backup job'),
250 },
251 bind: {
252 hidden: '{isRoot}',
253 disabled: '{isBindOrRoot}',
254 value: '{isIncludedInBackup}'
255 }
256 }
257 ],
258
259 advancedColumn1: [
260 {
261 xtype: 'proxmoxcheckbox',
262 name: 'quota',
263 defaultValue: 0,
264 bind: {
265 disabled: '{!quota}'
266 },
267 fieldLabel: gettext('Enable quota'),
268 listeners: {
269 disable: function() {
270 this.reset();
271 }
272 }
273 },
274 {
275 xtype: 'proxmoxcheckbox',
276 name: 'ro',
277 defaultValue: 0,
278 bind: {
279 hidden: '{isRoot}',
280 disabled: '{isRoot}'
281 },
282 fieldLabel: gettext('Read-only')
283 },
284 {
285 xtype: 'proxmoxKVComboBox',
286 name: 'mountoptions',
287 fieldLabel: gettext('Mount options'),
288 deleteEmpty: false,
289 comboItems: [
290 ['noatime', 'noatime'],
291 ['nodev', 'nodev'],
292 ['noexec', 'noexec'],
293 ['nosuid', 'nosuid']
294 ],
295 multiSelect: true,
296 value: [],
297 allowBlank: true
298 },
299 ],
300
301 advancedColumn2: [
302 {
303 xtype: 'proxmoxKVComboBox',
304 name: 'acl',
305 fieldLabel: 'ACLs',
306 deleteEmpty: false,
307 comboItems: [
308 ['__default__', Proxmox.Utils.defaultText],
309 ['1', Proxmox.Utils.enabledText],
310 ['0', Proxmox.Utils.disabledText]
311 ],
312 value: '__default__',
313 bind: {
314 disabled: '{isBind}'
315 },
316 allowBlank: true
317 },
318 {
319 xtype: 'proxmoxcheckbox',
320 inputValue: '0', // reverses the logic
321 name: 'replicate',
322 fieldLabel: gettext('Skip replication')
323 }
324 ]
325 });
326
327 Ext.define('PVE.lxc.MountPointEdit', {
328 extend: 'Proxmox.window.Edit',
329
330 unprivileged: false,
331
332 initComponent : function() {
333 var me = this;
334
335 var nodename = me.pveSelNode.data.node;
336 if (!nodename) {
337 throw "no node name specified";
338 }
339
340 var unused = me.confid && me.confid.match(/^unused\d+$/);
341
342 me.isCreate = me.confid ? unused : true;
343
344 var ipanel = Ext.create('PVE.lxc.MountPointInputPanel', {
345 confid: me.confid,
346 nodename: nodename,
347 unused: unused,
348 unprivileged: me.unprivileged,
349 isCreate: me.isCreate
350 });
351
352 var subject;
353 if (unused) {
354 subject = gettext('Unused Disk');
355 } else if (me.isCreate) {
356 subject = gettext('Mount Point');
357 } else {
358 subject = gettext('Mount Point') + ' (' + me.confid + ')';
359 }
360
361 Ext.apply(me, {
362 subject: subject,
363 defaultFocus: me.confid !== 'rootfs' ? 'textfield[name=mp]' : 'tool',
364 items: ipanel
365 });
366
367 me.callParent();
368
369 me.load({
370 success: function(response, options) {
371 ipanel.setVMConfig(response.result.data);
372 if (me.confid) {
373 /*data is defined as array above*/
374 var value = response.result.data[me.confid];
375 var mp = PVE.Parser.parseLxcMountPoint(value);
376
377 if (!mp) {
378 Ext.Msg.alert(gettext('Error'), 'Unable to parse mount point options');
379 me.close();
380 return;
381 }
382
383 ipanel.setMountPoint(mp);
384 me.isValid(); // trigger validation
385 }
386 }
387 });
388 }
389 });