]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/window/Settings.js
ui: window/FW Log Rate: eslint fixes and code cleanup/refactoring/modernize
[pve-manager.git] / www / manager6 / window / Settings.js
CommitLineData
ce11a8af
DC
1Ext.define('PVE.window.Settings', {
2 extend: 'Ext.window.Window',
3
d9ace13c 4 width: '800px',
ce11a8af
DC
5 title: gettext('My Settings'),
6 iconCls: 'fa fa-gear',
7 modal: true,
8 bodyPadding: 10,
9 resizable: false,
10
75ceae78
DL
11 buttons: [
12 {
13 xtype: 'proxmoxHelpButton',
14 onlineHelp: 'gui_my_settings',
f6710aac 15 hidden: false,
75ceae78
DL
16 },
17 '->',
18 {
19 text: gettext('Close'),
20 handler: function() {
21 this.up('window').close();
f6710aac
TL
22 },
23 },
75ceae78 24 ],
ce11a8af 25
d27a44a6 26 layout: 'hbox',
ce11a8af
DC
27
28 controller: {
29 xclass: 'Ext.app.ViewController',
30
d9ace13c
DC
31 init: function(view) {
32 var me = this;
33 var sp = Ext.state.Manager.getProvider();
34
35 var username = sp.get('login-username') || Proxmox.Utils.noneText;
1011b569 36 me.lookupReference('savedUserName').setValue(Ext.String.htmlEncode(username));
26fcae33
DJ
37 var vncMode = sp.get('novnc-scaling');
38 if (vncMode !== undefined) {
f5c68a74 39 me.lookupReference('noVNCScalingGroup').setValue({ noVNCScalingField: vncMode });
26fcae33 40 }
d9ace13c 41
6b6cd0e4
TL
42 let summarycolumns = sp.get('summarycolumns', 'auto');
43 me.lookup('summarycolumns').setValue(summarycolumns);
f973c5b2 44
300c0f73
TL
45 me.lookup('guestNotesCollapse').setValue(sp.get('guest-notes-collapse', 'never'));
46
d9ace13c 47 var settings = ['fontSize', 'fontFamily', 'letterSpacing', 'lineHeight'];
d9ace13c
DC
48 settings.forEach(function(setting) {
49 var val = localStorage.getItem('pve-xterm-' + setting);
50 if (val !== undefined && val !== null) {
51 var field = me.lookup(setting);
52 field.setValue(val);
2b0bdc46 53 field.resetOriginalValue();
d9ace13c
DC
54 }
55 });
2b0bdc46
DC
56 },
57
58 set_button_status: function() {
59 var me = this;
60
61 var form = me.lookup('xtermform');
62 var valid = form.isValid();
63 var dirty = form.isDirty();
d9ace13c 64
2b0bdc46
DC
65 var hasvalues = false;
66 var values = form.getValues();
67 Ext.Object.eachValue(values, function(value) {
68 if (value) {
69 hasvalues = true;
70 return false;
71 }
72 });
73
74 me.lookup('xtermsave').setDisabled(!dirty || !valid);
75 me.lookup('xtermreset').setDisabled(!hasvalues);
d9ace13c
DC
76 },
77
ce11a8af 78 control: {
2b0bdc46
DC
79 '#xtermjs form': {
80 dirtychange: 'set_button_status',
f6710aac 81 validitychange: 'set_button_status',
d9ace13c
DC
82 },
83 '#xtermjs button': {
84 click: function(button) {
85 var me = this;
86 var settings = ['fontSize', 'fontFamily', 'letterSpacing', 'lineHeight'];
87 settings.forEach(function(setting) {
88 var field = me.lookup(setting);
89 if (button.reference === 'xtermsave') {
90 var value = field.getValue();
91 if (value) {
92 localStorage.setItem('pve-xterm-' + setting, value);
93 } else {
94 localStorage.removeItem('pve-xterm-' + setting);
95 }
96 } else if (button.reference === 'xtermreset') {
97 field.setValue(undefined);
98 localStorage.removeItem('pve-xterm-' + setting);
99 }
2b0bdc46 100 field.resetOriginalValue();
d9ace13c 101 });
2b0bdc46 102 me.set_button_status();
f6710aac 103 },
ce11a8af
DC
104 },
105 'button[name=reset]': {
8058410f 106 click: function() {
2488c226 107 var blacklist = ['GuiCap', 'login-username', 'dash-storages'];
ce11a8af
DC
108 var sp = Ext.state.Manager.getProvider();
109 var state;
110 for (state in sp.state) {
111 if (sp.state.hasOwnProperty(state)) {
112 if (blacklist.indexOf(state) !== -1) {
113 continue;
114 }
115
116 sp.clear(state);
117 }
118 }
119
120 window.location.reload();
f6710aac 121 },
ce11a8af
DC
122 },
123 'button[name=clear-username]': {
8058410f 124 click: function() {
ce11a8af
DC
125 var me = this;
126 var usernamefield = me.lookupReference('savedUserName');
127 var sp = Ext.state.Manager.getProvider();
128
e7ade592 129 usernamefield.setValue(Proxmox.Utils.noneText);
ce11a8af 130 sp.clear('login-username');
f6710aac 131 },
2488c226
DC
132 },
133 'grid[reference=dashboard-storages]': {
134 selectionchange: function(grid, selected) {
135 var me = this;
136 var sp = Ext.state.Manager.getProvider();
137
138 // saves the selected storageids as
139 // "id1,id2,id3,..."
140 // or clears the variable
141 if (selected.length > 0) {
142 sp.set('dash-storages',
143 Ext.Array.pluck(selected, 'id').join(','));
144 } else {
145 sp.clear('dash-storages');
146 }
147 },
148 afterrender: function(grid) {
149 var me = grid;
150 var sp = Ext.state.Manager.getProvider();
151 var store = me.getStore();
152 var items = [];
153 me.suspendEvent('selectionchange');
154 var storages = sp.get('dash-storages') || '';
8058410f 155 storages.split(',').forEach(function(storage) {
2488c226
DC
156 // we have to get the records
157 // to be able to select them
158 if (storage !== '') {
159 var item = store.getById(storage);
160 if (item) {
161 items.push(item);
162 }
163 }
164 });
165 me.getSelectionModel().select(items);
166 me.resumeEvent('selectionchange');
f6710aac 167 },
f973c5b2
DC
168 },
169 'field[reference=summarycolumns]': {
170 change: function(el, newValue) {
171 var sp = Ext.state.Manager.getProvider();
172 sp.set('summarycolumns', newValue);
f6710aac 173 },
300c0f73
TL
174 },
175 'field[reference=guestNotesCollapse]': {
176 change: function(e, v) {
177 Ext.state.Manager.getProvider().set('guest-notes-collapse', v);
178 },
179 },
f6710aac 180 },
ce11a8af
DC
181 },
182
183 items: [{
26fcae33 184 xtype: 'fieldset',
d27a44a6 185 flex: 1,
26fcae33
DJ
186 title: gettext('Webinterface Settings'),
187 margin: '5',
188 layout: {
189 type: 'vbox',
f6710aac 190 align: 'left',
26fcae33
DJ
191 },
192 defaults: {
193 width: '100%',
f6710aac 194 margin: '0 0 10 0',
26fcae33
DJ
195 },
196 items: [
197 {
198 xtype: 'displayfield',
199 fieldLabel: gettext('Dashboard Storages'),
200 labelAlign: 'left',
f6710aac 201 labelWidth: '50%',
ce11a8af 202 },
26fcae33
DJ
203 {
204 xtype: 'grid',
205 maxHeight: 150,
206 reference: 'dashboard-storages',
207 selModel: {
f6710aac 208 selType: 'checkboxmodel',
2488c226 209 },
26fcae33
DJ
210 columns: [{
211 header: gettext('Name'),
212 dataIndex: 'storage',
f6710aac
TL
213 flex: 1,
214 }, {
26fcae33
DJ
215 header: gettext('Node'),
216 dataIndex: 'node',
f6710aac 217 flex: 1,
26fcae33
DJ
218 }],
219 store: {
220 type: 'diff',
221 field: ['type', 'storage', 'id', 'node'],
222 rstore: PVE.data.ResourceStore,
223 filters: [{
224 property: 'type',
f6710aac 225 value: 'storage',
2488c226 226 }],
8058410f 227 sorters: ['node', 'storage'],
f6710aac 228 },
26fcae33
DJ
229 },
230 {
231 xtype: 'box',
8058410f 232 autoEl: { tag: 'hr' },
26fcae33
DJ
233 },
234 {
bd7aef86 235 xtype: 'container',
8058410f 236 layout: 'hbox',
bd7aef86
DJ
237 items: [
238 {
239 xtype: 'displayfield',
94666c47 240 fieldLabel: gettext('Saved User Name') + ':',
ad8b37fa 241 labelWidth: 150,
bd7aef86
DJ
242 stateId: 'login-username',
243 reference: 'savedUserName',
244 flex: 1,
f6710aac 245 value: '',
bd7aef86
DJ
246 },
247 {
248 xtype: 'button',
249 cls: 'x-btn-default-toolbar-small proxmox-inline-button',
250 text: gettext('Reset'),
251 name: 'clear-username',
252 },
f6710aac 253 ],
26fcae33
DJ
254 },
255 {
256 xtype: 'box',
8058410f 257 autoEl: { tag: 'hr' },
26fcae33
DJ
258 },
259 {
bd7aef86
DJ
260 xtype: 'container',
261 layout: 'hbox',
9a08bd8a
TL
262 items: [
263 {
264 xtype: 'displayfield',
94666c47 265 fieldLabel: gettext('Layout') + ':',
bd7aef86 266 flex: 1,
9a08bd8a
TL
267 },
268 {
269 xtype: 'button',
270 cls: 'x-btn-default-toolbar-small proxmox-inline-button',
bd7aef86 271 text: gettext('Reset'),
9a08bd8a
TL
272 tooltip: gettext('Reset all layout changes (for example, column widths)'),
273 name: 'reset',
9a08bd8a 274 },
f6710aac 275 ],
26fcae33 276 },
f973c5b2
DC
277 {
278 xtype: 'box',
8058410f 279 autoEl: { tag: 'hr' },
f973c5b2
DC
280 },
281 {
282 xtype: 'proxmoxKVComboBox',
283 fieldLabel: gettext('Summary columns') + ':',
284 labelWidth: 150,
285 stateId: 'summarycolumns',
286 reference: 'summarycolumns',
287 comboItems: [
288 ['auto', 'auto'],
289 ['1', '1'],
290 ['2', '2'],
291 ['3', '3'],
292 ],
293 },
300c0f73
TL
294 {
295 xtype: 'proxmoxKVComboBox',
296 fieldLabel: gettext('Guest Notes') + ':',
297 labelWidth: 150,
298 stateId: 'guest-notes-collapse',
299 reference: 'guestNotesCollapse',
300 comboItems: [
301 ['never', 'Show by default'],
302 ['always', 'Collapse by default'],
303 ['auto', 'auto (Collapse if empty)'],
304 ],
305 },
f6710aac 306 ],
9d6d8d86
TL
307 },
308 {
26fcae33
DJ
309 xtype: 'container',
310 layout: 'vbox',
d27a44a6 311 flex: 1,
d9ace13c 312 margin: '5',
26fcae33
DJ
313 defaults: {
314 width: '100%',
315 // right margin ensures that the right border of the fieldsets
316 // is shown
f6710aac 317 margin: '0 2 10 0',
26fcae33 318 },
8058410f 319 items: [
26fcae33
DJ
320 {
321 xtype: 'fieldset',
322 itemId: 'xtermjs',
323 title: gettext('xterm.js Settings'),
324 items: [{
325 xtype: 'form',
326 reference: 'xtermform',
327 border: false,
2b0bdc46 328 layout: {
26fcae33 329 type: 'vbox',
f6710aac 330 algin: 'left',
26fcae33
DJ
331 },
332 defaults: {
333 width: '100%',
334 margin: '0 0 10 0',
d9ace13c 335 },
2b0bdc46
DC
336 items: [
337 {
26fcae33
DJ
338 xtype: 'textfield',
339 name: 'fontFamily',
340 reference: 'fontFamily',
341 emptyText: Proxmox.Utils.defaultText,
f6710aac 342 fieldLabel: gettext('Font-Family'),
26fcae33
DJ
343 },
344 {
345 xtype: 'proxmoxintegerfield',
346 emptyText: Proxmox.Utils.defaultText,
347 name: 'fontSize',
348 reference: 'fontSize',
349 minValue: 1,
f6710aac 350 fieldLabel: gettext('Font-Size'),
26fcae33
DJ
351 },
352 {
353 xtype: 'numberfield',
354 name: 'letterSpacing',
355 reference: 'letterSpacing',
356 emptyText: Proxmox.Utils.defaultText,
f6710aac 357 fieldLabel: gettext('Letter Spacing'),
26fcae33
DJ
358 },
359 {
360 xtype: 'numberfield',
361 name: 'lineHeight',
362 minValue: 0.1,
363 reference: 'lineHeight',
364 emptyText: Proxmox.Utils.defaultText,
f6710aac 365 fieldLabel: gettext('Line Height'),
2b0bdc46
DC
366 },
367 {
26fcae33
DJ
368 xtype: 'container',
369 layout: {
370 type: 'hbox',
f6710aac 371 pack: 'end',
26fcae33 372 },
a3c30fbc
TL
373 defaults: {
374 margin: '0 0 0 5',
375 },
26fcae33
DJ
376 items: [
377 {
378 xtype: 'button',
379 reference: 'xtermreset',
380 disabled: true,
f6710aac 381 text: gettext('Reset'),
26fcae33
DJ
382 },
383 {
384 xtype: 'button',
385 reference: 'xtermsave',
386 disabled: true,
f6710aac
TL
387 text: gettext('Save'),
388 },
389 ],
390 },
391 ],
392 }],
393 }, {
26fcae33
DJ
394 xtype: 'fieldset',
395 title: gettext('noVNC Settings'),
396 items: [
26fcae33
DJ
397 {
398 xtype: 'radiogroup',
b89a26bc 399 fieldLabel: gettext('Scaling mode'),
26fcae33
DJ
400 reference: 'noVNCScalingGroup',
401 height: '15px', // renders faster with value assigned
402 layout: {
403 type: 'hbox',
404 },
405 items: [
406 {
407 xtype: 'radiofield',
408 name: 'noVNCScalingField',
409 inputValue: 'scale',
410 boxLabel: 'Local Scaling',
411 checked: true,
f6710aac 412 }, {
26fcae33
DJ
413 xtype: 'radiofield',
414 name: 'noVNCScalingField',
415 inputValue: 'off',
416 boxLabel: 'Off',
417 margin: '0 0 0 10',
f6710aac 418 },
26fcae33
DJ
419 ],
420 listeners: {
421 change: function(el, newValue, undefined) {
422 var sp = Ext.state.Manager.getProvider();
f5c68a74 423 sp.set('novnc-scaling', newValue.noVNCScalingField);
f6710aac 424 },
26fcae33
DJ
425 },
426 },
f6710aac 427 ],
26fcae33 428 },
f6710aac 429 ],
ce11a8af 430 }],
ce11a8af 431});