]>
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.ConsoleWorkspace', {
105 extend
: 'PVE.Workspace',
107 alias
: ['widget.pveConsoleWorkspace'],
109 title
: gettext('Console'),
111 initComponent : function() {
112 // novnc is a string in param
113 // but a boolean in content
114 /*jslint confusion: true*/
117 var param
= Ext
.Object
.fromQueryString(window
.location
.search
);
118 var consoleType
= me
.consoleType
|| param
.console
;
120 param
.novnc
= (param
.novnc
=== '1') ? true : false;
123 if (consoleType
=== 'kvm') {
124 me
.title
= "VM " + param
.vmid
;
126 me
.title
+= " ('" + param
.vmname
+ "')";
129 xtype
: 'pveKVMConsole',
132 nodename
: param
.node
,
133 vmname
: param
.vmname
,
136 } else if (consoleType
=== 'lxc') {
137 me
.title
= "CT " + param
.vmid
;
139 me
.title
+= " ('" + param
.vmname
+ "')";
142 xtype
: 'pveLxcConsole',
145 nodename
: param
.node
,
146 vmname
: param
.vmname
,
149 } else if (consoleType
=== 'shell') {
150 me
.title
= "node '" + param
.node
+ "'";
154 nodename
: param
.node
,
157 } else if (consoleType
=== 'upgrade') {
158 me
.title
= Ext
.String
.format(gettext('System upgrade on node {0}'), "'" + param
.node
+ "'");
162 nodename
: param
.node
,
170 html
: gettext('Error') + ': No such console type'
175 layout
: { type
: 'fit' },
184 Ext
.define('PVE.StdWorkspace', {
185 extend
: 'PVE.Workspace',
187 alias
: ['widget.pveStdWorkspace'],
190 setContent: function(comp
) {
193 var cont
= me
.child('#content');
195 var lay
= cont
.getLayout();
197 var cur
= lay
.getActiveItem();
200 PVE
.Utils
.setErrorMask(cont
, false);
203 if (cur
!== null && lay
.getNext()) {
205 var task
= Ext
.create('Ext.util.DelayedTask', function(){
212 // helper for cleaning the content when logging out
217 selectById: function(nodeid
) {
219 var tree
= me
.down('pveResourceTree');
220 tree
.selectById(nodeid
);
223 checkVmMigration: function(record
) {
225 var tree
= me
.down('pveResourceTree');
226 tree
.checkVmMigration(record
);
229 onLogin: function(loginData
) {
235 PVE
.data
.ResourceStore
.startUpdate();
237 PVE
.Utils
.API2Request({
240 success: function(response
) {
241 PVE
.VersionInfo
= response
.result
.data
;
242 me
.updateVersionInfo();
248 updateUserInfo: function() {
251 var ui
= me
.query('#userinfo')[0];
254 var msg
= Ext
.String
.format(gettext("You are logged in as {0}"), "'" + PVE
.UserName
+ "'");
255 ui
.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg
+ '</div>');
262 updateVersionInfo: function() {
265 var ui
= me
.query('#versioninfo')[0];
267 if (PVE
.VersionInfo
) {
268 var version
= PVE
.VersionInfo
.version
+ '-' + PVE
.VersionInfo
.release
+ '/' +
269 PVE
.VersionInfo
.repoid
;
270 ui
.update('Virtual Environment ' + version
);
272 ui
.update('Virtual Environment');
277 initComponent : function() {
282 var sprovider
= Ext
.create('PVE.StateProvider');
283 Ext
.state
.Manager
.setProvider(sprovider
);
285 var selview
= Ext
.create('PVE.form.ViewSelector');
287 var rtree
= Ext
.createWidget('pveResourceTree', {
288 viewFilter
: selview
.getViewFilter(),
291 selType
: 'treemodel',
293 selectionchange: function(sm
, selected
) {
294 if (selected
.length
> 0) {
297 root
: 'PVE.dc.Config',
298 node
: 'PVE.node.Config',
299 qemu
: 'PVE.qemu.Config',
300 lxc
: 'PVE.lxc.Config',
301 storage
: 'PVE.storage.Browser',
302 pool
: 'pvePoolConfig'
305 xtype
: tlckup
[n
.data
.type
|| 'root'] ||
307 showSearch
: (n
.data
.id
=== 'root') ||
308 Ext
.isDefined(n
.data
.groupbyid
),
311 viewFilter
: selview
.getViewFilter()
313 PVE
.curSelectedNode
= n
;
321 selview
.on('select', function(combo
, records
) {
323 var view
= combo
.getViewFilter();
324 rtree
.setViewFilter(view
);
328 var caps
= sprovider
.get('GuiCap');
330 var createVM
= Ext
.createWidget('button', {
334 iconCls
: 'fa fa-desktop',
335 text
: gettext("Create VM"),
336 disabled
: !caps
.vms
['VM.Allocate'],
337 handler: function() {
338 var wiz
= Ext
.create('PVE.qemu.CreateWizard', {});
343 var createCT
= Ext
.createWidget('button', {
347 iconCls
: 'fa fa-cube',
348 text
: gettext("Create CT"),
349 disabled
: !caps
.vms
['VM.Allocate'],
350 handler: function() {
351 var wiz
= Ext
.create('PVE.lxc.CreateWizard', {});
356 sprovider
.on('statechange', function(sp
, key
, value
) {
357 if (key
=== 'GuiCap' && value
) {
359 createVM
.setDisabled(!caps
.vms
['VM.Allocate']);
360 createCT
.setDisabled(!caps
.vms
['VM.Allocate']);
365 layout
: { type
: 'border' },
382 html
: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
383 '<img style="padding-top:4px;padding-right:5px" src="/pve2/images/proxmox_logo.png"/></a>'
388 html
: 'Virtual Environment'
391 xtype
: 'pveGlobalSearchField',
405 iconCls
: 'fa black fa-gear',
409 handler: function() {
410 var win
= Ext
.create('PVE.window.Settings');
415 xtype
: 'pveHelpButton',
418 iconCls
: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ',
419 listenToGlobalEvent
: false,
420 onlineHelp
: 'pve_documentation_index',
430 iconCls
: 'fa fa-sign-out',
431 text
: gettext("Logout"),
432 handler: function() {
433 PVE
.data
.ResourceStore
.loadData([], false);
436 var rt
= me
.down('pveResourceTree');
439 // empty the stores of the StatusPanel child items
440 var statusPanels
= Ext
.ComponentQuery
.query('pveStatusPanel grid');
441 Ext
.Array
.forEach(statusPanels
, function(comp
) {
442 if (comp
.getStore()) {
443 comp
.getStore().loadData([], false);
453 stateId
: 'pvecenter',
458 layout
: { type
: 'card' },
470 layout
: { type
: 'vbox', align
: 'stretch' },
474 items
: [ selview
, rtree
],
476 resize: function(panel
, width
, height
) {
477 var viewWidth
= me
.getSize().width
;
478 if (width
> viewWidth
- 100) {
479 panel
.setWidth(viewWidth
- 100);
485 xtype
: 'pveStatusPanel',
491 title
: gettext('Logs'),
497 resize: function(panel
, width
, height
) {
498 var viewHeight
= me
.getSize().height
;
499 if (height
> (viewHeight
- 150)) {
500 panel
.setHeight(viewHeight
- 150);
512 // on resize, center all modal windows
513 Ext
.on('resize', function(){
514 var wins
= Ext
.ComponentQuery
.query('window[modal]');
515 if (wins
.length
> 0) {
516 wins
.forEach(function(win
){
517 win
.alignTo(me
, 'c-c');