]>
Commit | Line | Data |
---|---|---|
9bbc1e4d DM |
1 | // fixme: howto avoid jslint type confusion? |
2 | /*jslint confusion: true */ | |
3 | Ext.define('PVE.qemu.CreateWizard', { | |
4 | extend: 'PVE.window.Wizard', | |
5 | ||
6 | initComponent: function() { | |
7 | var me = this; | |
8 | ||
9 | var summarystore = Ext.create('Ext.data.Store', { | |
10 | model: 'KeyValue', | |
11 | sorters: [ | |
12 | { | |
13 | property : 'key', | |
14 | direction: 'ASC' | |
15 | } | |
16 | ] | |
17 | }); | |
18 | ||
19 | var cdpanel = Ext.create('PVE.qemu.CDInputPanel', { | |
20 | title: gettext('CD/DVD'), | |
21 | confid: 'ide2', | |
22 | fieldDefaults: { | |
23 | labelWidth: 160 | |
24 | }, | |
25 | insideWizard: true | |
26 | }); | |
27 | ||
28 | var hdpanel = Ext.create('PVE.qemu.HDInputPanel', { | |
29 | title: gettext('Hard Disk'), | |
30 | create: true, | |
31 | insideWizard: true | |
32 | }); | |
33 | ||
34 | var networkpanel = Ext.create('PVE.qemu.NetworkInputPanel', { | |
35 | title: gettext('Network'), | |
36 | insideWizard: true | |
37 | }); | |
38 | ||
39 | Ext.applyIf(me, { | |
40 | subject: gettext('Virtual Machine'), | |
41 | items: [ | |
42 | { | |
43 | xtype: 'inputpanel', | |
44 | title: gettext('General'), | |
45 | column1: [ | |
46 | { | |
47 | xtype: 'PVE.form.NodeSelector', | |
48 | name: 'nodename', | |
49 | selectCurNode: true, | |
50 | fieldLabel: gettext('Node'), | |
51 | allowBlank: false, | |
52 | onlineValidator: true, | |
53 | listeners: { | |
54 | change: function(f, value) { | |
55 | networkpanel.setNodename(value); | |
56 | hdpanel.setNodename(value); | |
57 | cdpanel.setNodename(value); | |
58 | } | |
59 | } | |
60 | }, | |
61 | { | |
62 | xtype: 'pveVMIDSelector', | |
63 | name: 'vmid', | |
64 | value: '', | |
65 | loadNextFreeVMID: true, | |
66 | validateExists: false | |
67 | }, | |
68 | { | |
69 | xtype: 'textfield', | |
70 | name: 'name', | |
71 | vtype: 'DnsName', | |
72 | value: '', | |
73 | fieldLabel: gettext('Name'), | |
74 | allowBlank: true | |
75 | } | |
76 | ], | |
77 | column2: [ | |
78 | { | |
79 | xtype: 'pvePoolSelector', | |
80 | fieldLabel: gettext('Resource Pool'), | |
81 | name: 'pool', | |
82 | value: '', | |
83 | allowBlank: true | |
84 | } | |
85 | ], | |
86 | onGetValues: function(values) { | |
87 | if (!values.name) { | |
88 | delete values.name; | |
89 | } | |
90 | if (!values.pool) { | |
91 | delete values.pool; | |
92 | } | |
93 | return values; | |
94 | } | |
95 | }, | |
96 | { | |
97 | title: gettext('OS'), | |
98 | xtype: 'PVE.qemu.OSTypeInputPanel' | |
99 | }, | |
100 | cdpanel, | |
101 | hdpanel, | |
102 | { | |
103 | xtype: 'PVE.qemu.ProcessorInputPanel', | |
104 | title: gettext('CPU') | |
105 | }, | |
106 | { | |
107 | xtype: 'PVE.qemu.MemoryInputPanel', | |
108 | insideWizard: true, | |
109 | title: gettext('Memory') | |
110 | }, | |
111 | networkpanel, | |
112 | { | |
113 | title: gettext('Confirm'), | |
114 | layout: 'fit', | |
115 | items: [ | |
116 | { | |
117 | title: gettext('Settings'), | |
118 | xtype: 'grid', | |
119 | store: summarystore, | |
120 | columns: [ | |
121 | {header: 'Key', width: 150, dataIndex: 'key'}, | |
122 | {header: 'Value', flex: 1, dataIndex: 'value'} | |
123 | ] | |
124 | } | |
125 | ], | |
126 | listeners: { | |
127 | show: function(panel) { | |
128 | var form = me.down('form').getForm(); | |
129 | var kv = me.getValues(); | |
130 | var data = []; | |
131 | Ext.Object.each(kv, function(key, value) { | |
132 | if (key === 'delete') { // ignore | |
133 | return; | |
134 | } | |
135 | var html = Ext.htmlEncode(Ext.JSON.encode(value)); | |
136 | data.push({ key: key, value: value }); | |
137 | }); | |
138 | summarystore.suspendEvents(); | |
139 | summarystore.removeAll(); | |
140 | summarystore.add(data); | |
141 | summarystore.sort(); | |
142 | summarystore.resumeEvents(); | |
143 | summarystore.fireEvent('datachanged', summarystore); | |
144 | ||
145 | } | |
146 | }, | |
147 | onSubmit: function() { | |
148 | var kv = me.getValues(); | |
149 | delete kv['delete']; | |
150 | ||
151 | var nodename = kv.nodename; | |
152 | delete kv.nodename; | |
153 | ||
154 | PVE.Utils.API2Request({ | |
155 | url: '/nodes/' + nodename + '/qemu', | |
156 | waitMsgTarget: me, | |
157 | method: 'POST', | |
158 | params: kv, | |
159 | success: function(response){ | |
160 | me.close(); | |
161 | }, | |
162 | failure: function(response, opts) { | |
163 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
164 | } | |
165 | }); | |
166 | } | |
167 | } | |
168 | ] | |
169 | }); | |
170 | ||
171 | me.callParent(); | |
172 | } | |
173 | }); | |
174 | ||
175 | ||
176 | ||
177 |