]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Workspace.js
4 * popup login window when auth fails (call onLogin handler)
5 * update (re-login) ticket every 15 minutes
9 Ext
.define('PVE.Workspace', {
10 extend
: 'Ext.container.Viewport',
12 title
: 'Proxmox Virtual Environment',
14 loginData
: null, // Data from last login call
16 onLogin: function(loginData
) {},
19 updateLoginData: function(loginData
) {
21 me
.loginData
= loginData
;
22 Proxmox
.CSRFPreventionToken
= loginData
.CSRFPreventionToken
;
23 Proxmox
.UserName
= loginData
.username
;
26 Ext
.state
.Manager
.set('GuiCap', loginData
.cap
);
29 // creates a session cookie (expire = null)
30 // that way the cookie gets deleted after browser window close
31 Ext
.util
.Cookies
.set('PVEAuthCookie', loginData
.ticket
, null, '/', null, true);
32 me
.onLogin(loginData
);
36 showLogin: function() {
39 Proxmox
.Utils
.authClear();
40 Proxmox
.UserName
= null;
44 me
.login
= Ext
.create('PVE.window.LoginWindow', {
45 handler: function(data
) {
47 me
.updateLoginData(data
);
48 Proxmox
.Utils
.checked_command(function() {}); // display subscription status
56 initComponent : function() {
59 Ext
.tip
.QuickTipManager
.init();
61 // fixme: what about other errors
62 Ext
.Ajax
.on('requestexception', function(conn
, response
, options
) {
63 if (response
.status
== 401 && !PVE
.Utils
.silenceAuthFailures
) { // auth failure
70 if (!Proxmox
.Utils
.authOK()) {
74 me
.onLogin(me
.loginData
);
78 Ext
.TaskManager
.start({
80 var ticket
= Proxmox
.Utils
.authOK();
81 if (!ticket
|| !Proxmox
.UserName
) {
87 username
: Proxmox
.UserName
,
90 url
: '/api2/json/access/ticket',
92 success: function(response
, opts
) {
93 var obj
= Ext
.decode(response
.responseText
);
94 me
.updateLoginData(obj
.data
);
104 Ext
.define('PVE.StdWorkspace', {
105 extend
: 'PVE.Workspace',
107 alias
: ['widget.pveStdWorkspace'],
110 setContent: function(comp
) {
113 var cont
= me
.child('#content');
115 var lay
= cont
.getLayout();
117 var cur
= lay
.getActiveItem();
120 Proxmox
.Utils
.setErrorMask(cont
, false);
123 if (cur
!== null && lay
.getNext()) {
125 var task
= Ext
.create('Ext.util.DelayedTask', function(){
132 // helper for cleaning the content when logging out
137 selectById: function(nodeid
) {
139 var tree
= me
.down('pveResourceTree');
140 tree
.selectById(nodeid
);
143 onLogin: function(loginData
) {
149 PVE
.data
.ResourceStore
.startUpdate();
151 Proxmox
.Utils
.API2Request({
154 success: function(response
) {
155 PVE
.VersionInfo
= response
.result
.data
;
156 me
.updateVersionInfo();
162 updateUserInfo: function() {
165 var ui
= me
.query('#userinfo')[0];
167 if (Proxmox
.UserName
) {
168 var msg
= Ext
.String
.format(gettext("You are logged in as {0}"), "'" + Proxmox
.UserName
+ "'");
169 ui
.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg
+ '</div>');
176 updateVersionInfo: function() {
179 var ui
= me
.query('#versioninfo')[0];
181 if (PVE
.VersionInfo
) {
182 var version
= PVE
.VersionInfo
.version
+ '-' + PVE
.VersionInfo
.release
;
183 ui
.update('Virtual Environment ' + version
);
185 ui
.update('Virtual Environment');
190 initComponent : function() {
195 var sprovider
= Ext
.create('PVE.StateProvider');
196 Ext
.state
.Manager
.setProvider(sprovider
);
198 var selview
= Ext
.create('PVE.form.ViewSelector');
200 var rtree
= Ext
.createWidget('pveResourceTree', {
201 viewFilter
: selview
.getViewFilter(),
204 selType
: 'treemodel',
206 selectionchange: function(sm
, selected
) {
207 if (selected
.length
> 0) {
210 root
: 'PVE.dc.Config',
211 node
: 'PVE.node.Config',
212 qemu
: 'PVE.qemu.Config',
213 lxc
: 'PVE.lxc.Config',
214 storage
: 'PVE.storage.Browser',
215 pool
: 'pvePoolConfig'
218 xtype
: tlckup
[n
.data
.type
|| 'root'] ||
220 showSearch
: (n
.data
.id
=== 'root') ||
221 Ext
.isDefined(n
.data
.groupbyid
),
224 viewFilter
: selview
.getViewFilter()
226 PVE
.curSelectedNode
= n
;
234 selview
.on('select', function(combo
, records
) {
236 var view
= combo
.getViewFilter();
237 rtree
.setViewFilter(view
);
241 var caps
= sprovider
.get('GuiCap');
243 var createVM
= Ext
.createWidget('button', {
247 iconCls
: 'fa fa-desktop',
248 text
: gettext("Create VM"),
249 disabled
: !caps
.vms
['VM.Allocate'],
250 handler: function() {
251 var wiz
= Ext
.create('PVE.qemu.CreateWizard', {});
256 var createCT
= Ext
.createWidget('button', {
260 iconCls
: 'fa fa-cube',
261 text
: gettext("Create CT"),
262 disabled
: !caps
.vms
['VM.Allocate'],
263 handler: function() {
264 var wiz
= Ext
.create('PVE.lxc.CreateWizard', {});
269 sprovider
.on('statechange', function(sp
, key
, value
) {
270 if (key
=== 'GuiCap' && value
) {
272 createVM
.setDisabled(!caps
.vms
['VM.Allocate']);
273 createCT
.setDisabled(!caps
.vms
['VM.Allocate']);
278 layout
: { type
: 'border' },
295 html
: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
296 '<img style="padding-top:4px;padding-right:5px" src="/pve2/images/proxmox_logo.png"/></a>'
301 html
: 'Virtual Environment'
304 xtype
: 'pveGlobalSearchField',
318 iconCls
: 'fa black fa-gear',
320 handler: function() {
321 var win
= Ext
.create('PVE.window.Settings');
326 xtype
: 'proxmoxHelpButton',
329 iconCls
: 'fa fa-book x-btn-icon-el-default-toolbar-small ',
330 listenToGlobalEvent
: false,
331 onlineHelp
: 'pve_documentation_index',
332 text
: gettext('Documentation'),
342 iconCls
: 'fa fa-sign-out',
343 text
: gettext("Logout"),
344 handler: function() {
345 PVE
.data
.ResourceStore
.loadData([], false);
348 var rt
= me
.down('pveResourceTree');
351 // empty the stores of the StatusPanel child items
352 var statusPanels
= Ext
.ComponentQuery
.query('pveStatusPanel grid');
353 Ext
.Array
.forEach(statusPanels
, function(comp
) {
354 if (comp
.getStore()) {
355 comp
.getStore().loadData([], false);
365 stateId
: 'pvecenter',
370 layout
: { type
: 'card' },
382 layout
: { type
: 'vbox', align
: 'stretch' },
386 items
: [ selview
, rtree
],
388 resize: function(panel
, width
, height
) {
389 var viewWidth
= me
.getSize().width
;
390 if (width
> viewWidth
- 100) {
391 panel
.setWidth(viewWidth
- 100);
397 xtype
: 'pveStatusPanel',
403 title
: gettext('Logs'),
409 resize: function(panel
, width
, height
) {
410 var viewHeight
= me
.getSize().height
;
411 if (height
> (viewHeight
- 150)) {
412 panel
.setHeight(viewHeight
- 150);
424 // on resize, center all modal windows
425 Ext
.on('resize', function(){
426 var wins
= Ext
.ComponentQuery
.query('window[modal]');
427 if (wins
.length
> 0) {
428 wins
.forEach(function(win
){
429 win
.alignTo(me
, 'c-c');