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