]>
git.proxmox.com Git - pve-manager.git/blob - www/manager/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
68 document
.title
= me
.title
;
72 if (!PVE
.Utils
.authOK()) {
76 me
.onLogin(me
.loginData
);
80 Ext
.TaskManager
.start({
82 var ticket
= PVE
.Utils
.authOK();
83 if (!ticket
|| !PVE
.UserName
) {
89 username
: PVE
.UserName
,
92 url
: '/api2/json/access/ticket',
94 success: function(response
, opts
) {
95 var obj
= Ext
.decode(response
.responseText
);
96 me
.updateLoginData(obj
.data
);
106 Ext
.define('PVE.ConsoleWorkspace', {
107 extend
: 'PVE.Workspace',
109 alias
: ['widget.pveConsoleWorkspace'],
111 title
: gettext('Console'),
113 initComponent : function() {
116 var param
= Ext
.Object
.fromQueryString(window
.location
.search
);
117 var consoleType
= me
.consoleType
|| param
.console
;
120 if (consoleType
=== 'kvm') {
121 me
.title
= "VM " + param
.vmid
;
123 me
.title
+= " ('" + param
.vmname
+ "')";
126 xtype
: 'pveKVMConsole',
128 nodename
: param
.node
,
129 vmname
: param
.vmname
,
132 } else if (consoleType
=== 'openvz') {
133 me
.title
= "CT " + param
.vmid
;
135 me
.title
+= " ('" + param
.vmname
+ "')";
138 xtype
: 'pveOpenVZConsole',
140 nodename
: param
.node
,
141 vmname
: param
.vmname
,
144 } else if (consoleType
=== 'shell') {
145 me
.title
= "node '" + param
.node
+ "'";
148 nodename
: param
.node
,
151 } else if (consoleType
=== 'upgrade') {
152 me
.title
= Ext
.String
.format(gettext('System upgrade on node {0}'), "'" + param
.node
+ "'");
155 nodename
: param
.node
,
163 html
: gettext('Error') + ': No such console type'
168 layout
: { type
: 'fit' },
177 Ext
.define('PVE.StdWorkspace', {
178 extend
: 'PVE.Workspace',
180 alias
: ['widget.pveStdWorkspace'],
183 setContent: function(comp
) {
186 var cont
= me
.child('#content');
187 cont
.removeAll(true);
190 PVE
.Utils
.setErrorMask(cont
, false);
196 // TODO: display something useful
198 // Note:: error mask has wrong zindex, so we do not
199 // use that - see bug 114
200 // PVE.Utils.setErrorMask(cont, 'nothing selected');
204 selectById: function(nodeid
) {
206 var tree
= me
.down('pveResourceTree');
207 tree
.selectById(nodeid
);
210 checkVmMigration: function(record
) {
212 var tree
= me
.down('pveResourceTree');
213 tree
.checkVmMigration(record
);
216 onLogin: function(loginData
) {
222 PVE
.data
.ResourceStore
.startUpdate();
224 PVE
.Utils
.API2Request({
227 success: function(response
) {
228 PVE
.VersionInfo
= response
.result
.data
;
229 me
.updateVersionInfo();
235 updateUserInfo: function() {
238 var ui
= me
.query('#userinfo')[0];
241 var msg
= Ext
.String
.format(gettext("You are logged in as {0}"), "'" + PVE
.UserName
+ "'");
242 ui
.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg
+ '</div>');
249 updateVersionInfo: function() {
252 var ui
= me
.query('#versioninfo')[0];
254 if (PVE
.VersionInfo
) {
255 var version
= PVE
.VersionInfo
.version
+ '-' + PVE
.VersionInfo
.release
+ '/' +
256 PVE
.VersionInfo
.repoid
;
257 ui
.update('<span class="x-panel-header-text">Proxmox Virtual Environment<br>' + gettext('Version') + ': ' + version
+ "</span>");
259 ui
.update('<span class="x-panel-header-text">Proxmox Virtual Environment</span>');
264 initComponent : function() {
269 var sprovider
= Ext
.create('PVE.StateProvider');
270 Ext
.state
.Manager
.setProvider(sprovider
);
272 var selview
= new PVE
.form
.ViewSelector({});
274 var rtree
= Ext
.createWidget('pveResourceTree', {
275 viewFilter
: selview
.getViewFilter(),
277 selModel
: new Ext
.selection
.TreeModel({
279 selectionchange: function(sm
, selected
) {
282 root
: 'PVE.dc.Config',
283 node
: 'PVE.node.Config',
284 qemu
: 'PVE.qemu.Config',
285 openvz
: 'PVE.openvz.Config',
286 storage
: 'PVE.storage.Browser',
287 pool
: 'pvePoolConfig'
290 if (selected
.length
> 0) {
293 xtype
: tlckup
[n
.data
.type
|| 'root'] ||
295 layout
: { type
: 'fit' },
296 showSearch
: (n
.data
.id
=== 'root') ||
297 Ext
.isDefined(n
.data
.groupbyid
),
300 viewFilter
: selview
.getViewFilter()
302 PVE
.curSelectedNode
= n
;
311 selview
.on('select', function(combo
, records
) {
312 if (records
&& records
.length
) {
313 var view
= combo
.getViewFilter();
314 rtree
.setViewFilter(view
);
318 var caps
= sprovider
.get('GuiCap');
320 var createVM
= Ext
.createWidget('button', {
324 text
: gettext("Create VM"),
325 disabled
: !caps
.vms
['VM.Allocate'],
326 handler: function() {
327 var wiz
= Ext
.create('PVE.qemu.CreateWizard', {});
332 var createCT
= Ext
.createWidget('button', {
336 text
: gettext("Create CT"),
337 disabled
: !caps
.vms
['VM.Allocate'],
338 handler: function() {
339 var wiz
= Ext
.create('PVE.openvz.CreateWizard', {});
344 sprovider
.on('statechange', function(sp
, key
, value
) {
345 if (key
=== 'GuiCap' && value
) {
347 createVM
.setDisabled(!caps
.vms
['VM.Allocate']);
348 createCT
.setDisabled(!caps
.vms
['VM.Allocate']);
353 layout
: { type
: 'border' },
372 html
: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
373 '<img height=30 width=209 src="/pve2/images/proxmox_logo.png"/></a>'
379 html
: '<span class="x-panel-header-text">Proxmox Virtual Environment</span>'
383 margins
: '8 10 0 10',
392 text
: gettext("Logout"),
393 handler: function() {
394 PVE
.data
.ResourceStore
.stopUpdate();
397 var rt
= me
.down('pveResourceTree');
409 layout
: { type
: 'fit' },
419 layout
: { type
: 'vbox', align
: 'stretch' },
423 items
: [ selview
, rtree
]
426 xtype
: 'pveStatusPanel',