]>
Commit | Line | Data |
---|---|---|
8f795124 DC |
1 | /*global |
2 | FileReader | |
3 | */ | |
256a65a4 | 4 | |
09358a73 DM |
5 | Ext.define('PVE.lxc.CreateWizard', { |
6 | extend: 'PVE.window.Wizard', | |
7 | ||
8 | initComponent: function() { | |
9 | var me = this; | |
10 | ||
11 | var summarystore = Ext.create('Ext.data.Store', { | |
12 | model: 'KeyValue', | |
13 | sorters: [ | |
14 | { | |
15 | property : 'key', | |
16 | direction: 'ASC' | |
17 | } | |
18 | ] | |
19 | }); | |
20 | ||
21 | var tmplsel = Ext.create('PVE.form.FileSelector', { | |
22 | name: 'ostemplate', | |
23 | storageContent: 'vztmpl', | |
24 | fieldLabel: gettext('Template'), | |
25 | allowBlank: false | |
26 | }); | |
27 | ||
28 | var tmplstoragesel = Ext.create('PVE.form.StorageSelector', { | |
29 | name: 'tmplstorage', | |
30 | fieldLabel: gettext('Storage'), | |
31 | storageContent: 'vztmpl', | |
32 | autoSelect: true, | |
33 | allowBlank: false, | |
34 | listeners: { | |
35 | change: function(f, value) { | |
36 | tmplsel.setStorage(value); | |
37 | } | |
38 | } | |
39 | }); | |
40 | ||
41 | var rootfspanel = Ext.create('PVE.lxc.MountPointInputPanel', { | |
42 | title: gettext('Root Disk'), | |
43 | insideWizard: true, | |
d5e771ce | 44 | isCreate: true, |
09358a73 | 45 | unused: false, |
c15e9cd5 | 46 | unprivileged: false, |
09358a73 DM |
47 | confid: 'rootfs' |
48 | }); | |
49 | ||
50 | var networkpanel = Ext.create('PVE.lxc.NetworkInputPanel', { | |
51 | title: gettext('Network'), | |
52 | insideWizard: true, | |
53 | dataCache: {}, | |
d5e771ce | 54 | isCreate: true |
09358a73 DM |
55 | }); |
56 | ||
b1339314 WB |
57 | var passwordfield = Ext.createWidget('textfield', { |
58 | inputType: 'password', | |
59 | name: 'password', | |
60 | value: '', | |
61 | fieldLabel: gettext('Password'), | |
62 | allowBlank: false, | |
63 | minLength: 5, | |
64 | change: function(f, value) { | |
65 | if (!me.rendered) { | |
66 | return; | |
67 | } | |
68 | me.down('field[name=confirmpw]').validate(); | |
69 | } | |
70 | }); | |
71 | ||
256a65a4 EK |
72 | /*jslint confusion: true */ |
73 | /* the validator function can return either a string or a boolean */ | |
dbed4c1c | 74 | me.sshkeyfield = Ext.createWidget('proxmoxtextfield', { |
b1339314 WB |
75 | name: 'ssh-public-keys', |
76 | value: '', | |
77 | fieldLabel: gettext('SSH public key'), | |
78 | allowBlank: true, | |
79 | validator: function(value) { | |
80 | if (value.length) { | |
81 | var key = PVE.Parser.parseSSHKey(value); | |
82 | if (!key) { | |
83 | return "Failed to recognize ssh key"; | |
84 | } | |
85 | me.down('field[name=password]').allowBlank = true; | |
86 | } else { | |
87 | me.down('field[name=password]').allowBlank = false; | |
88 | } | |
89 | me.down('field[name=password]').validate(); | |
90 | return true; | |
91 | }, | |
92 | afterRender: function() { | |
93 | if (!window.FileReader) { | |
94 | // No FileReader support in this browser | |
95 | return; | |
96 | } | |
97 | var cancel = function(ev) { | |
98 | ev = ev.event; | |
99 | if (ev.preventDefault) { | |
100 | ev.preventDefault(); | |
101 | } | |
102 | }; | |
103 | me.sshkeyfield.inputEl.on('dragover', cancel); | |
104 | me.sshkeyfield.inputEl.on('dragenter', cancel); | |
105 | me.sshkeyfield.inputEl.on('drop', function(ev) { | |
106 | ev = ev.event; | |
107 | if (ev.preventDefault) { | |
108 | ev.preventDefault(); | |
109 | } | |
110 | var files = ev.dataTransfer.files; | |
857b97a7 TL |
111 | PVE.Utils.loadSSHKeyFromFile(files[0], function (v) { |
112 | me.sshkeyfield.setValue(v); | |
113 | }); | |
b1339314 | 114 | }); |
8f795124 | 115 | } |
b1339314 WB |
116 | }); |
117 | ||
118 | var column2 = [ | |
119 | { | |
120 | xtype: 'pvePoolSelector', | |
121 | fieldLabel: gettext('Resource Pool'), | |
122 | name: 'pool', | |
123 | value: '', | |
124 | allowBlank: true | |
125 | }, | |
126 | passwordfield, | |
127 | { | |
128 | xtype: 'textfield', | |
129 | inputType: 'password', | |
130 | name: 'confirmpw', | |
131 | value: '', | |
132 | fieldLabel: gettext('Confirm password'), | |
133 | allowBlank: true, | |
134 | validator: function(value) { | |
135 | var pw = me.down('field[name=password]').getValue(); | |
136 | if (pw !== value) { | |
fd776fca | 137 | return "Passwords do not match!"; |
b1339314 WB |
138 | } |
139 | return true; | |
140 | } | |
141 | }, | |
142 | me.sshkeyfield | |
143 | ]; | |
256a65a4 | 144 | /*jslint confusion: false */ |
b1339314 WB |
145 | |
146 | if (window.FileReader) { | |
147 | column2.push({ | |
148 | xtype: 'filebutton', | |
149 | name: 'file', | |
150 | text: gettext('Load SSH Key File'), | |
151 | listeners: { | |
152 | change: function(btn, e, value) { | |
153 | e = e.event; | |
857b97a7 TL |
154 | PVE.Utils.loadSSHKeyFromFile(e.target.files[0], function (v) { |
155 | me.sshkeyfield.setValue(v); | |
156 | }); | |
b1339314 WB |
157 | btn.reset(); |
158 | } | |
159 | } | |
160 | }); | |
161 | } | |
162 | ||
09358a73 DM |
163 | Ext.applyIf(me, { |
164 | subject: gettext('LXC Container'), | |
165 | items: [ | |
166 | { | |
167 | xtype: 'inputpanel', | |
168 | title: gettext('General'), | |
ff05aec0 | 169 | onlineHelp: 'pct_general', |
09358a73 DM |
170 | column1: [ |
171 | { | |
2d0aa6d1 | 172 | xtype: 'pveNodeSelector', |
09358a73 | 173 | name: 'nodename', |
05c4b764 DC |
174 | selectCurNode: !me.nodename, |
175 | preferredValue: me.nodename, | |
09358a73 DM |
176 | fieldLabel: gettext('Node'), |
177 | allowBlank: false, | |
178 | onlineValidator: true, | |
179 | listeners: { | |
180 | change: function(f, value) { | |
181 | tmplstoragesel.setNodename(value); | |
182 | tmplsel.setStorage(undefined, value); | |
183 | networkpanel.setNodename(value); | |
184 | rootfspanel.setNodename(value); | |
185 | } | |
186 | } | |
187 | }, | |
188 | { | |
ed416f20 EK |
189 | xtype: 'pveGuestIDSelector', |
190 | name: 'vmid', // backend only knows vmid | |
191 | guestType: 'lxc', | |
09358a73 | 192 | value: '', |
ed416f20 | 193 | loadNextFreeID: true, |
09358a73 DM |
194 | validateExists: false |
195 | }, | |
196 | { | |
dbed4c1c | 197 | xtype: 'proxmoxtextfield', |
09358a73 DM |
198 | name: 'hostname', |
199 | vtype: 'DnsName', | |
200 | value: '', | |
201 | fieldLabel: gettext('Hostname'), | |
202 | skipEmptyText: true, | |
203 | allowBlank: true | |
a97bc800 EK |
204 | }, |
205 | { | |
896c0d50 | 206 | xtype: 'proxmoxcheckbox', |
a97bc800 EK |
207 | name: 'unprivileged', |
208 | value: '', | |
c15e9cd5 PA |
209 | listeners: { |
210 | change: function(f, value) { | |
211 | if (value) { | |
212 | rootfspanel.down('field[name=quota]').setValue(false); | |
213 | } | |
214 | rootfspanel.unprivileged = value; | |
234d2e37 | 215 | var hdsel = rootfspanel.down('#hdstorage'); |
c15e9cd5 PA |
216 | hdsel.fireEvent('change', hdsel, hdsel.getValue()); |
217 | } | |
218 | }, | |
a97bc800 | 219 | fieldLabel: gettext('Unprivileged container') |
09358a73 DM |
220 | } |
221 | ], | |
b1339314 | 222 | column2: column2, |
09358a73 DM |
223 | onGetValues: function(values) { |
224 | delete values.confirmpw; | |
225 | if (!values.pool) { | |
226 | delete values.pool; | |
227 | } | |
228 | return values; | |
229 | } | |
230 | }, | |
231 | { | |
232 | xtype: 'inputpanel', | |
233 | title: gettext('Template'), | |
c8802a60 | 234 | onlineHelp: 'pct_container_images', |
09358a73 DM |
235 | column1: [ tmplstoragesel, tmplsel] |
236 | }, | |
237 | rootfspanel, | |
238 | { | |
239 | xtype: 'pveLxcCPUInputPanel', | |
240 | title: gettext('CPU'), | |
241 | insideWizard: true | |
242 | }, | |
243 | { | |
244 | xtype: 'pveLxcMemoryInputPanel', | |
245 | title: gettext('Memory'), | |
246 | insideWizard: true | |
247 | }, | |
248 | networkpanel, | |
249 | { | |
250 | xtype: 'pveLxcDNSInputPanel', | |
251 | title: gettext('DNS'), | |
252 | insideWizard: true | |
253 | }, | |
254 | { | |
255 | title: gettext('Confirm'), | |
256 | layout: 'fit', | |
257 | items: [ | |
258 | { | |
09358a73 DM |
259 | xtype: 'grid', |
260 | store: summarystore, | |
261 | columns: [ | |
262 | {header: 'Key', width: 150, dataIndex: 'key'}, | |
263 | {header: 'Value', flex: 1, dataIndex: 'value'} | |
264 | ] | |
265 | } | |
266 | ], | |
267 | listeners: { | |
268 | show: function(panel) { | |
269 | var form = me.down('form').getForm(); | |
270 | var kv = me.getValues(); | |
271 | var data = []; | |
272 | Ext.Object.each(kv, function(key, value) { | |
273 | if (key === 'delete' || key === 'tmplstorage') { // ignore | |
274 | return; | |
275 | } | |
276 | if (key === 'password') { // don't show pw | |
277 | return; | |
278 | } | |
279 | var html = Ext.htmlEncode(Ext.JSON.encode(value)); | |
280 | data.push({ key: key, value: value }); | |
281 | }); | |
282 | summarystore.suspendEvents(); | |
283 | summarystore.removeAll(); | |
284 | summarystore.add(data); | |
285 | summarystore.sort(); | |
286 | summarystore.resumeEvents(); | |
59f2dd3d | 287 | summarystore.fireEvent('refresh'); |
09358a73 DM |
288 | } |
289 | }, | |
290 | onSubmit: function() { | |
291 | var kv = me.getValues(); | |
292 | delete kv['delete']; | |
293 | ||
294 | var nodename = kv.nodename; | |
295 | delete kv.nodename; | |
296 | delete kv.tmplstorage; | |
297 | ||
83576841 | 298 | if (!kv.password.length && kv['ssh-public-keys']) { |
8f795124 | 299 | delete kv.password; |
b1339314 WB |
300 | } |
301 | ||
e7ade592 | 302 | Proxmox.Utils.API2Request({ |
09358a73 DM |
303 | url: '/nodes/' + nodename + '/lxc', |
304 | waitMsgTarget: me, | |
305 | method: 'POST', | |
306 | params: kv, | |
307 | success: function(response, opts){ | |
308 | var upid = response.result.data; | |
fd776fca | 309 | |
8cbc11a7 | 310 | var win = Ext.create('Proxmox.window.TaskViewer', { |
09358a73 DM |
311 | upid: upid |
312 | }); | |
313 | win.show(); | |
314 | me.close(); | |
315 | }, | |
316 | failure: function(response, opts) { | |
317 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
318 | } | |
319 | }); | |
320 | } | |
321 | } | |
322 | ] | |
323 | }); | |
324 | ||
325 | me.callParent(); | |
326 | } | |
327 | }); | |
328 | ||
329 | ||
330 |