]>
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 // TODO: display something useful
214 // Note:: error mask has wrong zindex, so we do not
215 // use that - see bug 114
216 // PVE.Utils.setErrorMask(cont, 'nothing selected');
220 selectById: function(nodeid
) {
222 var tree
= me
.down('pveResourceTree');
223 tree
.selectById(nodeid
);
226 checkVmMigration: function(record
) {
228 var tree
= me
.down('pveResourceTree');
229 tree
.checkVmMigration(record
);
232 onLogin: function(loginData
) {
238 PVE
.data
.ResourceStore
.startUpdate();
240 PVE
.Utils
.API2Request({
243 success: function(response
) {
244 PVE
.VersionInfo
= response
.result
.data
;
245 me
.updateVersionInfo();
251 updateUserInfo: function() {
254 var ui
= me
.query('#userinfo')[0];
257 var msg
= Ext
.String
.format(gettext("You are logged in as {0}"), "'" + PVE
.UserName
+ "'");
258 ui
.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg
+ '</div>');
265 updateVersionInfo: function() {
268 var ui
= me
.query('#versioninfo')[0];
270 if (PVE
.VersionInfo
) {
271 var version
= PVE
.VersionInfo
.version
+ '-' + PVE
.VersionInfo
.release
+ '/' +
272 PVE
.VersionInfo
.repoid
;
273 ui
.update('Proxmox Virtual Environment ' + version
);
275 ui
.update('Proxmox Virtual Environment');
280 initComponent : function() {
285 var sprovider
= Ext
.create('PVE.StateProvider');
286 Ext
.state
.Manager
.setProvider(sprovider
);
288 var selview
= Ext
.create('PVE.form.ViewSelector');
290 var rtree
= Ext
.createWidget('pveResourceTree', {
291 viewFilter
: selview
.getViewFilter(),
294 selType
: 'treemodel',
296 selectionchange: function(sm
, selected
) {
299 root
: 'PVE.dc.Config',
300 node
: 'PVE.node.Config',
301 qemu
: 'PVE.qemu.Config',
302 lxc
: 'PVE.lxc.Config',
303 storage
: 'PVE.storage.Browser',
304 pool
: 'pvePoolConfig'
307 if (selected
.length
> 0) {
310 xtype
: tlckup
[n
.data
.type
|| 'root'] ||
312 layout
: { type
: 'fit' },
313 showSearch
: (n
.data
.id
=== 'root') ||
314 Ext
.isDefined(n
.data
.groupbyid
),
317 viewFilter
: selview
.getViewFilter()
319 PVE
.curSelectedNode
= n
;
328 selview
.on('select', function(combo
, records
) {
330 var view
= combo
.getViewFilter();
331 rtree
.setViewFilter(view
);
335 var caps
= sprovider
.get('GuiCap');
337 var createVM
= Ext
.createWidget('button', {
341 iconCls
: 'fa fa-desktop',
342 text
: gettext("Create VM"),
343 disabled
: !caps
.vms
['VM.Allocate'],
344 handler: function() {
345 var wiz
= Ext
.create('PVE.qemu.CreateWizard', {});
350 var createCT
= Ext
.createWidget('button', {
354 iconCls
: 'fa fa-cube',
355 text
: gettext("Create CT"),
356 disabled
: !caps
.vms
['VM.Allocate'],
357 handler: function() {
358 var wiz
= Ext
.create('PVE.lxc.CreateWizard', {});
363 sprovider
.on('statechange', function(sp
, key
, value
) {
364 if (key
=== 'GuiCap' && value
) {
366 createVM
.setDisabled(!caps
.vms
['VM.Allocate']);
367 createCT
.setDisabled(!caps
.vms
['VM.Allocate']);
372 layout
: { type
: 'border' },
389 html
: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
390 '<img height=30 width=209 src="/pve2/images/proxmox_logo.png"/></a>'
396 html
: 'Proxmox Virtual Environment'
411 iconCls
: 'fa fa-sign-out',
412 text
: gettext("Logout"),
413 handler: function() {
414 PVE
.data
.ResourceStore
.stopUpdate();
417 var rt
= me
.down('pveResourceTree');
426 stateId
: 'pvecenter',
431 layout
: { type
: 'card' },
443 layout
: { type
: 'vbox', align
: 'stretch' },
447 items
: [ selview
, rtree
],
449 resize: function(panel
, width
, height
) {
450 var viewWidth
= me
.getSize().width
;
451 if (width
> viewWidth
- 100) {
452 panel
.setWidth(viewWidth
- 100);
458 xtype
: 'pveStatusPanel',
467 resize: function(panel
, width
, height
) {
469 var viewHeight
= me
.getSize().height
;
470 if (height
> (viewHeight
- 150)) {
471 panel
.setHeight(viewHeight
- 150);