]>
Commit | Line | Data |
---|---|---|
956d1b6e DM |
1 | Ext.define('PVE.qemu.Monitor', { |
2 | extend: 'Ext.panel.Panel', | |
3 | ||
4 | alias: 'widget.pveQemuMonitor', | |
5 | ||
6 | maxLines: 500, | |
7 | ||
8 | initComponent : function() { | |
9 | var me = this; | |
10 | ||
11 | var nodename = me.pveSelNode.data.node; | |
12 | if (!nodename) { | |
13 | throw "no node name specified"; | |
14 | } | |
15 | ||
16 | var vmid = me.pveSelNode.data.vmid; | |
17 | if (!vmid) { | |
18 | throw "no VM ID specified"; | |
19 | } | |
20 | ||
21 | var lines = []; | |
22 | ||
23 | var textbox = Ext.createWidget('panel', { | |
24 | region: 'center', | |
25 | xtype: 'panel', | |
26 | autoScroll: true, | |
27 | border: true, | |
28 | margins: '5 5 5 5', | |
da794fcf | 29 | bodyStyle: 'font-family: monospace;' |
956d1b6e DM |
30 | }); |
31 | ||
32 | var scrollToEnd = function() { | |
33 | var el = textbox.getTargetEl(); | |
34 | var dom = Ext.getDom(el); | |
da794fcf DM |
35 | |
36 | var clientHeight = dom.clientHeight; | |
37 | // BrowserBug: clientHeight reports 0 in IE9 StrictMode | |
38 | // Instead we are using offsetHeight and hardcoding borders | |
39 | if (Ext.isIE9 && Ext.isStrict) { | |
40 | clientHeight = dom.offsetHeight + 2; | |
41 | } | |
42 | dom.scrollTop = dom.scrollHeight - clientHeight; | |
a2f57991 | 43 | }; |
956d1b6e DM |
44 | |
45 | var refresh = function() { | |
da794fcf | 46 | textbox.update('<pre>' + lines.join('\n') + '</pre>'); |
956d1b6e DM |
47 | scrollToEnd(); |
48 | }; | |
49 | ||
50 | var addLine = function(line) { | |
51 | lines.push(line); | |
52 | if (lines.length > me.maxLines) { | |
53 | lines.shift(); | |
54 | } | |
55 | }; | |
56 | ||
57 | var executeCmd = function(cmd) { | |
58 | addLine("# " + Ext.htmlEncode(cmd)); | |
59 | refresh(); | |
60 | PVE.Utils.API2Request({ | |
61 | params: { command: cmd }, | |
62 | url: '/nodes/' + nodename + '/qemu/' + vmid + "/monitor", | |
63 | method: 'POST', | |
64 | waitMsgTarget: me, | |
65 | success: function(response, opts) { | |
66 | var res = response.result.data; | |
67 | Ext.Array.each(res.split('\n'), function(line) { | |
68 | addLine(Ext.htmlEncode(line)); | |
69 | }); | |
70 | refresh(); | |
71 | }, | |
72 | failure: function(response, opts) { | |
73 | Ext.Msg.alert('Error', response.htmlStatus); | |
74 | } | |
75 | }); | |
76 | }; | |
77 | ||
78 | Ext.apply(me, { | |
79 | layout: { type: 'border' }, | |
80 | border: false, | |
81 | items: [ | |
82 | textbox, | |
83 | { | |
84 | region: 'south', | |
85 | margins:'0 5 5 5', | |
86 | border: false, | |
87 | xtype: 'textfield', | |
88 | name: 'cmd', | |
89 | value: '', | |
90 | fieldStyle: 'font-family: monospace;', | |
91 | allowBlank: true, | |
92 | listeners: { | |
93 | afterrender: function(f) { | |
94 | f.focus(false); | |
95 | addLine("Type 'help' for help."); | |
96 | refresh(); | |
97 | }, | |
98 | specialkey: function(f, e) { | |
99 | if (e.getKey() === e.ENTER) { | |
100 | var cmd = f.getValue(); | |
101 | f.setValue(''); | |
102 | executeCmd(cmd); | |
103 | } | |
104 | } | |
105 | } | |
106 | } | |
107 | ], | |
108 | listeners: { | |
109 | show: function() { | |
110 | var field = me.query('textfield[name="cmd"]')[0]; | |
111 | field.focus(false, true); | |
112 | } | |
113 | } | |
114 | }); | |
115 | ||
116 | me.callParent(); | |
117 | } | |
118 | }); |