]>
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 PVE
.CSRFPreventionToken
= loginData
.CSRFPreventionToken
;
23 PVE
.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 PVE
.Utils
.authClear();
44 me
.login
= Ext
.create('PVE.window.LoginWindow', {
45 handler: function(data
) {
47 me
.updateLoginData(data
);
48 PVE
.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) { // auth failure
70 if (!PVE
.Utils
.authOK()) {
74 me
.onLogin(me
.loginData
);
78 Ext
.TaskManager
.start({
80 var ticket
= PVE
.Utils
.authOK();
81 if (!ticket
|| !PVE
.UserName
) {
87 username
: PVE
.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 PVE
.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 PVE
.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];
168 var msg
= Ext
.String
.format(gettext("You are logged in as {0}"), "'" + PVE
.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 PVE
.VersionInfo
.repoid
;
184 ui
.update('Virtual Environment ' + version
);
186 ui
.update('Virtual Environment');
191 initComponent : function() {
196 var sprovider
= Ext
.create('PVE.StateProvider');
197 Ext
.state
.Manager
.setProvider(sprovider
);
199 var selview
= Ext
.create('PVE.form.ViewSelector');
201 var rtree
= Ext
.createWidget('pveResourceTree', {
202 viewFilter
: selview
.getViewFilter(),
205 selType
: 'treemodel',
207 selectionchange: function(sm
, selected
) {
208 if (selected
.length
> 0) {
211 root
: 'PVE.dc.Config',
212 node
: 'PVE.node.Config',
213 qemu
: 'PVE.qemu.Config',
214 lxc
: 'PVE.lxc.Config',
215 storage
: 'PVE.storage.Browser',
216 pool
: 'pvePoolConfig'
219 xtype
: tlckup
[n
.data
.type
|| 'root'] ||
221 showSearch
: (n
.data
.id
=== 'root') ||
222 Ext
.isDefined(n
.data
.groupbyid
),
225 viewFilter
: selview
.getViewFilter()
227 PVE
.curSelectedNode
= n
;
235 selview
.on('select', function(combo
, records
) {
237 var view
= combo
.getViewFilter();
238 rtree
.setViewFilter(view
);
242 var caps
= sprovider
.get('GuiCap');
244 var createVM
= Ext
.createWidget('button', {
248 iconCls
: 'fa fa-desktop',
249 text
: gettext("Create VM"),
250 disabled
: !caps
.vms
['VM.Allocate'],
251 handler: function() {
252 var wiz
= Ext
.create('PVE.qemu.CreateWizard', {});
257 var createCT
= Ext
.createWidget('button', {
261 iconCls
: 'fa fa-cube',
262 text
: gettext("Create CT"),
263 disabled
: !caps
.vms
['VM.Allocate'],
264 handler: function() {
265 var wiz
= Ext
.create('PVE.lxc.CreateWizard', {});
270 sprovider
.on('statechange', function(sp
, key
, value
) {
271 if (key
=== 'GuiCap' && value
) {
273 createVM
.setDisabled(!caps
.vms
['VM.Allocate']);
274 createCT
.setDisabled(!caps
.vms
['VM.Allocate']);
279 layout
: { type
: 'border' },
296 html
: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
297 '<img style="padding-top:4px;padding-right:5px" src="/pve2/images/proxmox_logo.png"/></a>'
302 html
: 'Virtual Environment'
306 html
: '<a href="https://bugzilla.proxmox.com" target="_blank">BETA</a>'
309 xtype
: 'pveGlobalSearchField',
323 iconCls
: 'fa black fa-gear',
325 handler: function() {
326 var win
= Ext
.create('PVE.window.Settings');
331 xtype
: 'pveHelpButton',
334 iconCls
: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ',
335 listenToGlobalEvent
: false,
336 onlineHelp
: 'pve_documentation_index',
346 iconCls
: 'fa fa-sign-out',
347 text
: gettext("Logout"),
348 handler: function() {
349 PVE
.data
.ResourceStore
.loadData([], false);
352 var rt
= me
.down('pveResourceTree');
355 // empty the stores of the StatusPanel child items
356 var statusPanels
= Ext
.ComponentQuery
.query('pveStatusPanel grid');
357 Ext
.Array
.forEach(statusPanels
, function(comp
) {
358 if (comp
.getStore()) {
359 comp
.getStore().loadData([], false);
369 stateId
: 'pvecenter',
374 layout
: { type
: 'card' },
386 layout
: { type
: 'vbox', align
: 'stretch' },
390 items
: [ selview
, rtree
],
392 resize: function(panel
, width
, height
) {
393 var viewWidth
= me
.getSize().width
;
394 if (width
> viewWidth
- 100) {
395 panel
.setWidth(viewWidth
- 100);
401 xtype
: 'pveStatusPanel',
407 title
: gettext('Logs'),
413 resize: function(panel
, width
, height
) {
414 var viewHeight
= me
.getSize().height
;
415 if (height
> (viewHeight
- 150)) {
416 panel
.setHeight(viewHeight
- 150);
428 // on resize, center all modal windows
429 Ext
.on('resize', function(){
430 var wins
= Ext
.ComponentQuery
.query('window[modal]');
431 if (wins
.length
> 0) {
432 wins
.forEach(function(win
){
433 win
.alignTo(me
, 'c-c');