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