]>
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 checkVmMigration: function(record
) {
145 var tree
= me
.down('pveResourceTree');
146 tree
.checkVmMigration(record
);
149 onLogin: function(loginData
) {
155 PVE
.data
.ResourceStore
.startUpdate();
157 PVE
.Utils
.API2Request({
160 success: function(response
) {
161 PVE
.VersionInfo
= response
.result
.data
;
162 me
.updateVersionInfo();
168 updateUserInfo: function() {
171 var ui
= me
.query('#userinfo')[0];
174 var msg
= Ext
.String
.format(gettext("You are logged in as {0}"), "'" + PVE
.UserName
+ "'");
175 ui
.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg
+ '</div>');
182 updateVersionInfo: function() {
185 var ui
= me
.query('#versioninfo')[0];
187 if (PVE
.VersionInfo
) {
188 var version
= PVE
.VersionInfo
.version
+ '-' + PVE
.VersionInfo
.release
+ '/' +
189 PVE
.VersionInfo
.repoid
;
190 ui
.update('Virtual Environment ' + version
);
192 ui
.update('Virtual Environment');
197 initComponent : function() {
202 var sprovider
= Ext
.create('PVE.StateProvider');
203 Ext
.state
.Manager
.setProvider(sprovider
);
205 var selview
= Ext
.create('PVE.form.ViewSelector');
207 var rtree
= Ext
.createWidget('pveResourceTree', {
208 viewFilter
: selview
.getViewFilter(),
211 selType
: 'treemodel',
213 selectionchange: function(sm
, selected
) {
214 if (selected
.length
> 0) {
217 root
: 'PVE.dc.Config',
218 node
: 'PVE.node.Config',
219 qemu
: 'PVE.qemu.Config',
220 lxc
: 'PVE.lxc.Config',
221 storage
: 'PVE.storage.Browser',
222 pool
: 'pvePoolConfig'
225 xtype
: tlckup
[n
.data
.type
|| 'root'] ||
227 showSearch
: (n
.data
.id
=== 'root') ||
228 Ext
.isDefined(n
.data
.groupbyid
),
231 viewFilter
: selview
.getViewFilter()
233 PVE
.curSelectedNode
= n
;
241 selview
.on('select', function(combo
, records
) {
243 var view
= combo
.getViewFilter();
244 rtree
.setViewFilter(view
);
248 var caps
= sprovider
.get('GuiCap');
250 var createVM
= Ext
.createWidget('button', {
254 iconCls
: 'fa fa-desktop',
255 text
: gettext("Create VM"),
256 disabled
: !caps
.vms
['VM.Allocate'],
257 handler: function() {
258 var wiz
= Ext
.create('PVE.qemu.CreateWizard', {});
263 var createCT
= Ext
.createWidget('button', {
267 iconCls
: 'fa fa-cube',
268 text
: gettext("Create CT"),
269 disabled
: !caps
.vms
['VM.Allocate'],
270 handler: function() {
271 var wiz
= Ext
.create('PVE.lxc.CreateWizard', {});
276 sprovider
.on('statechange', function(sp
, key
, value
) {
277 if (key
=== 'GuiCap' && value
) {
279 createVM
.setDisabled(!caps
.vms
['VM.Allocate']);
280 createCT
.setDisabled(!caps
.vms
['VM.Allocate']);
285 layout
: { type
: 'border' },
302 html
: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
303 '<img style="padding-top:4px;padding-right:5px" src="/pve2/images/proxmox_logo.png"/></a>'
308 html
: 'Virtual Environment'
311 xtype
: 'pveGlobalSearchField',
325 iconCls
: 'fa black fa-gear',
327 handler: function() {
328 var win
= Ext
.create('PVE.window.Settings');
333 xtype
: 'pveHelpButton',
336 iconCls
: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ',
337 listenToGlobalEvent
: false,
338 onlineHelp
: 'pve_documentation_index',
348 iconCls
: 'fa fa-sign-out',
349 text
: gettext("Logout"),
350 handler: function() {
351 PVE
.data
.ResourceStore
.loadData([], false);
354 var rt
= me
.down('pveResourceTree');
357 // empty the stores of the StatusPanel child items
358 var statusPanels
= Ext
.ComponentQuery
.query('pveStatusPanel grid');
359 Ext
.Array
.forEach(statusPanels
, function(comp
) {
360 if (comp
.getStore()) {
361 comp
.getStore().loadData([], false);
371 stateId
: 'pvecenter',
376 layout
: { type
: 'card' },
388 layout
: { type
: 'vbox', align
: 'stretch' },
392 items
: [ selview
, rtree
],
394 resize: function(panel
, width
, height
) {
395 var viewWidth
= me
.getSize().width
;
396 if (width
> viewWidth
- 100) {
397 panel
.setWidth(viewWidth
- 100);
403 xtype
: 'pveStatusPanel',
409 title
: gettext('Logs'),
415 resize: function(panel
, width
, height
) {
416 var viewHeight
= me
.getSize().height
;
417 if (height
> (viewHeight
- 150)) {
418 panel
.setHeight(viewHeight
- 150);
430 // on resize, center all modal windows
431 Ext
.on('resize', function(){
432 var wins
= Ext
.ComponentQuery
.query('window[modal]');
433 if (wins
.length
> 0) {
434 wins
.forEach(function(win
){
435 win
.alignTo(me
, 'c-c');