]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/CreateWizard.js
make the lxc wizard select the current node by default
[pve-manager.git] / www / manager6 / lxc / CreateWizard.js
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: 'pveNodeSelector',
62 name: 'nodename',
63 selectCurNode: true,
64 fieldLabel: gettext('Node'),
65 allowBlank: false,
66 onlineValidator: true,
67 listeners: {
68 change: function(f, value) {
69 tmplstoragesel.setNodename(value);
70 tmplsel.setStorage(undefined, value);
71 networkpanel.setNodename(value);
72 rootfspanel.setNodename(value);
73 }
74 }
75 },
76 {
77 xtype: 'pveVMIDSelector',
78 name: 'vmid',
79 value: '',
80 loadNextFreeVMID: true,
81 validateExists: false
82 },
83 {
84 xtype: 'pvetextfield',
85 name: 'hostname',
86 vtype: 'DnsName',
87 value: '',
88 fieldLabel: gettext('Hostname'),
89 skipEmptyText: true,
90 allowBlank: true
91 }
92 ],
93 column2: [
94 {
95 xtype: 'pvePoolSelector',
96 fieldLabel: gettext('Resource Pool'),
97 name: 'pool',
98 value: '',
99 allowBlank: true
100 },
101 {
102 xtype: 'textfield',
103 inputType: 'password',
104 name: 'password',
105 value: '',
106 fieldLabel: gettext('Password'),
107 allowBlank: false,
108 minLength: 5,
109 change: function(f, value) {
110 if (!me.rendered) {
111 return;
112 }
113 me.down('field[name=confirmpw]').validate();
114 }
115 },
116 {
117 xtype: 'textfield',
118 inputType: 'password',
119 name: 'confirmpw',
120 value: '',
121 fieldLabel: gettext('Confirm password'),
122 allowBlank: false,
123 validator: function(value) {
124 var pw = me.down('field[name=password]').getValue();
125 if (pw !== value) {
126 return "Passwords does not match!";
127 }
128 return true;
129 }
130 }
131 ],
132 onGetValues: function(values) {
133 delete values.confirmpw;
134 if (!values.pool) {
135 delete values.pool;
136 }
137 return values;
138 }
139 },
140 {
141 xtype: 'inputpanel',
142 title: gettext('Template'),
143 column1: [ tmplstoragesel, tmplsel]
144 },
145 rootfspanel,
146 {
147 xtype: 'pveLxcCPUInputPanel',
148 title: gettext('CPU'),
149 insideWizard: true
150 },
151 {
152 xtype: 'pveLxcMemoryInputPanel',
153 title: gettext('Memory'),
154 insideWizard: true
155 },
156 networkpanel,
157 {
158 xtype: 'pveLxcDNSInputPanel',
159 title: gettext('DNS'),
160 insideWizard: true
161 },
162 {
163 title: gettext('Confirm'),
164 layout: 'fit',
165 items: [
166 {
167 title: gettext('Settings'),
168 xtype: 'grid',
169 store: summarystore,
170 columns: [
171 {header: 'Key', width: 150, dataIndex: 'key'},
172 {header: 'Value', flex: 1, dataIndex: 'value'}
173 ]
174 }
175 ],
176 listeners: {
177 show: function(panel) {
178 var form = me.down('form').getForm();
179 var kv = me.getValues();
180 var data = [];
181 Ext.Object.each(kv, function(key, value) {
182 if (key === 'delete' || key === 'tmplstorage') { // ignore
183 return;
184 }
185 if (key === 'password') { // don't show pw
186 return;
187 }
188 var html = Ext.htmlEncode(Ext.JSON.encode(value));
189 data.push({ key: key, value: value });
190 });
191 summarystore.suspendEvents();
192 summarystore.removeAll();
193 summarystore.add(data);
194 summarystore.sort();
195 summarystore.resumeEvents();
196 summarystore.fireEvent('datachanged', summarystore);
197 }
198 },
199 onSubmit: function() {
200 var kv = me.getValues();
201 delete kv['delete'];
202
203 var nodename = kv.nodename;
204 delete kv.nodename;
205 delete kv.tmplstorage;
206
207 PVE.Utils.API2Request({
208 url: '/nodes/' + nodename + '/lxc',
209 waitMsgTarget: me,
210 method: 'POST',
211 params: kv,
212 success: function(response, opts){
213 var upid = response.result.data;
214
215 var win = Ext.create('PVE.window.TaskViewer', {
216 upid: upid
217 });
218 win.show();
219 me.close();
220 },
221 failure: function(response, opts) {
222 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
223 }
224 });
225 }
226 }
227 ]
228 });
229
230 me.callParent();
231 }
232 });
233
234
235