]>
Commit | Line | Data |
---|---|---|
09358a73 DM |
1 | /*jslint confusion: true */ |
2 | Ext.define('PVE.lxc.CreateWizard', { | |
3 | extend: 'PVE.window.Wizard', | |
4 | ||
5 | initComponent: function() { | |
6 | var me = this; | |
7 | ||
8 | var summarystore = Ext.create('Ext.data.Store', { | |
9 | model: 'KeyValue', | |
10 | sorters: [ | |
11 | { | |
12 | property : 'key', | |
13 | direction: 'ASC' | |
14 | } | |
15 | ] | |
16 | }); | |
17 | ||
18 | var tmplsel = Ext.create('PVE.form.FileSelector', { | |
19 | name: 'ostemplate', | |
20 | storageContent: 'vztmpl', | |
21 | fieldLabel: gettext('Template'), | |
22 | allowBlank: false | |
23 | }); | |
24 | ||
25 | var tmplstoragesel = Ext.create('PVE.form.StorageSelector', { | |
26 | name: 'tmplstorage', | |
27 | fieldLabel: gettext('Storage'), | |
28 | storageContent: 'vztmpl', | |
29 | autoSelect: true, | |
30 | allowBlank: false, | |
31 | listeners: { | |
32 | change: function(f, value) { | |
33 | tmplsel.setStorage(value); | |
34 | } | |
35 | } | |
36 | }); | |
37 | ||
38 | var rootfspanel = Ext.create('PVE.lxc.MountPointInputPanel', { | |
39 | title: gettext('Root Disk'), | |
40 | insideWizard: true, | |
41 | create: true, | |
42 | unused: false, | |
43 | confid: 'rootfs' | |
44 | }); | |
45 | ||
46 | var networkpanel = Ext.create('PVE.lxc.NetworkInputPanel', { | |
47 | title: gettext('Network'), | |
48 | insideWizard: true, | |
49 | dataCache: {}, | |
50 | create: true | |
51 | }); | |
52 | ||
53 | Ext.applyIf(me, { | |
54 | subject: gettext('LXC Container'), | |
55 | items: [ | |
56 | { | |
57 | xtype: 'inputpanel', | |
58 | title: gettext('General'), | |
59 | column1: [ | |
60 | { | |
61 | xtype: 'PVE.form.NodeSelector', | |
62 | name: 'nodename', | |
63 | fieldLabel: gettext('Node'), | |
64 | allowBlank: false, | |
65 | onlineValidator: true, | |
66 | listeners: { | |
67 | change: function(f, value) { | |
68 | tmplstoragesel.setNodename(value); | |
69 | tmplsel.setStorage(undefined, value); | |
70 | networkpanel.setNodename(value); | |
71 | rootfspanel.setNodename(value); | |
72 | } | |
73 | } | |
74 | }, | |
75 | { | |
76 | xtype: 'pveVMIDSelector', | |
77 | name: 'vmid', | |
78 | value: '', | |
79 | loadNextFreeVMID: true, | |
80 | validateExists: false | |
81 | }, | |
82 | { | |
83 | xtype: 'pvetextfield', | |
84 | name: 'hostname', | |
85 | vtype: 'DnsName', | |
86 | value: '', | |
87 | fieldLabel: gettext('Hostname'), | |
88 | skipEmptyText: true, | |
89 | allowBlank: true | |
90 | } | |
91 | ], | |
92 | column2: [ | |
93 | { | |
94 | xtype: 'pvePoolSelector', | |
95 | fieldLabel: gettext('Resource Pool'), | |
96 | name: 'pool', | |
97 | value: '', | |
98 | allowBlank: true | |
99 | }, | |
100 | { | |
101 | xtype: 'textfield', | |
102 | inputType: 'password', | |
103 | name: 'password', | |
104 | value: '', | |
105 | fieldLabel: gettext('Password'), | |
106 | allowBlank: false, | |
107 | minLength: 5, | |
108 | change: function(f, value) { | |
109 | if (!me.rendered) { | |
110 | return; | |
111 | } | |
112 | me.down('field[name=confirmpw]').validate(); | |
113 | } | |
114 | }, | |
115 | { | |
116 | xtype: 'textfield', | |
117 | inputType: 'password', | |
118 | name: 'confirmpw', | |
119 | value: '', | |
120 | fieldLabel: gettext('Confirm password'), | |
121 | allowBlank: false, | |
122 | validator: function(value) { | |
123 | var pw = me.down('field[name=password]').getValue(); | |
124 | if (pw !== value) { | |
125 | return "Passwords does not match!"; | |
126 | } | |
127 | return true; | |
128 | } | |
129 | } | |
130 | ], | |
131 | onGetValues: function(values) { | |
132 | delete values.confirmpw; | |
133 | if (!values.pool) { | |
134 | delete values.pool; | |
135 | } | |
136 | return values; | |
137 | } | |
138 | }, | |
139 | { | |
140 | xtype: 'inputpanel', | |
141 | title: gettext('Template'), | |
142 | column1: [ tmplstoragesel, tmplsel] | |
143 | }, | |
144 | rootfspanel, | |
145 | { | |
146 | xtype: 'pveLxcCPUInputPanel', | |
147 | title: gettext('CPU'), | |
148 | insideWizard: true | |
149 | }, | |
150 | { | |
151 | xtype: 'pveLxcMemoryInputPanel', | |
152 | title: gettext('Memory'), | |
153 | insideWizard: true | |
154 | }, | |
155 | networkpanel, | |
156 | { | |
157 | xtype: 'pveLxcDNSInputPanel', | |
158 | title: gettext('DNS'), | |
159 | insideWizard: true | |
160 | }, | |
161 | { | |
162 | title: gettext('Confirm'), | |
163 | layout: 'fit', | |
164 | items: [ | |
165 | { | |
166 | title: gettext('Settings'), | |
167 | xtype: 'grid', | |
168 | store: summarystore, | |
169 | columns: [ | |
170 | {header: 'Key', width: 150, dataIndex: 'key'}, | |
171 | {header: 'Value', flex: 1, dataIndex: 'value'} | |
172 | ] | |
173 | } | |
174 | ], | |
175 | listeners: { | |
176 | show: function(panel) { | |
177 | var form = me.down('form').getForm(); | |
178 | var kv = me.getValues(); | |
179 | var data = []; | |
180 | Ext.Object.each(kv, function(key, value) { | |
181 | if (key === 'delete' || key === 'tmplstorage') { // ignore | |
182 | return; | |
183 | } | |
184 | if (key === 'password') { // don't show pw | |
185 | return; | |
186 | } | |
187 | var html = Ext.htmlEncode(Ext.JSON.encode(value)); | |
188 | data.push({ key: key, value: value }); | |
189 | }); | |
190 | summarystore.suspendEvents(); | |
191 | summarystore.removeAll(); | |
192 | summarystore.add(data); | |
193 | summarystore.sort(); | |
194 | summarystore.resumeEvents(); | |
195 | summarystore.fireEvent('datachanged', summarystore); | |
196 | } | |
197 | }, | |
198 | onSubmit: function() { | |
199 | var kv = me.getValues(); | |
200 | delete kv['delete']; | |
201 | ||
202 | var nodename = kv.nodename; | |
203 | delete kv.nodename; | |
204 | delete kv.tmplstorage; | |
205 | ||
206 | PVE.Utils.API2Request({ | |
207 | url: '/nodes/' + nodename + '/lxc', | |
208 | waitMsgTarget: me, | |
209 | method: 'POST', | |
210 | params: kv, | |
211 | success: function(response, opts){ | |
212 | var upid = response.result.data; | |
213 | ||
214 | var win = Ext.create('PVE.window.TaskViewer', { | |
215 | upid: upid | |
216 | }); | |
217 | win.show(); | |
218 | me.close(); | |
219 | }, | |
220 | failure: function(response, opts) { | |
221 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
222 | } | |
223 | }); | |
224 | } | |
225 | } | |
226 | ] | |
227 | }); | |
228 | ||
229 | me.callParent(); | |
230 | } | |
231 | }); | |
232 | ||
233 | ||
234 |