]> git.proxmox.com Git - pve-manager.git/blob - www/manager/Workspace.js
update tree node if node attribute changes (vm migration)
[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 me.onLogin(loginData);
30 },
31
32 // private
33 showLogin: function() {
34 var me = this;
35
36 PVE.Utils.authClear();
37 PVE.UserName = null;
38 me.loginData = null;
39
40 if (!me.login) {
41 me.login = Ext.create('PVE.window.LoginWindow', {
42 handler: function(data) {
43 me.login = null;
44 me.updateLoginData(data);
45 }
46 });
47 }
48 me.onLogin(null);
49 me.login.show();
50 },
51
52 initComponent : function() {
53 var me = this;
54
55 Ext.tip.QuickTipManager.init();
56
57 // fixme: what about other errors
58 Ext.Ajax.on('requestexception', function(conn, response, options) {
59 if (response.status == 401) { // auth failure
60 me.showLogin();
61 }
62 });
63
64 document.title = me.title;
65
66 me.callParent();
67
68 if (!PVE.Utils.authOK()) {
69 me.showLogin();
70 } else {
71 if (me.loginData) {
72 me.onLogin(me.loginData);
73 }
74 }
75
76 Ext.TaskManager.start({
77 run: function() {
78 var ticket = PVE.Utils.authOK();
79 if (!ticket || !PVE.UserName) {
80 return;
81 }
82
83 Ext.Ajax.request({
84 params: {
85 username: PVE.UserName,
86 password: ticket
87 },
88 url: '/api2/json/access/ticket',
89 method: 'POST',
90 success: function(response, opts) {
91 // cookie is automatically updated
92 var obj = Ext.decode(response.responseText);
93 me.updateLoginData(obj.data);
94 }
95 });
96 },
97 interval: 15*60*1000
98 });
99
100 }
101 });
102
103 Ext.define('PVE.ConsoleWorkspace', {
104 extend: 'PVE.Workspace',
105 requires: [
106 'PVE.KVMConsole'
107 ],
108
109 alias: ['widget.pveConsoleWorkspace'],
110
111 title: 'Proxmox Console',
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;
122 content = {
123 xtype: 'pveKVMConsole',
124 vmid: param.vmid,
125 nodename: param.node,
126 toplevel: true
127 };
128 } else if (consoleType === 'shell') {
129 me.title = "node " + param.node + " - Proxmox Shell";
130 content = {
131 xtype: 'pveShell',
132 nodename: param.node,
133 toplevel: true
134 };
135 } else {
136 content = {
137 border: false,
138 bodyPadding: 10,
139 html: 'Error: No such console type'
140 };
141 }
142
143 Ext.apply(me, {
144 layout: { type: 'fit' },
145 border: false,
146 items: [ content ]
147 });
148
149 me.callParent();
150 }
151 });
152
153 Ext.define('PVE.StdWorkspace', {
154 extend: 'PVE.Workspace',
155 requires: [
156 'Ext.History',
157 'Ext.state.*',
158 'Ext.selection.*',
159 'PVE.form.ViewSelector',
160 'PVE.data.ResourceStore',
161 'PVE.tree.ResourceTree'
162 ],
163
164 alias: ['widget.pveStdWorkspace'],
165
166 // private
167 defaultContent: {
168 title: 'Nothing selected',
169 region: 'center'
170 },
171
172 setContent: function(comp) {
173 var me = this;
174
175 if (!comp) {
176 comp = me.defaultContent;
177 }
178
179 var cont = me.child('#content');
180 cont.removeAll(true);
181 cont.add(comp);
182 cont.doLayout();
183 },
184
185 selectById: function(nodeid) {
186 var me = this;
187 var tree = me.down('pveResourceTree');
188 tree.selectById(nodeid);
189 },
190
191 checkVmMigration: function(record) {
192 var me = this;
193 var tree = me.down('pveResourceTree');
194 tree.checkVmMigration(record);
195 },
196
197 onLogin: function(loginData) {
198 var me = this;
199
200 me.updateUserInfo();
201
202 if (loginData) {
203 PVE.data.ResourceStore.startUpdate();
204 }
205 },
206
207 updateUserInfo: function() {
208 var me = this;
209
210 var ui = me.query('#userinfo')[0];
211
212 if (PVE.UserName) {
213 ui.update('<div class="x-unselectable" style="white-space:nowrap;">You are logged in as "' + PVE.UserName + '"</div>');
214 } else {
215 ui.update('');
216 }
217 ui.doLayout();
218 },
219
220 initComponent : function() {
221 var me = this;
222
223 Ext.History.init();
224 Ext.state.Manager.setProvider(Ext.create('PVE.StateProvider'));
225
226 //document.title = ;
227
228 var selview = new PVE.form.ViewSelector({
229 listeners: {
230 select: function(combo, records) {
231 if (records && records.length) {
232 var view = combo.getViewFilter();
233 combo.up('pveResourceTree').setViewFilter(view);
234 }
235 }
236 }
237 });
238
239 var rtree = Ext.createWidget('pveResourceTree', {
240 width: 200,
241 region: 'west',
242 margins: '0 0 0 5',
243 split: true,
244 viewFilter: selview.getViewFilter(),
245 tbar: [ ' ', selview ],
246 selModel: new Ext.selection.TreeModel({
247 listeners: {
248 selectionchange: function(sm, selected) {
249 var comp;
250 var tlckup = {
251 root: 'PVE.dc.Config',
252 node: 'PVE.node.Config',
253 qemu: 'PVE.qemu.Config',
254 storage: 'PVE.storage.Browser'
255 };
256
257 if (selected.length > 0) {
258 var n = selected[0];
259 comp = {
260 xtype: tlckup[n.data.type || 'root'] ||
261 'PVE.panel.Config',
262 layout: { type: 'fit' },
263 showSearch: (n.data.id === 'root') ||
264 Ext.isDefined(n.data.groupbyid),
265 pveSelNode: n,
266 workspace: me,
267 viewFilter: selview.getViewFilter()
268 };
269 }
270
271 me.setContent(comp);
272 }
273 }
274 })
275 });
276
277 Ext.apply(me, {
278 layout: { type: 'border' },
279 border: false,
280 items: [
281 {
282 region: 'north',
283 height: 30,
284 layout: {
285 type: 'hbox',
286 align : 'middle'
287 },
288 baseCls: 'x-plain',
289 defaults: {
290 baseCls: 'x-plain'
291 },
292 border: false,
293 margins: '2 0 5 0',
294 items: [
295 {
296 margins: '0 0 0 4',
297 html: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
298 '<img height=30 width=209 src="/pve2/images/proxmox_logo.png"/></a>'
299 },
300 {
301 minWidth: 200,
302 flex: 1,
303 html: '<span class="x-panel-header-text">Proxmox Virtual Environment<br>Version ' + PVE.GUIVersion + "</span>"
304 },
305 {
306 pack: 'end',
307 margins: '8 10 0 10',
308 id: 'userinfo',
309 stateful: false
310 },
311 {
312 pack: 'end',
313 margins: '3 5 0 0',
314 xtype: 'button',
315 baseCls: 'x-btn',
316 text: "Logout",
317 handler: function() {
318 PVE.data.ResourceStore.stopUpdate();
319 me.showLogin();
320 me.setContent();
321 var rt = me.down('pveResourceTree');
322 rt.clearTree();
323 }
324 },
325 {
326 pack: 'end',
327 margins: '3 5 0 0',
328 xtype: 'button',
329 baseCls: 'x-btn',
330 text: "Create VM",
331 handler: function() {
332 var wiz = Ext.create('PVE.qemu.CreateWizard', {});
333 wiz.show();
334 }
335 },
336 {
337 pack: 'end',
338 margins: '3 5 0 0',
339 xtype: 'button',
340 baseCls: 'x-btn',
341 text: "Create CT",
342 handler: function() {
343 var wiz = Ext.create('PVE.openvz.CreateWizard', {});
344 wiz.show();
345 }
346 }
347 ]
348 },
349 {
350 region: 'center',
351 id: 'content',
352 xtype: 'panel',
353 layout: { type: 'fit' },
354 border: false,
355 stateful: false,
356 margins:'0 5 0 0',
357 items: [ me.defaultContent ]
358 },
359 rtree,
360 {
361 xtype: 'pveStatusPanel',
362 region: 'south',
363 margins:'0 5 5 5',
364 height: 200,
365 collapsible: true,
366 split:true
367 }
368 ]
369 });
370
371 me.callParent();
372
373 me.updateUserInfo();
374 }
375 });
376