]> git.proxmox.com Git - pve-manager-legacy.git/blame - www/manager6/ha/GroupEdit.js
ui: enable gettext localisation for more user exposed strings
[pve-manager-legacy.git] / www / manager6 / ha / GroupEdit.js
CommitLineData
37b5b066 1Ext.define('PVE.ha.GroupInputPanel', {
c3a1166e 2 extend: 'Proxmox.panel.InputPanel',
2963616a 3 onlineHelp: 'ha_manager_groups',
37b5b066
DM
4
5 groupId: undefined,
1cea646d 6
37b5b066
DM
7 onGetValues: function(values) {
8 var me = this;
9
9af71828 10 if (me.isCreate) {
37b5b066
DM
11 values.type = 'group';
12 }
13
14 return values;
15 },
16
8b520a2b 17 initComponent: function() {
37b5b066
DM
18 var me = this;
19
2cc5cb2f 20 let update_nodefield, update_node_selection;
bd5d4d9d 21
2cc5cb2f 22 let sm = Ext.create('Ext.selection.CheckboxModel', {
bd5d4d9d
TL
23 mode: 'SIMPLE',
24 listeners: {
25 selectionchange: function(model, selected) {
26 update_nodefield(selected);
9beb4751
TL
27 },
28 },
bd5d4d9d
TL
29 });
30
2cc5cb2f 31 let store = Ext.create('Ext.data.Store', {
8b520a2b 32 fields: ['node', 'mem', 'cpu', 'priority'],
2cc5cb2f 33 data: PVE.data.ResourceStore.getNodes(), // use already cached data to avoid an API call
bd5d4d9d
TL
34 proxy: {
35 type: 'memory',
8b520a2b 36 reader: { type: 'json' },
bd5d4d9d
TL
37 },
38 sorters: [
39 {
8b520a2b 40 property: 'node',
9beb4751
TL
41 direction: 'ASC',
42 },
43 ],
bd5d4d9d
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,
9beb4751 55 dataIndex: 'node',
bd5d4d9d
TL
56 },
57 {
58 header: gettext('Memory usage') + " %",
59 renderer: PVE.Utils.render_mem_usage_percent,
60 sortable: true,
61 width: 150,
9beb4751 62 dataIndex: 'mem',
bd5d4d9d
TL
63 },
64 {
65 header: gettext('CPU usage'),
c2235410 66 renderer: Proxmox.Utils.render_cpu,
bd5d4d9d
TL
67 sortable: true,
68 width: 150,
9beb4751 69 dataIndex: 'cpu',
bd5d4d9d
TL
70 },
71 {
f8fe74da 72 header: gettext('Priority'),
bd5d4d9d
TL
73 xtype: 'widgetcolumn',
74 dataIndex: 'priority',
75 sortable: true,
76 stopSelection: true,
77 widget: {
9fcbafbe 78 xtype: 'proxmoxintegerfield',
bd5d4d9d
TL
79 minValue: 0,
80 maxValue: 1000,
f7cd9347 81 isFormField: false,
bd5d4d9d
TL
82 listeners: {
83 change: function(numberfield, value, old_value) {
2cc5cb2f 84 let record = numberfield.getWidgetRecord();
bd5d4d9d
TL
85 record.set('priority', value);
86 update_nodefield(sm.getSelection());
2cc5cb2f 87 record.commit();
9beb4751
TL
88 },
89 },
90 },
91 },
92 ],
bd5d4d9d
TL
93 });
94
2cc5cb2f 95 let nodefield = Ext.create('Ext.form.field.Hidden', {
bd5d4d9d
TL
96 name: 'nodes',
97 value: '',
98 listeners: {
2cc5cb2f 99 change: function(field, value) {
bd5d4d9d 100 update_node_selection(value);
9beb4751 101 },
bd5d4d9d 102 },
8b520a2b 103 isValid: function() {
2cc5cb2f 104 let value = this.getValue();
f56649b7 105 return value && value.length !== 0;
9beb4751 106 },
bd5d4d9d
TL
107 });
108
109 update_node_selection = function(string) {
110 sm.deselectAll(true);
111
8b520a2b 112 string.split(',').forEach(function(e, idx, array) {
2cc5cb2f 113 let [node, priority] = e.split(':');
bd5d4d9d 114 store.each(function(record) {
2cc5cb2f 115 if (record.get('node') === node) {
bd5d4d9d 116 sm.select(record, true);
2cc5cb2f 117 record.set('priority', priority);
bd5d4d9d
TL
118 record.commit();
119 }
120 });
121 });
122 nodegrid.reconfigure(store);
bd5d4d9d
TL
123 };
124
125 update_nodefield = function(selected) {
f906b38b
TL
126 let nodes = selected
127 .map(({ data }) => data.node + (data.priority ? `:${data.priority}` : ''))
128 .join(',');
bd5d4d9d
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
37b5b066
DM
137 me.column1 = [
138 {
9af71828 139 xtype: me.isCreate ? 'textfield' : 'displayfield',
37b5b066 140 name: 'group',
37b5b066
DM
141 value: me.groupId || '',
142 fieldLabel: 'ID',
143 vtype: 'StorageId',
9beb4751 144 allowBlank: false,
37b5b066 145 },
9beb4751 146 nodefield,
37b5b066
DM
147 ];
148
149 me.column2 = [
150 {
956cd0bd 151 xtype: 'proxmoxcheckbox',
37b5b066
DM
152 name: 'restricted',
153 uncheckedValue: 0,
9beb4751 154 fieldLabel: 'restricted',
37b5b066
DM
155 },
156 {
956cd0bd 157 xtype: 'proxmoxcheckbox',
37b5b066
DM
158 name: 'nofailback',
159 uncheckedValue: 0,
9beb4751
TL
160 fieldLabel: 'nofailback',
161 },
37b5b066
DM
162 ];
163
164 me.columnB = [
165 {
166 xtype: 'textfield',
167 name: 'comment',
9beb4751 168 fieldLabel: gettext('Comment'),
bd5d4d9d 169 },
9beb4751 170 nodegrid,
37b5b066 171 ];
925ef9da 172
37b5b066 173 me.callParent();
9beb4751 174 },
37b5b066
DM
175});
176
177Ext.define('PVE.ha.GroupEdit', {
0d173d3e 178 extend: 'Proxmox.window.Edit',
37b5b066
DM
179
180 groupId: undefined,
181
8b520a2b 182 initComponent: function() {
37b5b066 183 var me = this;
925ef9da 184
9af71828 185 me.isCreate = !me.groupId;
37b5b066 186
9af71828 187 if (me.isCreate) {
37b5b066
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', {
9af71828 196 isCreate: me.isCreate,
9beb4751 197 groupId: me.groupId,
37b5b066
DM
198 });
199
200 Ext.apply(me, {
201 subject: gettext('HA Group'),
8b520a2b 202 items: [ipanel],
37b5b066 203 });
925ef9da 204
37b5b066
DM
205 me.callParent();
206
9af71828 207 if (!me.isCreate) {
37b5b066 208 me.load({
8b520a2b 209 success: function(response, options) {
37b5b066
DM
210 var values = response.result.data;
211
37b5b066 212 ipanel.setValues(values);
9beb4751 213 },
37b5b066
DM
214 });
215 }
9beb4751 216 },
37b5b066 217});