]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/ha/GroupEdit.js
ui: Utils: use render functions from widget-toolkit
[pve-manager.git] / www / manager6 / ha / GroupEdit.js
CommitLineData
78fa6280 1Ext.define('PVE.ha.GroupInputPanel', {
ef4ef788 2 extend: 'Proxmox.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
d5e771ce 10 if (me.isCreate) {
78fa6280
DM
11 values.type = 'group';
12 }
13
14 return values;
15 },
16
8058410f 17 initComponent: function() {
78fa6280
DM
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);
f6710aac
TL
27 },
28 },
1a4667e6
TL
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', {
8058410f 35 fields: ['node', 'mem', 'cpu', 'priority'],
1a4667e6
TL
36 data: data,
37 proxy: {
38 type: 'memory',
8058410f 39 reader: { type: 'json' },
1a4667e6
TL
40 },
41 sorters: [
42 {
8058410f 43 property: 'node',
f6710aac
TL
44 direction: 'ASC',
45 },
46 ],
1a4667e6
TL
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,
f6710aac 58 dataIndex: 'node',
1a4667e6
TL
59 },
60 {
61 header: gettext('Memory usage') + " %",
62 renderer: PVE.Utils.render_mem_usage_percent,
63 sortable: true,
64 width: 150,
f6710aac 65 dataIndex: 'mem',
1a4667e6
TL
66 },
67 {
68 header: gettext('CPU usage'),
1bd7bcdb 69 renderer: Proxmox.Utils.render_cpu,
1a4667e6
TL
70 sortable: true,
71 width: 150,
f6710aac 72 dataIndex: 'cpu',
1a4667e6
TL
73 },
74 {
75 header: 'Priority',
76 xtype: 'widgetcolumn',
77 dataIndex: 'priority',
78 sortable: true,
79 stopSelection: true,
80 widget: {
bf96f60d 81 xtype: 'proxmoxintegerfield',
1a4667e6
TL
82 minValue: 0,
83 maxValue: 1000,
7471035d 84 isFormField: false,
1a4667e6
TL
85 listeners: {
86 change: function(numberfield, value, old_value) {
87 var record = numberfield.getWidgetRecord();
88 record.set('priority', value);
89 update_nodefield(sm.getSelection());
f6710aac
TL
90 },
91 },
92 },
93 },
94 ],
1a4667e6
TL
95 });
96
97 var nodefield = Ext.create('Ext.form.field.Hidden', {
98 name: 'nodes',
99 value: '',
100 listeners: {
8058410f 101 change: function(nodefield, value) {
1a4667e6 102 update_node_selection(value);
f6710aac 103 },
1a4667e6 104 },
8058410f 105 isValid: function() {
1a4667e6 106 var value = nodefield.getValue();
53e3ea84 107 return value && 0 !== value.length;
f6710aac 108 },
1a4667e6
TL
109 });
110
111 update_node_selection = function(string) {
112 sm.deselectAll(true);
113
8058410f 114 string.split(',').forEach(function(e, idx, array) {
1a4667e6
TL
115 var res = e.split(':');
116
117 store.each(function(record) {
118 var node = record.get('node');
119
120 if (node == res[0]) {
121 sm.select(record, true);
122 record.set('priority', res[1]);
123 record.commit();
124 }
125 });
126 });
127 nodegrid.reconfigure(store);
1a4667e6
TL
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 {
d5e771ce 154 xtype: me.isCreate ? 'textfield' : 'displayfield',
78fa6280 155 name: 'group',
78fa6280
DM
156 value: me.groupId || '',
157 fieldLabel: 'ID',
158 vtype: 'StorageId',
f6710aac 159 allowBlank: false,
78fa6280 160 },
f6710aac 161 nodefield,
78fa6280
DM
162 ];
163
164 me.column2 = [
165 {
896c0d50 166 xtype: 'proxmoxcheckbox',
78fa6280
DM
167 name: 'restricted',
168 uncheckedValue: 0,
f6710aac 169 fieldLabel: 'restricted',
78fa6280
DM
170 },
171 {
896c0d50 172 xtype: 'proxmoxcheckbox',
78fa6280
DM
173 name: 'nofailback',
174 uncheckedValue: 0,
f6710aac
TL
175 fieldLabel: 'nofailback',
176 },
78fa6280
DM
177 ];
178
179 me.columnB = [
180 {
181 xtype: 'textfield',
182 name: 'comment',
f6710aac 183 fieldLabel: gettext('Comment'),
1a4667e6 184 },
f6710aac 185 nodegrid,
78fa6280 186 ];
2a4971d8 187
78fa6280 188 me.callParent();
f6710aac 189 },
78fa6280
DM
190});
191
192Ext.define('PVE.ha.GroupEdit', {
9fccc702 193 extend: 'Proxmox.window.Edit',
78fa6280
DM
194
195 groupId: undefined,
196
8058410f 197 initComponent: function() {
78fa6280 198 var me = this;
2a4971d8 199
d5e771ce 200 me.isCreate = !me.groupId;
78fa6280 201
d5e771ce 202 if (me.isCreate) {
78fa6280
DM
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', {
d5e771ce 211 isCreate: me.isCreate,
f6710aac 212 groupId: me.groupId,
78fa6280
DM
213 });
214
215 Ext.apply(me, {
216 subject: gettext('HA Group'),
8058410f 217 items: [ipanel],
78fa6280 218 });
2a4971d8 219
78fa6280
DM
220 me.callParent();
221
d5e771ce 222 if (!me.isCreate) {
78fa6280 223 me.load({
8058410f 224 success: function(response, options) {
78fa6280
DM
225 var values = response.result.data;
226
78fa6280 227 ipanel.setValues(values);
f6710aac 228 },
78fa6280
DM
229 });
230 }
f6710aac 231 },
78fa6280 232});