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