]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/Workspace.js
ext6/triton: add some visual changes and fixes
[pve-manager.git] / www / manager6 / Workspace.js
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
9 Ext.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
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
104 Ext.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
181 Ext.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');
191 cont.removeAll(true);
192
193 if (comp) {
194 PVE.Utils.setErrorMask(cont, false);
195 comp.border = false;
196 cont.add(comp);
197 cont.updateLayout();
198 }
199 // else {
200 // TODO: display something useful
201
202 // Note:: error mask has wrong zindex, so we do not
203 // use that - see bug 114
204 // PVE.Utils.setErrorMask(cont, 'nothing selected');
205 //}
206 },
207
208 selectById: function(nodeid) {
209 var me = this;
210 var tree = me.down('pveResourceTree');
211 tree.selectById(nodeid);
212 },
213
214 checkVmMigration: function(record) {
215 var me = this;
216 var tree = me.down('pveResourceTree');
217 tree.checkVmMigration(record);
218 },
219
220 onLogin: function(loginData) {
221 var me = this;
222
223 me.updateUserInfo();
224
225 if (loginData) {
226 PVE.data.ResourceStore.startUpdate();
227
228 PVE.Utils.API2Request({
229 url: '/version',
230 method: 'GET',
231 success: function(response) {
232 PVE.VersionInfo = response.result.data;
233 me.updateVersionInfo();
234 }
235 });
236 }
237 },
238
239 updateUserInfo: function() {
240 var me = this;
241
242 var ui = me.query('#userinfo')[0];
243
244 if (PVE.UserName) {
245 var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + PVE.UserName + "'");
246 ui.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg + '</div>');
247 } else {
248 ui.update('');
249 }
250 ui.updateLayout();
251 },
252
253 updateVersionInfo: function() {
254 var me = this;
255
256 var ui = me.query('#versioninfo')[0];
257
258 if (PVE.VersionInfo) {
259 var version = PVE.VersionInfo.version + '-' + PVE.VersionInfo.release + '/' +
260 PVE.VersionInfo.repoid;
261 ui.update('Proxmox Virtual Environment<br>' + gettext('Version') + ': ' + version);
262 } else {
263 ui.update('Proxmox Virtual Environment');
264 }
265 ui.updateLayout();
266 },
267
268 initComponent : function() {
269 var me = this;
270
271 Ext.History.init();
272
273 var sprovider = Ext.create('PVE.StateProvider');
274 Ext.state.Manager.setProvider(sprovider);
275
276 var selview = Ext.create('PVE.form.ViewSelector');
277
278 var rtree = Ext.createWidget('pveResourceTree', {
279 viewFilter: selview.getViewFilter(),
280 flex: 1,
281 selModel: {
282 selType: 'treemodel',
283 listeners: {
284 selectionchange: function(sm, selected) {
285 var comp;
286 var tlckup = {
287 root: 'PVE.dc.Config',
288 node: 'PVE.node.Config',
289 qemu: 'PVE.qemu.Config',
290 lxc: 'PVE.lxc.Config',
291 storage: 'PVE.storage.Browser',
292 pool: 'pvePoolConfig'
293 };
294
295 if (selected.length > 0) {
296 var n = selected[0];
297 comp = {
298 xtype: tlckup[n.data.type || 'root'] ||
299 'pvePanelConfig',
300 layout: { type: 'fit' },
301 showSearch: (n.data.id === 'root') ||
302 Ext.isDefined(n.data.groupbyid),
303 pveSelNode: n,
304 workspace: me,
305 viewFilter: selview.getViewFilter()
306 };
307 PVE.curSelectedNode = n;
308 }
309
310 me.setContent(comp);
311 }
312 }
313 }
314 });
315
316 selview.on('select', function(combo, records) {
317 if (records) {
318 var view = combo.getViewFilter();
319 rtree.setViewFilter(view);
320 }
321 });
322
323 var caps = sprovider.get('GuiCap');
324
325 var createVM = Ext.createWidget('button', {
326 pack: 'end',
327 margin: '3 5 0 0',
328 baseCls: 'x-btn',
329 text: gettext("Create VM"),
330 disabled: !caps.vms['VM.Allocate'],
331 handler: function() {
332 var wiz = Ext.create('PVE.qemu.CreateWizard', {});
333 wiz.show();
334 }
335 });
336
337 var createCT = Ext.createWidget('button', {
338 pack: 'end',
339 margin: '3 5 0 0',
340 baseCls: 'x-btn',
341 text: gettext("Create CT"),
342 disabled: !caps.vms['VM.Allocate'],
343 handler: function() {
344 var wiz = Ext.create('PVE.lxc.CreateWizard', {});
345 wiz.show();
346 }
347 });
348
349 sprovider.on('statechange', function(sp, key, value) {
350 if (key === 'GuiCap' && value) {
351 caps = value;
352 createVM.setDisabled(!caps.vms['VM.Allocate']);
353 createCT.setDisabled(!caps.vms['VM.Allocate']);
354 }
355 });
356
357 Ext.apply(me, {
358 layout: { type: 'border' },
359 border: false,
360 items: [
361 {
362 region: 'north',
363 height: 30,
364 layout: {
365 type: 'hbox',
366 },
367 baseCls: 'x-plain',
368 defaults: {
369 baseCls: 'x-plain'
370 },
371 border: false,
372 height: 35,
373 margin: '2 0 5 0',
374 items: [
375 {
376 margin: '0 0 0 4',
377 html: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
378 '<img height=30 width=209 src="/pve2/images/proxmox_logo.png"/></a>'
379 },
380 {
381 minWidth: 200,
382 flex: 1,
383 id: 'versioninfo',
384 html: 'Proxmox Virtual Environment'
385 },
386 {
387 pack: 'end',
388 margin: '8 10 0 10',
389 id: 'userinfo',
390 stateful: false
391 },
392 {
393 pack: 'end',
394 margin: '3 5 0 0',
395 xtype: 'button',
396 baseCls: 'x-btn',
397 text: gettext("Logout"),
398 handler: function() {
399 PVE.data.ResourceStore.stopUpdate();
400 me.showLogin();
401 me.setContent();
402 var rt = me.down('pveResourceTree');
403 rt.clearTree();
404 }
405 },
406 createVM,
407 createCT
408 ]
409 },
410 {
411 region: 'center',
412 id: 'content',
413 xtype: 'container',
414 layout: { type: 'fit' },
415 border: false,
416 stateful: false,
417 margin: '0 5 0 0',
418 items: []
419 },
420 {
421 region: 'west',
422 xtype: 'container',
423 border: false,
424 layout: { type: 'vbox', align: 'stretch' },
425 margin: '0 0 0 5',
426 split: true,
427 width: 200,
428 items: [ selview, rtree ]
429 },
430 {
431 xtype: 'pveStatusPanel',
432 region: 'south',
433 margin:'0 5 5 5',
434 height: 200,
435 split:true
436 }
437 ]
438 });
439
440 me.callParent();
441
442 me.updateUserInfo();
443 }
444 });
445