]> git.proxmox.com Git - pve-manager.git/blob - www/manager/Workspace.js
add panel for pools
[pve-manager.git] / www / manager / 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 requires: [
12 'Ext.tip.*',
13 'PVE.Utils',
14 'PVE.window.LoginWindow'
15 ],
16
17 title: 'Proxmox Virtual Environment',
18
19 loginData: null, // Data from last login call
20
21 onLogin: function(loginData) {},
22
23 // private
24 updateLoginData: function(loginData) {
25 var me = this;
26 me.loginData = loginData;
27 PVE.CSRFPreventionToken = loginData.CSRFPreventionToken;
28 PVE.UserName = loginData.username;
29 var expire = Ext.Date.add(new Date(), Ext.Date.HOUR, 2);
30 Ext.util.Cookies.set('PVEAuthCookie', loginData.ticket, expire);
31 me.onLogin(loginData);
32 },
33
34 // private
35 showLogin: function() {
36 var me = this;
37
38 PVE.Utils.authClear();
39 PVE.UserName = null;
40 me.loginData = null;
41
42 if (!me.login) {
43 me.login = Ext.create('PVE.window.LoginWindow', {
44 handler: function(data) {
45 me.login = null;
46 me.updateLoginData(data);
47 }
48 });
49 }
50 me.onLogin(null);
51 me.login.show();
52 },
53
54 initComponent : function() {
55 var me = this;
56
57 Ext.tip.QuickTipManager.init();
58
59 // fixme: what about other errors
60 Ext.Ajax.on('requestexception', function(conn, response, options) {
61 if (response.status == 401) { // auth failure
62 me.showLogin();
63 }
64 });
65
66 document.title = me.title;
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 requires: [
107 'PVE.KVMConsole'
108 ],
109
110 alias: ['widget.pveConsoleWorkspace'],
111
112 title: gettext('Console'),
113
114 initComponent : function() {
115 var me = this;
116
117 var param = Ext.Object.fromQueryString(window.location.search);
118 var consoleType = me.consoleType || param.console;
119
120 var content;
121 if (consoleType === 'kvm') {
122 me.title = "VM " + param.vmid;
123 if (param.vmname) {
124 me.title += " ('" + param.vmname + "')";
125 }
126 content = {
127 xtype: 'pveKVMConsole',
128 vmid: param.vmid,
129 nodename: param.node,
130 vmname: param.vmname,
131 toplevel: true
132 };
133 } else if (consoleType === 'openvz') {
134 me.title = "CT " + param.vmid;
135 if (param.vmname) {
136 me.title += " ('" + param.vmname + "')";
137 }
138 content = {
139 xtype: 'pveOpenVZConsole',
140 vmid: param.vmid,
141 nodename: param.node,
142 vmname: param.vmname,
143 toplevel: true
144 };
145 } else if (consoleType === 'shell') {
146 me.title = "node '" + param.node;
147 content = {
148 xtype: 'pveShell',
149 nodename: param.node,
150 toplevel: true
151 };
152 } else {
153 content = {
154 border: false,
155 bodyPadding: 10,
156 html: 'Error: No such console type'
157 };
158 }
159
160 Ext.apply(me, {
161 layout: { type: 'fit' },
162 border: false,
163 items: [ content ]
164 });
165
166 me.callParent();
167 }
168 });
169
170 Ext.define('PVE.StdWorkspace', {
171 extend: 'PVE.Workspace',
172
173 alias: ['widget.pveStdWorkspace'],
174
175 // private
176 setContent: function(comp) {
177 var me = this;
178
179 var cont = me.child('#content');
180 cont.removeAll(true);
181
182 if (comp) {
183 PVE.Utils.setErrorMask(cont, false);
184 comp.border = false;
185 cont.add(comp);
186 cont.doLayout();
187 } else {
188 PVE.Utils.setErrorMask(cont, 'nothing selected');
189 }
190 },
191
192 selectById: function(nodeid) {
193 var me = this;
194 var tree = me.down('pveResourceTree');
195 tree.selectById(nodeid);
196 },
197
198 checkVmMigration: function(record) {
199 var me = this;
200 var tree = me.down('pveResourceTree');
201 tree.checkVmMigration(record);
202 },
203
204 onLogin: function(loginData) {
205 var me = this;
206
207 me.updateUserInfo();
208
209 if (loginData) {
210 PVE.data.ResourceStore.startUpdate();
211 }
212 },
213
214 updateUserInfo: function() {
215 var me = this;
216
217 var ui = me.query('#userinfo')[0];
218
219 if (PVE.UserName) {
220 var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + PVE.UserName + "'");
221 ui.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg + '</div>');
222 } else {
223 ui.update('');
224 }
225 ui.doLayout();
226 },
227
228 initComponent : function() {
229 var me = this;
230
231 Ext.History.init();
232 Ext.state.Manager.setProvider(Ext.create('PVE.StateProvider'));
233
234 var selview = new PVE.form.ViewSelector({});
235
236 var rtree = Ext.createWidget('pveResourceTree', {
237 viewFilter: selview.getViewFilter(),
238 flex: 1,
239 selModel: new Ext.selection.TreeModel({
240 listeners: {
241 selectionchange: function(sm, selected) {
242 var comp;
243 var tlckup = {
244 root: 'PVE.dc.Config',
245 node: 'PVE.node.Config',
246 qemu: 'PVE.qemu.Config',
247 openvz: 'PVE.openvz.Config',
248 storage: 'PVE.storage.Browser',
249 pool: 'pvePoolConfig'
250 };
251
252 if (selected.length > 0) {
253 var n = selected[0];
254 comp = {
255 xtype: tlckup[n.data.type || 'root'] ||
256 'pvePanelConfig',
257 layout: { type: 'fit' },
258 showSearch: (n.data.id === 'root') ||
259 Ext.isDefined(n.data.groupbyid),
260 pveSelNode: n,
261 workspace: me,
262 viewFilter: selview.getViewFilter()
263 };
264 }
265
266 me.setContent(comp);
267 }
268 }
269 })
270 });
271
272 selview.on('select', function(combo, records) {
273 if (records && records.length) {
274 var view = combo.getViewFilter();
275 rtree.setViewFilter(view);
276 }
277 });
278
279 Ext.apply(me, {
280 layout: { type: 'border' },
281 border: false,
282 items: [
283 {
284 region: 'north',
285 height: 30,
286 layout: {
287 type: 'hbox',
288 align : 'middle'
289 },
290 baseCls: 'x-plain',
291 defaults: {
292 baseCls: 'x-plain'
293 },
294 border: false,
295 margins: '2 0 5 0',
296 items: [
297 {
298 margins: '0 0 0 4',
299 html: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
300 '<img height=30 width=209 src="/pve2/images/proxmox_logo.png"/></a>'
301 },
302 {
303 minWidth: 200,
304 flex: 1,
305 html: '<span class="x-panel-header-text">Proxmox Virtual Environment<br>' + gettext('Version') + ' ' + PVE.GUIVersion + "</span>"
306 },
307 {
308 pack: 'end',
309 margins: '8 10 0 10',
310 id: 'userinfo',
311 stateful: false
312 },
313 {
314 pack: 'end',
315 margins: '3 5 0 0',
316 xtype: 'button',
317 baseCls: 'x-btn',
318 text: gettext("Logout"),
319 handler: function() {
320 PVE.data.ResourceStore.stopUpdate();
321 me.showLogin();
322 me.setContent();
323 var rt = me.down('pveResourceTree');
324 rt.clearTree();
325 }
326 },
327 {
328 pack: 'end',
329 margins: '3 5 0 0',
330 xtype: 'button',
331 baseCls: 'x-btn',
332 text: gettext("Create VM"),
333 handler: function() {
334 var wiz = Ext.create('PVE.qemu.CreateWizard', {});
335 wiz.show();
336 }
337 },
338 {
339 pack: 'end',
340 margins: '3 5 0 0',
341 xtype: 'button',
342 baseCls: 'x-btn',
343 text: gettext("Create CT"),
344 handler: function() {
345 var wiz = Ext.create('PVE.openvz.CreateWizard', {});
346 wiz.show();
347 }
348 }
349 ]
350 },
351 {
352 region: 'center',
353 id: 'content',
354 xtype: 'container',
355 layout: { type: 'fit' },
356 border: false,
357 stateful: false,
358 margins: '0 5 0 0',
359 items: []
360 },
361 {
362 region: 'west',
363 xtype: 'container',
364 border: false,
365 layout: { type: 'vbox', align: 'stretch' },
366 margins: '0 0 0 5',
367 split: true,
368 width: 200,
369 items: [ selview, rtree ]
370 },
371 {
372 xtype: 'pveStatusPanel',
373 region: 'south',
374 margins:'0 5 5 5',
375 height: 200,
376 split:true
377 }
378 ]
379 });
380
381 me.callParent();
382
383 me.updateUserInfo();
384 }
385 });
386