]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Workspace.js
ui: eslint: fix trailing comma and comma related whitespaces errors
[pve-manager.git] / www / manager6 / Workspace.js
CommitLineData
787ae72a
DM
1/*
2 * Workspace base class
3 *
4 * popup login window when auth fails (call onLogin handler)
5 * update (re-login) ticket every 15 minutes
6 *
7 */
8
9Ext.define('PVE.Workspace', {
10 extend: 'Ext.container.Viewport',
11
12 title: 'Proxmox Virtual Environment',
13
14 loginData: null, // Data from last login call
15
16 onLogin: function(loginData) {},
17
18 // private
19 updateLoginData: function(loginData) {
20 var me = this;
21 me.loginData = loginData;
24d2ed8c 22 Proxmox.Utils.setAuthData(loginData);
787ae72a 23
3d7b2aa9
TL
24 var rt = me.down('pveResourceTree');
25 rt.setDatacenterText(loginData.clustername);
9ebe2165 26 PVE.ClusterName = loginData.clustername;
3d7b2aa9 27
787ae72a
DM
28 if (loginData.cap) {
29 Ext.state.Manager.set('GuiCap', loginData.cap);
30 }
1370f628 31 me.response401count = 0;
787ae72a 32
787ae72a
DM
33 me.onLogin(loginData);
34 },
35
36 // private
37 showLogin: function() {
38 var me = this;
39
e7ade592 40 Proxmox.Utils.authClear();
9fd1198e 41 Ext.state.Manager.clear('GuiCap');
35a04562 42 Proxmox.UserName = null;
787ae72a
DM
43 me.loginData = null;
44
45 if (!me.login) {
46 me.login = Ext.create('PVE.window.LoginWindow', {
47 handler: function(data) {
48 me.login = null;
49 me.updateLoginData(data);
e7ade592 50 Proxmox.Utils.checked_command(function() {}); // display subscription status
f6710aac 51 },
787ae72a
DM
52 });
53 }
54 me.onLogin(null);
55 me.login.show();
56 },
57
58 initComponent : function() {
59 var me = this;
60
61 Ext.tip.QuickTipManager.init();
62
63 // fixme: what about other errors
64 Ext.Ajax.on('requestexception', function(conn, response, options) {
fe13284e 65 if (response.status == 401 && !PVE.Utils.silenceAuthFailures) { // auth failure
1370f628
TL
66 // don't immediately show as logged out to cope better with some big
67 // upgrades, which may temporarily produce a false positive 401 err
68 me.response401count++;
69 if (me.response401count > 5) {
70 me.showLogin();
71 }
787ae72a
DM
72 }
73 });
74
787ae72a
DM
75 me.callParent();
76
e7ade592 77 if (!Proxmox.Utils.authOK()) {
787ae72a 78 me.showLogin();
7c8051b4 79 } else {
787ae72a
DM
80 if (me.loginData) {
81 me.onLogin(me.loginData);
82 }
83 }
84
85 Ext.TaskManager.start({
86 run: function() {
e7ade592 87 var ticket = Proxmox.Utils.authOK();
35a04562 88 if (!ticket || !Proxmox.UserName) {
787ae72a
DM
89 return;
90 }
91
92 Ext.Ajax.request({
7c8051b4 93 params: {
35a04562 94 username: Proxmox.UserName,
f6710aac 95 password: ticket,
787ae72a
DM
96 },
97 url: '/api2/json/access/ticket',
98 method: 'POST',
99 success: function(response, opts) {
100 var obj = Ext.decode(response.responseText);
101 me.updateLoginData(obj.data);
f6710aac 102 },
787ae72a
DM
103 });
104 },
f6710aac 105 interval: 15*60*1000,
787ae72a
DM
106 });
107
f6710aac 108 },
787ae72a
DM
109});
110
787ae72a
DM
111Ext.define('PVE.StdWorkspace', {
112 extend: 'PVE.Workspace',
113
114 alias: ['widget.pveStdWorkspace'],
115
116 // private
117 setContent: function(comp) {
118 var me = this;
7c8051b4 119
787ae72a 120 var cont = me.child('#content');
834ba9e4
DC
121
122 var lay = cont.getLayout();
123
124 var cur = lay.getActiveItem();
787ae72a
DM
125
126 if (comp) {
e7ade592 127 Proxmox.Utils.setErrorMask(cont, false);
787ae72a
DM
128 comp.border = false;
129 cont.add(comp);
834ba9e4
DC
130 if (cur !== null && lay.getNext()) {
131 lay.next();
132 var task = Ext.create('Ext.util.DelayedTask', function(){
133 cont.remove(cur);
134 });
135 task.delay(10);
136 }
137 }
de7eeaac
EK
138 else {
139 // helper for cleaning the content when logging out
140 cont.removeAll();
141 }
787ae72a
DM
142 },
143
144 selectById: function(nodeid) {
145 var me = this;
146 var tree = me.down('pveResourceTree');
147 tree.selectById(nodeid);
148 },
149
787ae72a
DM
150 onLogin: function(loginData) {
151 var me = this;
152
153 me.updateUserInfo();
154
155 if (loginData) {
156 PVE.data.ResourceStore.startUpdate();
157
e7ade592 158 Proxmox.Utils.API2Request({
787ae72a
DM
159 url: '/version',
160 method: 'GET',
161 success: function(response) {
162 PVE.VersionInfo = response.result.data;
163 me.updateVersionInfo();
f6710aac 164 },
787ae72a 165 });
f1ca55fb
AD
166
167 Proxmox.Utils.API2Request({
168 url: '/cluster/sdn',
169 method: 'GET',
170 success: function(response) {
171 PVE.SDNInfo = response.result.data;
35ffde01
TL
172 },
173 failure: function(response) {
174 PVE.SDNInfo = null;
175 let ui = Ext.ComponentQuery.query('treelistitem[text="SDN"]')[0];
176 if (ui) {
177 ui.addCls('x-hidden-display');
178 }
179 },
f1ca55fb 180 });
787ae72a
DM
181 }
182 },
183
184 updateUserInfo: function() {
185 var me = this;
787ae72a 186 var ui = me.query('#userinfo')[0];
1011b569 187 ui.setText(Ext.String.htmlEncode(Proxmox.UserName || ''));
6a71fe01 188 ui.updateLayout();
787ae72a
DM
189 },
190
191 updateVersionInfo: function() {
192 var me = this;
193
194 var ui = me.query('#versioninfo')[0];
195
196 if (PVE.VersionInfo) {
180a86d3 197 var version = PVE.VersionInfo.version;
55d727ca 198 ui.update('Virtual Environment ' + version);
787ae72a 199 } else {
55d727ca 200 ui.update('Virtual Environment');
787ae72a 201 }
6a71fe01 202 ui.updateLayout();
787ae72a
DM
203 },
204
205 initComponent : function() {
206 var me = this;
207
208 Ext.History.init();
209
210 var sprovider = Ext.create('PVE.StateProvider');
211 Ext.state.Manager.setProvider(sprovider);
212
aeb5e2f6 213 var selview = Ext.create('PVE.form.ViewSelector');
787ae72a
DM
214
215 var rtree = Ext.createWidget('pveResourceTree', {
216 viewFilter: selview.getViewFilter(),
217 flex: 1,
aeb5e2f6
EK
218 selModel: {
219 selType: 'treemodel',
787ae72a
DM
220 listeners: {
221 selectionchange: function(sm, selected) {
787ae72a
DM
222 if (selected.length > 0) {
223 var n = selected[0];
f184350f
EK
224 var tlckup = {
225 root: 'PVE.dc.Config',
226 node: 'PVE.node.Config',
227 qemu: 'PVE.qemu.Config',
228 lxc: 'PVE.lxc.Config',
229 storage: 'PVE.storage.Browser',
9233148b 230 sdn: 'PVE.sdn.Browser',
f6710aac 231 pool: 'pvePoolConfig',
f184350f
EK
232 };
233 var comp = {
7c8051b4 234 xtype: tlckup[n.data.type || 'root'] ||
787ae72a 235 'pvePanelConfig',
787ae72a
DM
236 showSearch: (n.data.id === 'root') ||
237 Ext.isDefined(n.data.groupbyid),
238 pveSelNode: n,
239 workspace: me,
f6710aac 240 viewFilter: selview.getViewFilter(),
787ae72a
DM
241 };
242 PVE.curSelectedNode = n;
f184350f 243 me.setContent(comp);
787ae72a 244 }
f6710aac
TL
245 },
246 },
247 },
787ae72a
DM
248 });
249
7c8051b4 250 selview.on('select', function(combo, records) {
fb387756 251 if (records) {
787ae72a
DM
252 var view = combo.getViewFilter();
253 rtree.setViewFilter(view);
254 }
255 });
256
257 var caps = sprovider.get('GuiCap');
258
259 var createVM = Ext.createWidget('button', {
260 pack: 'end',
f01259ee 261 margin: '3 5 0 0',
787ae72a 262 baseCls: 'x-btn',
d1f155b8 263 iconCls: 'fa fa-desktop',
787ae72a
DM
264 text: gettext("Create VM"),
265 disabled: !caps.vms['VM.Allocate'],
266 handler: function() {
267 var wiz = Ext.create('PVE.qemu.CreateWizard', {});
268 wiz.show();
f6710aac 269 },
787ae72a
DM
270 });
271
272 var createCT = Ext.createWidget('button', {
273 pack: 'end',
f01259ee 274 margin: '3 5 0 0',
787ae72a 275 baseCls: 'x-btn',
d1f155b8 276 iconCls: 'fa fa-cube',
787ae72a
DM
277 text: gettext("Create CT"),
278 disabled: !caps.vms['VM.Allocate'],
279 handler: function() {
280 var wiz = Ext.create('PVE.lxc.CreateWizard', {});
281 wiz.show();
f6710aac 282 },
787ae72a
DM
283 });
284
285 sprovider.on('statechange', function(sp, key, value) {
286 if (key === 'GuiCap' && value) {
287 caps = value;
288 createVM.setDisabled(!caps.vms['VM.Allocate']);
289 createCT.setDisabled(!caps.vms['VM.Allocate']);
290 }
291 });
292
293 Ext.apply(me, {
294 layout: { type: 'border' },
295 border: false,
296 items: [
297 {
298 region: 'north',
7c8051b4 299 layout: {
787ae72a 300 type: 'hbox',
f6710aac 301 align: 'middle',
787ae72a 302 },
7c8051b4 303 baseCls: 'x-plain',
787ae72a 304 defaults: {
f6710aac 305 baseCls: 'x-plain',
787ae72a
DM
306 },
307 border: false,
f76884fd 308 margin: '2 0 2 5',
787ae72a
DM
309 items: [
310 {
d1efcadf 311 xtype: 'proxmoxlogo',
787ae72a
DM
312 },
313 {
bbcfa5ab 314 minWidth: 150,
787ae72a 315 id: 'versioninfo',
f6710aac 316 html: 'Virtual Environment',
787ae72a 317 },
839eed58
DC
318 {
319 xtype: 'pveGlobalSearchField',
f6710aac 320 tree: rtree,
839eed58
DC
321 },
322 {
f6710aac 323 flex: 1,
839eed58 324 },
3ef58611 325 {
672a6270 326 xtype: 'proxmoxHelpButton',
3ef58611 327 hidden: false,
1e4a853c 328 baseCls: 'x-btn',
41e024ee 329 iconCls: 'fa fa-book x-btn-icon-el-default-toolbar-small ',
3ef58611 330 listenToGlobalEvent: false,
c8802a60 331 onlineHelp: 'pve_documentation_index',
41e024ee 332 text: gettext('Documentation'),
f6710aac 333 margin: '0 5 0 0',
3ef58611 334 },
7c8051b4 335 createVM,
6a7465ae 336 createCT,
787ae72a
DM
337 {
338 pack: 'end',
f76884fd 339 margin: '0 5 0 0',
d962846d 340 id: 'userinfo',
787ae72a
DM
341 xtype: 'button',
342 baseCls: 'x-btn',
404bf6c8
TL
343 style: {
344 // proxmox dark grey p light grey as border
345 backgroundColor: '#464d4d',
f6710aac 346 borderColor: '#ABBABA',
404bf6c8 347 },
d962846d
DC
348 iconCls: 'fa fa-user',
349 menu: [
350 {
351 iconCls: 'fa fa-gear',
352 text: gettext('My Settings'),
353 handler: function() {
354 var win = Ext.create('PVE.window.Settings');
355 win.show();
f6710aac 356 },
d962846d
DC
357 },
358 {
359 text: gettext('Password'),
360 iconCls: 'fa fa-fw fa-key',
361 handler: function() {
362 var win = Ext.create('Proxmox.window.PasswordEdit', {
f6710aac 363 userid: Proxmox.UserName,
d962846d
DC
364 });
365 win.show();
f6710aac 366 },
d962846d
DC
367 },
368 {
369 text: 'TFA',
370 iconCls: 'fa fa-fw fa-lock',
371 handler: function(btn, event, rec) {
f6710aac
TL
372 var win = Ext.create('PVE.window.TFAEdit', {
373 userid: Proxmox.UserName,
d962846d
DC
374 });
375 win.show();
f6710aac 376 },
d962846d 377 },
428d5e78
DC
378 {
379 iconCls: 'fa fa-language',
380 text: gettext('Language'),
381 handler: function() {
382 Ext.create('Proxmox.window.LanguageEditWindow')
383 .show();
384 },
385 },
d962846d
DC
386 '-',
387 {
388 iconCls: 'fa fa-fw fa-sign-out',
389 text: gettext("Logout"),
390 handler: function() {
391 PVE.data.ResourceStore.loadData([], false);
392 me.showLogin();
393 me.setContent(null);
394 var rt = me.down('pveResourceTree');
395 rt.setDatacenterText(undefined);
396 rt.clearTree();
397
398 // empty the stores of the StatusPanel child items
399 var statusPanels = Ext.ComponentQuery.query('pveStatusPanel grid');
400 Ext.Array.forEach(statusPanels, function(comp) {
401 if (comp.getStore()) {
402 comp.getStore().loadData([], false);
403 }
404 });
f6710aac
TL
405 },
406 },
407 ],
408 },
409 ],
787ae72a
DM
410 },
411 {
412 region: 'center',
29aedb75
DC
413 stateful: true,
414 stateId: 'pvecenter',
415 minWidth: 100,
416 minHeight: 100,
787ae72a
DM
417 id: 'content',
418 xtype: 'container',
834ba9e4 419 layout: { type: 'card' },
787ae72a 420 border: false,
f01259ee 421 margin: '0 5 0 0',
f6710aac 422 items: [],
787ae72a
DM
423 },
424 {
425 region: 'west',
29aedb75
DC
426 stateful: true,
427 stateId: 'pvewest',
428 itemId: 'west',
787ae72a
DM
429 xtype: 'container',
430 border: false,
431 layout: { type: 'vbox', align: 'stretch' },
f01259ee 432 margin: '0 0 0 5',
787ae72a
DM
433 split: true,
434 width: 200,
29aedb75
DC
435 items: [ selview, rtree ],
436 listeners: {
437 resize: function(panel, width, height) {
438 var viewWidth = me.getSize().width;
439 if (width > viewWidth - 100) {
440 panel.setWidth(viewWidth - 100);
441 }
f6710aac
TL
442 },
443 },
787ae72a
DM
444 },
445 {
80e8b725 446 xtype: 'pveStatusPanel',
29aedb75
DC
447 stateful: true,
448 stateId: 'pvesouth',
449 itemId: 'south',
787ae72a 450 region: 'south',
f01259ee 451 margin:'0 5 5 5',
6a87871f
DC
452 title: gettext('Logs'),
453 collapsible: true,
454 header: false,
29aedb75
DC
455 height: 200,
456 split:true,
457 listeners: {
458 resize: function(panel, width, height) {
29aedb75
DC
459 var viewHeight = me.getSize().height;
460 if (height > (viewHeight - 150)) {
461 panel.setHeight(viewHeight - 150);
462 }
f6710aac
TL
463 },
464 },
465 },
466 ],
787ae72a
DM
467 });
468
469 me.callParent();
470
471 me.updateUserInfo();
6c18be66
DC
472
473 // on resize, center all modal windows
474 Ext.on('resize', function(){
475 var wins = Ext.ComponentQuery.query('window[modal]');
476 if (wins.length > 0) {
477 wins.forEach(function(win){
478 win.alignTo(me, 'c-c');
479 });
480 }
481 });
f6710aac 482 },
787ae72a
DM
483});
484