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