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