]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Workspace.js
bump version to 4.1-31
[pve-manager.git] / www / manager6 / Workspace.js
CommitLineData
787ae72a
DM
1/*
2 * Workspace base class
3 *
4 * popup login window when auth fails (call onLogin handler)
5 * update (re-login) ticket every 15 minutes
6 *
7 */
8
9Ext.define('PVE.Workspace', {
10 extend: 'Ext.container.Viewport',
11
12 title: 'Proxmox Virtual Environment',
13
14 loginData: null, // Data from last login call
15
16 onLogin: function(loginData) {},
17
18 // private
19 updateLoginData: function(loginData) {
20 var me = this;
21 me.loginData = loginData;
22 PVE.CSRFPreventionToken = loginData.CSRFPreventionToken;
23 PVE.UserName = loginData.username;
24
25 if (loginData.cap) {
26 Ext.state.Manager.set('GuiCap', loginData.cap);
27 }
28
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);
33 },
34
35 // private
36 showLogin: function() {
37 var me = this;
38
39 PVE.Utils.authClear();
40 PVE.UserName = null;
41 me.loginData = null;
42
43 if (!me.login) {
44 me.login = Ext.create('PVE.window.LoginWindow', {
45 handler: function(data) {
46 me.login = null;
47 me.updateLoginData(data);
48 PVE.Utils.checked_command(function() {}); // display subscription status
49 }
50 });
51 }
52 me.onLogin(null);
53 me.login.show();
54 },
55
56 initComponent : function() {
57 var me = this;
58
59 Ext.tip.QuickTipManager.init();
60
61 // fixme: what about other errors
62 Ext.Ajax.on('requestexception', function(conn, response, options) {
63 if (response.status == 401) { // auth failure
64 me.showLogin();
65 }
66 });
67
787ae72a
DM
68 me.callParent();
69
70 if (!PVE.Utils.authOK()) {
71 me.showLogin();
72 } else {
73 if (me.loginData) {
74 me.onLogin(me.loginData);
75 }
76 }
77
78 Ext.TaskManager.start({
79 run: function() {
80 var ticket = PVE.Utils.authOK();
81 if (!ticket || !PVE.UserName) {
82 return;
83 }
84
85 Ext.Ajax.request({
86 params: {
87 username: PVE.UserName,
88 password: ticket
89 },
90 url: '/api2/json/access/ticket',
91 method: 'POST',
92 success: function(response, opts) {
93 var obj = Ext.decode(response.responseText);
94 me.updateLoginData(obj.data);
95 }
96 });
97 },
98 interval: 15*60*1000
99 });
100
101 }
102});
103
104Ext.define('PVE.ConsoleWorkspace', {
105 extend: 'PVE.Workspace',
106
107 alias: ['widget.pveConsoleWorkspace'],
108
109 title: gettext('Console'),
110
111 initComponent : function() {
112 var me = this;
113
114 var param = Ext.Object.fromQueryString(window.location.search);
115 var consoleType = me.consoleType || param.console;
116
117 param.novnc = (param.novnc === '1') ? true : false;
118
119 var content;
120 if (consoleType === 'kvm') {
121 me.title = "VM " + param.vmid;
122 if (param.vmname) {
123 me.title += " ('" + param.vmname + "')";
124 }
125 content = {
126 xtype: 'pveKVMConsole',
127 novnc: param.novnc,
128 vmid: param.vmid,
129 nodename: param.node,
130 vmname: param.vmname,
131 toplevel: true
132 };
133 } else if (consoleType === 'lxc') {
134 me.title = "CT " + param.vmid;
135 if (param.vmname) {
136 me.title += " ('" + param.vmname + "')";
137 }
138 content = {
139 xtype: 'pveLxcConsole',
140 novnc: param.novnc,
141 vmid: param.vmid,
142 nodename: param.node,
143 vmname: param.vmname,
144 toplevel: true
145 };
146 } else if (consoleType === 'shell') {
147 me.title = "node '" + param.node + "'";
148 content = {
149 xtype: 'pveShell',
150 novnc: param.novnc,
151 nodename: param.node,
152 toplevel: true
153 };
154 } else if (consoleType === 'upgrade') {
155 me.title = Ext.String.format(gettext('System upgrade on node {0}'), "'" + param.node + "'");
156 content = {
157 xtype: 'pveShell',
158 novnc: param.novnc,
159 nodename: param.node,
160 ugradeSystem: true,
161 toplevel: true
162 };
163 } else {
164 content = {
165 border: false,
166 bodyPadding: 10,
167 html: gettext('Error') + ': No such console type'
168 };
169 }
170
171 Ext.apply(me, {
172 layout: { type: 'fit' },
173 border: false,
174 items: [ content ]
175 });
176
177 me.callParent();
178 }
179});
180
181Ext.define('PVE.StdWorkspace', {
182 extend: 'PVE.Workspace',
183
184 alias: ['widget.pveStdWorkspace'],
185
186 // private
187 setContent: function(comp) {
188 var me = this;
189
190 var cont = me.child('#content');
834ba9e4
DC
191
192 var lay = cont.getLayout();
193
194 var cur = lay.getActiveItem();
787ae72a
DM
195
196 if (comp) {
197 PVE.Utils.setErrorMask(cont, false);
198 comp.border = false;
199 cont.add(comp);
834ba9e4
DC
200 if (cur !== null && lay.getNext()) {
201 lay.next();
202 var task = Ext.create('Ext.util.DelayedTask', function(){
203 cont.remove(cur);
204 });
205 task.delay(10);
206 }
207 }
787ae72a
DM
208 // else {
209 // TODO: display something useful
210
211 // Note:: error mask has wrong zindex, so we do not
212 // use that - see bug 114
213 // PVE.Utils.setErrorMask(cont, 'nothing selected');
214 //}
215 },
216
217 selectById: function(nodeid) {
218 var me = this;
219 var tree = me.down('pveResourceTree');
220 tree.selectById(nodeid);
221 },
222
223 checkVmMigration: function(record) {
224 var me = this;
225 var tree = me.down('pveResourceTree');
226 tree.checkVmMigration(record);
227 },
228
229 onLogin: function(loginData) {
230 var me = this;
231
232 me.updateUserInfo();
233
234 if (loginData) {
235 PVE.data.ResourceStore.startUpdate();
236
237 PVE.Utils.API2Request({
238 url: '/version',
239 method: 'GET',
240 success: function(response) {
241 PVE.VersionInfo = response.result.data;
242 me.updateVersionInfo();
243 }
244 });
245 }
246 },
247
248 updateUserInfo: function() {
249 var me = this;
250
251 var ui = me.query('#userinfo')[0];
252
253 if (PVE.UserName) {
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>');
256 } else {
257 ui.update('');
258 }
6a71fe01 259 ui.updateLayout();
787ae72a
DM
260 },
261
262 updateVersionInfo: function() {
263 var me = this;
264
265 var ui = me.query('#versioninfo')[0];
266
267 if (PVE.VersionInfo) {
268 var version = PVE.VersionInfo.version + '-' + PVE.VersionInfo.release + '/' +
269 PVE.VersionInfo.repoid;
f76884fd 270 ui.update('Proxmox Virtual Environment ' + version);
787ae72a 271 } else {
cbf55439 272 ui.update('Proxmox Virtual Environment');
787ae72a 273 }
6a71fe01 274 ui.updateLayout();
787ae72a
DM
275 },
276
277 initComponent : function() {
278 var me = this;
279
280 Ext.History.init();
281
282 var sprovider = Ext.create('PVE.StateProvider');
283 Ext.state.Manager.setProvider(sprovider);
284
aeb5e2f6 285 var selview = Ext.create('PVE.form.ViewSelector');
787ae72a
DM
286
287 var rtree = Ext.createWidget('pveResourceTree', {
288 viewFilter: selview.getViewFilter(),
289 flex: 1,
aeb5e2f6
EK
290 selModel: {
291 selType: 'treemodel',
787ae72a
DM
292 listeners: {
293 selectionchange: function(sm, selected) {
294 var comp;
295 var tlckup = {
296 root: 'PVE.dc.Config',
297 node: 'PVE.node.Config',
298 qemu: 'PVE.qemu.Config',
299 lxc: 'PVE.lxc.Config',
300 storage: 'PVE.storage.Browser',
301 pool: 'pvePoolConfig'
302 };
303
304 if (selected.length > 0) {
305 var n = selected[0];
306 comp = {
307 xtype: tlckup[n.data.type || 'root'] ||
308 'pvePanelConfig',
309 layout: { type: 'fit' },
310 showSearch: (n.data.id === 'root') ||
311 Ext.isDefined(n.data.groupbyid),
312 pveSelNode: n,
313 workspace: me,
314 viewFilter: selview.getViewFilter()
315 };
316 PVE.curSelectedNode = n;
317 }
318
319 me.setContent(comp);
320 }
321 }
aeb5e2f6 322 }
787ae72a
DM
323 });
324
325 selview.on('select', function(combo, records) {
fb387756 326 if (records) {
787ae72a
DM
327 var view = combo.getViewFilter();
328 rtree.setViewFilter(view);
329 }
330 });
331
332 var caps = sprovider.get('GuiCap');
333
334 var createVM = Ext.createWidget('button', {
335 pack: 'end',
f01259ee 336 margin: '3 5 0 0',
787ae72a 337 baseCls: 'x-btn',
d1f155b8 338 iconCls: 'fa fa-desktop',
787ae72a
DM
339 text: gettext("Create VM"),
340 disabled: !caps.vms['VM.Allocate'],
341 handler: function() {
342 var wiz = Ext.create('PVE.qemu.CreateWizard', {});
343 wiz.show();
344 }
345 });
346
347 var createCT = Ext.createWidget('button', {
348 pack: 'end',
f01259ee 349 margin: '3 5 0 0',
787ae72a 350 baseCls: 'x-btn',
d1f155b8 351 iconCls: 'fa fa-cube',
787ae72a
DM
352 text: gettext("Create CT"),
353 disabled: !caps.vms['VM.Allocate'],
354 handler: function() {
355 var wiz = Ext.create('PVE.lxc.CreateWizard', {});
356 wiz.show();
357 }
358 });
359
360 sprovider.on('statechange', function(sp, key, value) {
361 if (key === 'GuiCap' && value) {
362 caps = value;
363 createVM.setDisabled(!caps.vms['VM.Allocate']);
364 createCT.setDisabled(!caps.vms['VM.Allocate']);
365 }
366 });
367
368 Ext.apply(me, {
369 layout: { type: 'border' },
370 border: false,
371 items: [
372 {
373 region: 'north',
787ae72a
DM
374 layout: {
375 type: 'hbox',
f76884fd 376 align: 'middle'
787ae72a
DM
377 },
378 baseCls: 'x-plain',
379 defaults: {
380 baseCls: 'x-plain'
381 },
382 border: false,
f76884fd 383 margin: '2 0 2 5',
787ae72a
DM
384 items: [
385 {
787ae72a
DM
386 html: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
387 '<img height=30 width=209 src="/pve2/images/proxmox_logo.png"/></a>'
388 },
389 {
390 minWidth: 200,
391 flex: 1,
392 id: 'versioninfo',
5fc9bddb 393 html: 'Proxmox Virtual Environment'
787ae72a
DM
394 },
395 {
396 pack: 'end',
f76884fd 397 margin: '0 10 0 0',
787ae72a
DM
398 id: 'userinfo',
399 stateful: false
400 },
401 {
402 pack: 'end',
f76884fd 403 margin: '0 5 0 0',
787ae72a
DM
404 xtype: 'button',
405 baseCls: 'x-btn',
d1f155b8 406 iconCls: 'fa fa-sign-out',
787ae72a
DM
407 text: gettext("Logout"),
408 handler: function() {
409 PVE.data.ResourceStore.stopUpdate();
410 me.showLogin();
411 me.setContent();
412 var rt = me.down('pveResourceTree');
413 rt.clearTree();
414 }
415 },
416 createVM,
417 createCT
418 ]
419 },
420 {
421 region: 'center',
422 id: 'content',
423 xtype: 'container',
834ba9e4 424 layout: { type: 'card' },
787ae72a
DM
425 border: false,
426 stateful: false,
f01259ee 427 margin: '0 5 0 0',
787ae72a
DM
428 items: []
429 },
430 {
431 region: 'west',
432 xtype: 'container',
433 border: false,
434 layout: { type: 'vbox', align: 'stretch' },
f01259ee 435 margin: '0 0 0 5',
787ae72a
DM
436 split: true,
437 width: 200,
438 items: [ selview, rtree ]
439 },
440 {
80e8b725 441 xtype: 'pveStatusPanel',
787ae72a 442 region: 'south',
f01259ee 443 margin:'0 5 5 5',
787ae72a
DM
444 height: 200,
445 split:true
446 }
447 ]
448 });
449
450 me.callParent();
451
452 me.updateUserInfo();
453 }
454});
455