]>
Commit | Line | Data |
---|---|---|
78fa6280 DM |
1 | Ext.define('PVE.ha.GroupInputPanel', { |
2 | extend: 'PVE.panel.InputPanel', | |
c8802a60 | 3 | onlineHelp: 'ha_manager_groups', |
78fa6280 DM |
4 | |
5 | groupId: undefined, | |
2c195fdd | 6 | |
78fa6280 DM |
7 | onGetValues: function(values) { |
8 | var me = this; | |
9 | ||
10 | if (me.create) { | |
11 | values.type = 'group'; | |
12 | } | |
13 | ||
14 | return values; | |
15 | }, | |
16 | ||
17 | initComponent : function() { | |
18 | var me = this; | |
19 | ||
1a4667e6 TL |
20 | var update_nodefield, update_node_selection; |
21 | ||
22 | var sm = Ext.create('Ext.selection.CheckboxModel', { | |
23 | mode: 'SIMPLE', | |
24 | listeners: { | |
25 | selectionchange: function(model, selected) { | |
26 | update_nodefield(selected); | |
27 | } | |
28 | } | |
29 | }); | |
30 | ||
31 | // use already cached data to avoid an API call | |
32 | var data = PVE.data.ResourceStore.getNodes(); | |
33 | ||
34 | var store = Ext.create('Ext.data.Store', { | |
35 | fields: [ 'node', 'mem', 'cpu', 'priority' ], | |
36 | data: data, | |
37 | proxy: { | |
38 | type: 'memory', | |
39 | reader: {type: 'json'} | |
40 | }, | |
41 | sorters: [ | |
42 | { | |
43 | property : 'node', | |
44 | direction: 'ASC' | |
45 | } | |
46 | ] | |
47 | }); | |
48 | ||
49 | var nodegrid = Ext.createWidget('grid', { | |
50 | store: store, | |
51 | border: true, | |
52 | height: 300, | |
53 | selModel: sm, | |
54 | columns: [ | |
55 | { | |
56 | header: gettext('Node'), | |
57 | flex: 1, | |
58 | dataIndex: 'node' | |
59 | }, | |
60 | { | |
61 | header: gettext('Memory usage') + " %", | |
62 | renderer: PVE.Utils.render_mem_usage_percent, | |
63 | sortable: true, | |
64 | width: 150, | |
65 | dataIndex: 'mem' | |
66 | }, | |
67 | { | |
68 | header: gettext('CPU usage'), | |
69 | renderer: PVE.Utils.render_cpu, | |
70 | sortable: true, | |
71 | width: 150, | |
72 | dataIndex: 'cpu' | |
73 | }, | |
74 | { | |
75 | header: 'Priority', | |
76 | xtype: 'widgetcolumn', | |
77 | dataIndex: 'priority', | |
78 | sortable: true, | |
79 | stopSelection: true, | |
80 | widget: { | |
8a7e5598 | 81 | xtype: 'pveIntegerField', |
1a4667e6 TL |
82 | minValue: 0, |
83 | maxValue: 1000, | |
84 | listeners: { | |
85 | change: function(numberfield, value, old_value) { | |
86 | var record = numberfield.getWidgetRecord(); | |
87 | record.set('priority', value); | |
88 | update_nodefield(sm.getSelection()); | |
89 | } | |
90 | } | |
91 | } | |
92 | } | |
93 | ] | |
94 | }); | |
95 | ||
96 | var nodefield = Ext.create('Ext.form.field.Hidden', { | |
97 | name: 'nodes', | |
98 | value: '', | |
99 | listeners: { | |
100 | change: function (nodefield, value) { | |
101 | update_node_selection(value); | |
102 | } | |
103 | }, | |
104 | isValid: function () { | |
105 | var value = nodefield.getValue(); | |
106 | return (value && 0 !== value.length); | |
107 | } | |
108 | }); | |
109 | ||
110 | update_node_selection = function(string) { | |
111 | sm.deselectAll(true); | |
112 | ||
113 | string.split(',').forEach(function (e, idx, array) { | |
114 | var res = e.split(':'); | |
115 | ||
116 | store.each(function(record) { | |
117 | var node = record.get('node'); | |
118 | ||
119 | if (node == res[0]) { | |
120 | sm.select(record, true); | |
121 | record.set('priority', res[1]); | |
122 | record.commit(); | |
123 | } | |
124 | }); | |
125 | }); | |
126 | nodegrid.reconfigure(store); | |
127 | ||
128 | }; | |
129 | ||
130 | update_nodefield = function(selected) { | |
131 | var nodes = ''; | |
132 | var first_iteration = true; | |
133 | Ext.Array.each(selected, function(record) { | |
134 | if (!first_iteration) { | |
135 | nodes += ','; | |
136 | } | |
137 | first_iteration = false; | |
138 | ||
139 | nodes += record.data.node; | |
140 | if (record.data.priority) { | |
141 | nodes += ':' + record.data.priority; | |
142 | } | |
143 | }); | |
144 | ||
145 | // nodefield change listener calls us again, which results in a | |
146 | // endless recursion, suspend the event temporary to avoid this | |
147 | nodefield.suspendEvent('change'); | |
148 | nodefield.setValue(nodes); | |
149 | nodefield.resumeEvent('change'); | |
150 | }; | |
151 | ||
78fa6280 DM |
152 | me.column1 = [ |
153 | { | |
154 | xtype: me.create ? 'textfield' : 'displayfield', | |
155 | name: 'group', | |
78fa6280 DM |
156 | value: me.groupId || '', |
157 | fieldLabel: 'ID', | |
158 | vtype: 'StorageId', | |
159 | allowBlank: false | |
160 | }, | |
1a4667e6 | 161 | nodefield |
78fa6280 DM |
162 | ]; |
163 | ||
164 | me.column2 = [ | |
165 | { | |
166 | xtype: 'pvecheckbox', | |
167 | name: 'restricted', | |
168 | uncheckedValue: 0, | |
185a77e5 | 169 | fieldLabel: 'restricted' |
78fa6280 DM |
170 | }, |
171 | { | |
172 | xtype: 'pvecheckbox', | |
173 | name: 'nofailback', | |
174 | uncheckedValue: 0, | |
185a77e5 | 175 | fieldLabel: 'nofailback' |
22f2f9d6 | 176 | } |
78fa6280 DM |
177 | ]; |
178 | ||
179 | me.columnB = [ | |
180 | { | |
181 | xtype: 'textfield', | |
182 | name: 'comment', | |
183 | fieldLabel: gettext('Comment') | |
1a4667e6 TL |
184 | }, |
185 | nodegrid | |
78fa6280 DM |
186 | ]; |
187 | ||
188 | me.callParent(); | |
189 | } | |
190 | }); | |
191 | ||
192 | Ext.define('PVE.ha.GroupEdit', { | |
193 | extend: 'PVE.window.Edit', | |
194 | ||
195 | groupId: undefined, | |
196 | ||
197 | initComponent : function() { | |
198 | var me = this; | |
199 | ||
200 | me.create = !me.groupId; | |
201 | ||
202 | if (me.create) { | |
203 | me.url = '/api2/extjs/cluster/ha/groups'; | |
204 | me.method = 'POST'; | |
205 | } else { | |
206 | me.url = '/api2/extjs/cluster/ha/groups/' + me.groupId; | |
207 | me.method = 'PUT'; | |
208 | } | |
209 | ||
210 | var ipanel = Ext.create('PVE.ha.GroupInputPanel', { | |
211 | create: me.create, | |
212 | groupId: me.groupId | |
213 | }); | |
214 | ||
215 | Ext.apply(me, { | |
216 | subject: gettext('HA Group'), | |
217 | items: [ ipanel ] | |
218 | }); | |
219 | ||
220 | me.callParent(); | |
221 | ||
222 | if (!me.create) { | |
223 | me.load({ | |
224 | success: function(response, options) { | |
225 | var values = response.result.data; | |
226 | ||
78fa6280 DM |
227 | ipanel.setValues(values); |
228 | } | |
229 | }); | |
230 | } | |
231 | } | |
232 | }); |