]> git.proxmox.com Git - pve-manager.git/blame - www/manager/Workspace.js
Added translations
[pve-manager.git] / www / manager / Workspace.js
CommitLineData
aff192e6
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',
aff192e6
DM
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;
8fb7d745
DM
24
25 if (loginData.cap) {
26 Ext.state.Manager.set('GuiCap', loginData.cap);
27 }
28
485dd03d
DM
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);
aff192e6
DM
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);
c576f184 48 PVE.Utils.checked_command(function() {}); // display subscription status
aff192e6
DM
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 document.title = me.title;
69
70 me.callParent();
71
72 if (!PVE.Utils.authOK()) {
73 me.showLogin();
74 } else {
75 if (me.loginData) {
76 me.onLogin(me.loginData);
77 }
78 }
79
80 Ext.TaskManager.start({
81 run: function() {
82 var ticket = PVE.Utils.authOK();
83 if (!ticket || !PVE.UserName) {
84 return;
85 }
86
87 Ext.Ajax.request({
88 params: {
89 username: PVE.UserName,
90 password: ticket
91 },
92 url: '/api2/json/access/ticket',
93 method: 'POST',
94 success: function(response, opts) {
aff192e6
DM
95 var obj = Ext.decode(response.responseText);
96 me.updateLoginData(obj.data);
97 }
98 });
99 },
100 interval: 15*60*1000
101 });
102
103 }
104});
105
106Ext.define('PVE.ConsoleWorkspace', {
107 extend: 'PVE.Workspace',
aff192e6
DM
108
109 alias: ['widget.pveConsoleWorkspace'],
110
7e6b14a8 111 title: gettext('Console'),
aff192e6
DM
112
113 initComponent : function() {
114 var me = this;
115
116 var param = Ext.Object.fromQueryString(window.location.search);
117 var consoleType = me.consoleType || param.console;
118
119 var content;
120 if (consoleType === 'kvm') {
121 me.title = "VM " + param.vmid;
fb3feb55
DM
122 if (param.vmname) {
123 me.title += " ('" + param.vmname + "')";
124 }
aff192e6
DM
125 content = {
126 xtype: 'pveKVMConsole',
127 vmid: param.vmid,
128 nodename: param.node,
fb3feb55 129 vmname: param.vmname,
1a7bfb86
DM
130 toplevel: true
131 };
132 } else if (consoleType === 'openvz') {
133 me.title = "CT " + param.vmid;
fb3feb55
DM
134 if (param.vmname) {
135 me.title += " ('" + param.vmname + "')";
136 }
1a7bfb86
DM
137 content = {
138 xtype: 'pveOpenVZConsole',
139 vmid: param.vmid,
140 nodename: param.node,
fb3feb55 141 vmname: param.vmname,
aff192e6
DM
142 toplevel: true
143 };
144 } else if (consoleType === 'shell') {
3a76893d 145 me.title = "node '" + param.node + "'";
aff192e6
DM
146 content = {
147 xtype: 'pveShell',
148 nodename: param.node,
149 toplevel: true
150 };
3a76893d
DM
151 } else if (consoleType === 'upgrade') {
152 me.title = Ext.String.format(gettext('System upgrade on node {0}'), "'" + param.node + "'");
153 content = {
154 xtype: 'pveShell',
155 nodename: param.node,
156 ugradeSystem: true,
157 toplevel: true
158 };
aff192e6
DM
159 } else {
160 content = {
161 border: false,
162 bodyPadding: 10,
0070ee37 163 html: gettext('Error: No such console type')
aff192e6
DM
164 };
165 }
166
167 Ext.apply(me, {
168 layout: { type: 'fit' },
169 border: false,
170 items: [ content ]
171 });
172
173 me.callParent();
174 }
175});
176
177Ext.define('PVE.StdWorkspace', {
178 extend: 'PVE.Workspace',
aff192e6
DM
179
180 alias: ['widget.pveStdWorkspace'],
181
182 // private
aff192e6
DM
183 setContent: function(comp) {
184 var me = this;
185
aff192e6
DM
186 var cont = me.child('#content');
187 cont.removeAll(true);
3732a665
DM
188
189 if (comp) {
524710d6 190 PVE.Utils.setErrorMask(cont, false);
3732a665
DM
191 comp.border = false;
192 cont.add(comp);
193 cont.doLayout();
42476072
DM
194 }
195 // else {
b3a1dbbb
DM
196 // TODO: display something useful
197
198 // Note:: error mask has wrong zindex, so we do not
199 // use that - see bug 114
200 // PVE.Utils.setErrorMask(cont, 'nothing selected');
42476072 201 //}
aff192e6
DM
202 },
203
204 selectById: function(nodeid) {
205 var me = this;
206 var tree = me.down('pveResourceTree');
207 tree.selectById(nodeid);
208 },
209
72482751 210 checkVmMigration: function(record) {
52df9bc1
DM
211 var me = this;
212 var tree = me.down('pveResourceTree');
72482751 213 tree.checkVmMigration(record);
52df9bc1
DM
214 },
215
aff192e6
DM
216 onLogin: function(loginData) {
217 var me = this;
218
219 me.updateUserInfo();
220
221 if (loginData) {
222 PVE.data.ResourceStore.startUpdate();
a7d04d71
DM
223
224 PVE.Utils.API2Request({
225 url: '/version',
226 method: 'GET',
227 success: function(response) {
228 PVE.VersionInfo = response.result.data;
229 me.updateVersionInfo();
230 }
231 });
aff192e6
DM
232 }
233 },
234
235 updateUserInfo: function() {
236 var me = this;
237
238 var ui = me.query('#userinfo')[0];
239
240 if (PVE.UserName) {
a2dca26b
DM
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>');
aff192e6
DM
243 } else {
244 ui.update('');
245 }
246 ui.doLayout();
247 },
248
a7d04d71
DM
249 updateVersionInfo: function() {
250 var me = this;
251
252 var ui = me.query('#versioninfo')[0];
253
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>");
258 } else {
259 ui.update('<span class="x-panel-header-text">Proxmox Virtual Environment</span>');
260 }
261 ui.doLayout();
262 },
263
aff192e6
DM
264 initComponent : function() {
265 var me = this;
266
267 Ext.History.init();
aff192e6 268
2840e622
DM
269 var sprovider = Ext.create('PVE.StateProvider');
270 Ext.state.Manager.setProvider(sprovider);
271
3732a665 272 var selview = new PVE.form.ViewSelector({});
aff192e6
DM
273
274 var rtree = Ext.createWidget('pveResourceTree', {
aff192e6 275 viewFilter: selview.getViewFilter(),
3732a665 276 flex: 1,
aff192e6
DM
277 selModel: new Ext.selection.TreeModel({
278 listeners: {
279 selectionchange: function(sm, selected) {
280 var comp;
281 var tlckup = {
282 root: 'PVE.dc.Config',
283 node: 'PVE.node.Config',
284 qemu: 'PVE.qemu.Config',
6521f904 285 openvz: 'PVE.openvz.Config',
0004edad
DM
286 storage: 'PVE.storage.Browser',
287 pool: 'pvePoolConfig'
aff192e6
DM
288 };
289
290 if (selected.length > 0) {
291 var n = selected[0];
292 comp = {
293 xtype: tlckup[n.data.type || 'root'] ||
524710d6 294 'pvePanelConfig',
aff192e6
DM
295 layout: { type: 'fit' },
296 showSearch: (n.data.id === 'root') ||
297 Ext.isDefined(n.data.groupbyid),
298 pveSelNode: n,
52df9bc1 299 workspace: me,
aff192e6
DM
300 viewFilter: selview.getViewFilter()
301 };
91b0d3c2 302 PVE.curSelectedNode = n;
aff192e6
DM
303 }
304
305 me.setContent(comp);
306 }
307 }
308 })
309 });
310
3732a665
DM
311 selview.on('select', function(combo, records) {
312 if (records && records.length) {
313 var view = combo.getViewFilter();
314 rtree.setViewFilter(view);
315 }
316 });
317
2840e622
DM
318 var caps = sprovider.get('GuiCap');
319
320 var createVM = Ext.createWidget('button', {
321 pack: 'end',
322 margins: '3 5 0 0',
323 baseCls: 'x-btn',
324 text: gettext("Create VM"),
325 disabled: !caps.vms['VM.Allocate'],
326 handler: function() {
327 var wiz = Ext.create('PVE.qemu.CreateWizard', {});
328 wiz.show();
329 }
330 });
331
332 var createCT = Ext.createWidget('button', {
333 pack: 'end',
334 margins: '3 5 0 0',
335 baseCls: 'x-btn',
336 text: gettext("Create CT"),
337 disabled: !caps.vms['VM.Allocate'],
338 handler: function() {
339 var wiz = Ext.create('PVE.openvz.CreateWizard', {});
340 wiz.show();
341 }
342 });
343
344 sprovider.on('statechange', function(sp, key, value) {
345 if (key === 'GuiCap' && value) {
346 caps = value;
347 createVM.setDisabled(!caps.vms['VM.Allocate']);
348 createCT.setDisabled(!caps.vms['VM.Allocate']);
349 }
350 });
351
aff192e6
DM
352 Ext.apply(me, {
353 layout: { type: 'border' },
354 border: false,
355 items: [
356 {
357 region: 'north',
358 height: 30,
359 layout: {
360 type: 'hbox',
361 align : 'middle'
362 },
363 baseCls: 'x-plain',
364 defaults: {
365 baseCls: 'x-plain'
366 },
367 border: false,
368 margins: '2 0 5 0',
369 items: [
370 {
371 margins: '0 0 0 4',
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>'
374 },
375 {
376 minWidth: 200,
377 flex: 1,
a7d04d71
DM
378 id: 'versioninfo',
379 html: '<span class="x-panel-header-text">Proxmox Virtual Environment</span>'
aff192e6
DM
380 },
381 {
382 pack: 'end',
383 margins: '8 10 0 10',
384 id: 'userinfo',
385 stateful: false
386 },
387 {
388 pack: 'end',
389 margins: '3 5 0 0',
390 xtype: 'button',
391 baseCls: 'x-btn',
a2dca26b 392 text: gettext("Logout"),
aff192e6
DM
393 handler: function() {
394 PVE.data.ResourceStore.stopUpdate();
395 me.showLogin();
396 me.setContent();
397 var rt = me.down('pveResourceTree');
398 rt.clearTree();
399 }
2840e622
DM
400 },
401 createVM,
402 createCT
aff192e6
DM
403 ]
404 },
405 {
406 region: 'center',
407 id: 'content',
3732a665 408 xtype: 'container',
aff192e6
DM
409 layout: { type: 'fit' },
410 border: false,
411 stateful: false,
3732a665
DM
412 margins: '0 5 0 0',
413 items: []
414 },
415 {
416 region: 'west',
417 xtype: 'container',
418 border: false,
419 layout: { type: 'vbox', align: 'stretch' },
420 margins: '0 0 0 5',
421 split: true,
422 width: 200,
423 items: [ selview, rtree ]
aff192e6 424 },
aff192e6
DM
425 {
426 xtype: 'pveStatusPanel',
427 region: 'south',
428 margins:'0 5 5 5',
429 height: 200,
aff192e6
DM
430 split:true
431 }
432 ]
433 });
434
435 me.callParent();
436
437 me.updateUserInfo();
438 }
439});
440