]>
Commit | Line | Data |
---|---|---|
e5bb8722 DM |
1 | Ext.define('PVE.qemu.MemoryInputPanel', { |
2 | extend: 'PVE.panel.InputPanel', | |
42902182 | 3 | alias: 'widget.pveQemuMemoryPanel', |
c8802a60 | 4 | onlineHelp: 'qm_memory', |
e5bb8722 DM |
5 | |
6 | insideWizard: false, | |
7 | ||
8 | onGetValues: function(values) { | |
9 | var me = this; | |
10 | ||
11 | var res; | |
12 | ||
13 | if (values.memoryType === 'fixed') { | |
14 | res = { memory: values.memory }; | |
9a60a19b DC |
15 | if (values.ballooning === '1') { |
16 | // if balloning is active if it is not explicitely set | |
17 | res['delete'] = "balloon,shares"; | |
18 | } else { | |
19 | res['delete'] = "shares"; | |
20 | res.balloon = 0; | |
21 | } | |
e5bb8722 DM |
22 | } else { |
23 | res = { | |
24 | memory: values.maxmemory, | |
25 | balloon: values.balloon | |
26 | }; | |
27 | if (Ext.isDefined(values.shares) && (values.shares !== "")) { | |
28 | res.shares = values.shares; | |
29 | } else { | |
30 | res['delete'] = "shares"; | |
31 | } | |
32 | } | |
33 | ||
34 | return res; | |
35 | }, | |
36 | ||
37 | initComponent : function() { | |
38 | var me = this; | |
39 | var labelWidth = 160; | |
40 | ||
41 | var items = [ | |
42 | { | |
43 | xtype: 'radiofield', | |
44 | name: 'memoryType', | |
45 | inputValue: 'fixed', | |
46 | boxLabel: gettext('Use fixed size memory'), | |
47 | checked: true, | |
48 | listeners: { | |
49 | change: function(f, value) { | |
50 | if (!me.rendered) { | |
51 | return; | |
52 | } | |
53 | me.down('field[name=memory]').setDisabled(!value); | |
9a60a19b | 54 | me.down('field[name=ballooning]').setDisabled(!value); |
e5bb8722 DM |
55 | me.down('field[name=maxmemory]').setDisabled(value); |
56 | me.down('field[name=balloon]').setDisabled(value); | |
57 | me.down('field[name=shares]').setDisabled(value); | |
58 | } | |
59 | } | |
60 | }, | |
61 | { | |
62 | xtype: 'pveMemoryField', | |
63 | name: 'memory', | |
64 | hotplug: me.hotplug, | |
65 | fieldLabel: gettext('Memory') + ' (MB)', | |
66 | labelAlign: 'right', | |
22f2f9d6 | 67 | labelWidth: labelWidth |
e5bb8722 | 68 | }, |
9a60a19b | 69 | { |
896c0d50 | 70 | xtype: 'proxmoxcheckbox', |
9a60a19b DC |
71 | hotplug: me.hotplug, |
72 | name: 'ballooning', | |
73 | value: '1', | |
74 | labelAlign: 'right', | |
75 | labelWidth: labelWidth, | |
76 | fieldLabel: gettext('Ballooning') | |
77 | }, | |
e5bb8722 DM |
78 | { |
79 | xtype: 'radiofield', | |
80 | name: 'memoryType', | |
81 | inputValue: 'dynamic', | |
82 | boxLabel: gettext('Automatically allocate memory within this range'), | |
83 | listeners: { | |
84 | change: function(f, value) { | |
85 | if (!me.rendered) { | |
86 | return; | |
87 | } | |
88 | } | |
89 | } | |
90 | }, | |
91 | { | |
92 | xtype: 'pveMemoryField', | |
93 | name: 'maxmemory', | |
94 | hotplug: me.hotplug, | |
95 | disabled: true, | |
96 | value: '1024', | |
97 | fieldLabel: gettext('Maximum memory') + ' (MB)', | |
98 | labelAlign: 'right', | |
99 | labelWidth: labelWidth, | |
100 | listeners: { | |
101 | change: function(f, value) { | |
102 | var bf = me.down('field[name=balloon]'); | |
103 | var balloon = bf.getValue(); | |
104 | if (balloon > value) { | |
105 | bf.setValue(value); | |
106 | } | |
107 | bf.setMaxValue(value); | |
108 | } | |
109 | } | |
110 | }, | |
111 | { | |
bf96f60d | 112 | xtype: 'proxmoxintegerfield', |
e5bb8722 DM |
113 | name: 'balloon', |
114 | disabled: true, | |
115 | minValue: 0, | |
116 | maxValue: 512*1024, | |
117 | value: '512', | |
118 | step: 32, | |
119 | fieldLabel: gettext('Minimum memory') + ' (MB)', | |
120 | labelAlign: 'right', | |
121 | labelWidth: labelWidth, | |
122 | allowBlank: false | |
123 | }, | |
124 | { | |
bf96f60d | 125 | xtype: 'proxmoxintegerfield', |
e5bb8722 DM |
126 | name: 'shares', |
127 | disabled: true, | |
128 | minValue: 0, | |
129 | maxValue: 50000, | |
130 | value: '', | |
131 | step: 10, | |
132 | fieldLabel: gettext('Shares'), | |
133 | labelAlign: 'right', | |
134 | labelWidth: labelWidth, | |
135 | allowBlank: true, | |
e7ade592 | 136 | emptyText: Proxmox.Utils.defaultText + ' (1000)', |
e5bb8722 | 137 | submitEmptyText: false |
22f2f9d6 | 138 | } |
e5bb8722 DM |
139 | ]; |
140 | ||
141 | if (me.insideWizard) { | |
142 | me.column1 = items; | |
143 | } else { | |
144 | me.items = items; | |
145 | } | |
146 | ||
147 | me.callParent(); | |
148 | } | |
149 | }); | |
150 | ||
151 | Ext.define('PVE.qemu.MemoryEdit', { | |
152 | extend: 'PVE.window.Edit', | |
153 | ||
154 | initComponent : function() { | |
155 | var me = this; | |
156 | ||
157 | var memoryhotplug; | |
158 | if(me.hotplug) { | |
159 | Ext.each(me.hotplug.split(','), function(el) { | |
160 | if (el === 'memory') { | |
161 | memoryhotplug = 1; | |
162 | } | |
163 | }); | |
164 | } | |
165 | ||
166 | var ipanel = Ext.create('PVE.qemu.MemoryInputPanel', { | |
22f2f9d6 | 167 | hotplug: memoryhotplug |
e5bb8722 DM |
168 | }); |
169 | ||
170 | Ext.apply(me, { | |
171 | subject: gettext('Memory'), | |
ec0bd652 | 172 | items: [ ipanel ], |
e5bb8722 DM |
173 | // uncomment the following to use the async configiguration API |
174 | // backgroundDelay: 5, | |
175 | width: 400 | |
176 | }); | |
177 | ||
178 | me.callParent(); | |
179 | ||
180 | me.load({ | |
181 | success: function(response, options) { | |
182 | var data = response.result.data; | |
183 | ||
184 | var values = { | |
185 | memory: data.memory, | |
186 | maxmemory: data.memory, | |
187 | balloon: data.balloon, | |
9a60a19b | 188 | ballooning: data.balloon === 0 ? '0' : '1', |
e5bb8722 | 189 | shares: data.shares, |
22f2f9d6 | 190 | memoryType: data.balloon ? 'dynamic' : 'fixed' |
e5bb8722 DM |
191 | }; |
192 | ipanel.setValues(values); | |
193 | } | |
194 | }); | |
195 | } | |
196 | }); |