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