]> git.proxmox.com Git - pve-manager-legacy.git/blame - www/mobile/VMSummaryBase.js
mobile ui: eslint fixes
[pve-manager-legacy.git] / www / mobile / VMSummaryBase.js
CommitLineData
b46a5aa8
TL
1Ext.define('PVE.VMSummaryBase', {
2 extend: 'PVE.Page',
3
4 nodename: undefined,
5 vmid: undefined,
6 vmtype: undefined, // qemu or lxc
7
8 // defines the key/value config keys do display
9 config_keys: undefined,
10
11 vm_command: function(cmd, params) {
12 var me = this;
13
51d8307e 14 Proxmox.Utils.API2Request({
b46a5aa8
TL
15 params: params,
16 url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid +
17 '/status/' + cmd,
18 method: 'POST',
19 success: function(response, opts) {
20 var upid = response.result.data;
21 var page = 'nodes/' + me.nodename + '/tasks/' + upid;
22 PVE.Workspace.gotoPage(page);
23 },
24 failure: function(response, opts) {
25 Ext.Msg.alert('Error', response.htmlStatus);
f3b18589 26 },
b46a5aa8
TL
27 });
28 },
29
30 config: {
31 items: [
32 {
f3b18589 33 xtype: 'pveTitleBar',
b46a5aa8
TL
34 },
35 {
36 xtype: 'component',
37 itemId: 'vmstatus',
38 styleHtmlContent: true,
39 style: 'background-color:white;',
40 tpl: [
41 '<table style="margin-bottom:0px;">',
42 '<tr><td>Status:</td><td>{[this.status(values)]}</td></tr>',
43 '<tr><td>Memory:</td><td>{[this.meminfo(values)]}</td></tr>',
44 '<tr><td>CPU:</td><td>{[this.cpuinfo(values)]}</td></tr>',
42ec1872 45 '<tr><td>Uptime:</td><td>{[Proxmox.Utils.format_duration_long' +
b46a5aa8
TL
46 '(values.uptime)]}</td></tr>',
47 '</table>',
48 {
49 meminfo: function(values) {
50 if (!Ext.isDefined(values.mem)) {
51 return '-';
52 }
42ec1872
DC
53 return Proxmox.Utils.format_size(values.mem || 0) + " of " +
54 Proxmox.Utils.format_size(values.maxmem);
b46a5aa8
TL
55 },
56 cpuinfo: function(values) {
57 if (!Ext.isDefined(values.cpu)) {
58 return '-';
59 }
60 var per = values.cpu * 100;
61 return per.toFixed(2) + "% (" + values.cpus + " CPUs)";
62 },
63 status: function(values) {
f3b18589
TL
64 return values.qmpstatus ? values.qmpstatus
65 : values.status;
66 },
67 },
68 ],
b46a5aa8
TL
69 },
70 {
71 xtype: 'component',
72 cls: 'dark',
73 padding: 5,
f3b18589 74 html: gettext('Configuration'),
b46a5aa8
TL
75 },
76 {
77 xtype: 'container',
78 scrollable: 'both',
79 flex: 1,
80 styleHtmlContent: true,
81 itemId: 'vmconfig',
82 style: 'background-color:white;white-space:pre',
83 tpl: [
84 '<table style="margin-bottom:0px;">',
85 '<tpl for=".">',
86 '<tr><td>{key}</td><td>{value}</td></tr>',
87 '</tpl>',
f3b18589
TL
88 '</table>',
89 ],
90 },
91 ],
b46a5aa8
TL
92 },
93
94 reload: function() {
95 var me = this;
96
97 var vm_stat = me.down('#vmstatus');
98
99 var error_handler = function(response) {
100 me.setMasked({ xtype: 'loadmask', message: response.htmlStatus });
101 };
102
51d8307e 103 Proxmox.Utils.API2Request({
b46a5aa8
TL
104 url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid +
105 '/status/current',
106 method: 'GET',
107 success: function(response) {
108 var d = response.result.data;
109
110 me.render_menu(d);
111
112 vm_stat.setData(d);
113 },
f3b18589 114 failure: error_handler,
b46a5aa8
TL
115 });
116
117 var vm_cfg = me.down('#vmconfig');
118
51d8307e 119 Proxmox.Utils.API2Request({
b46a5aa8
TL
120 url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid +
121 '/config',
122 method: 'GET',
123 success: function(response) {
124 var d = response.result.data;
125 var kv = PVE.Workspace.obj_to_kv(d, me.config_keys);
126 vm_cfg.setData(kv);
127 },
f3b18589 128 failure: error_handler,
b46a5aa8
TL
129 });
130 },
131
132 render_menu: function(data) {
133 var me = this;
134
135 // use two item arrays for format reasons.
136 // display start, stop and migrate by default
137 var top_items = [
138 {
139 text: gettext('Start'),
140 handler: function() {
141 me.vm_command("start", {});
f3b18589 142 },
b46a5aa8
TL
143 },
144 {
145 text: gettext('Stop'),
146 handler: function() {
147 me.vm_command("stop", {});
f3b18589
TL
148 },
149 },
b46a5aa8
TL
150 ];
151
152 var bottom_items = [{
153 text: gettext('Migrate'),
154 handler: function() {
155 PVE.Workspace.gotoPage('nodes/' + me.nodename + '/' + me.vmtype +
156 '/' + me.vmid +'/migrate');
f3b18589 157 },
b46a5aa8
TL
158 }];
159
160 // use qmpstatus with qemu, as it's exacter
f3b18589 161 var vm_status = me.vmtype === 'qemu' ? data.qmpstatus : data.status;
b46a5aa8 162
f3b18589 163 if (vm_status === 'running') {
b46a5aa8
TL
164 top_items.push(
165 {
166 text: gettext('Shutdown'),
167 handler: function() {
168 me.vm_command("shutdown", {});
f3b18589 169 },
b46a5aa8
TL
170 },
171 {
172 text: gettext('Suspend'),
173 handler: function() {
174 me.vm_command("suspend", {});
f3b18589
TL
175 },
176 },
b46a5aa8
TL
177 );
178
179 bottom_items.push({
180 text: gettext('Console'),
181 handler: function() {
182 var vmtype = me.vmtype === 'qemu' ? 'kvm' : me.vmtype;
183 PVE.Utils.openConsoleWindow('html5', vmtype, me.vmid,
184 me.nodename);
f3b18589 185 },
b46a5aa8
TL
186 });
187
f3b18589 188 if (data.spice || me.vmtype==='lxc') {
b46a5aa8
TL
189 bottom_items.push({
190 text: gettext('Spice'),
191 handler: function() {
192 var vmtype = me.vmtype === 'qemu' ? 'kvm' : me.vmtype;
193 PVE.Utils.openConsoleWindow('vv', vmtype, me.vmid,
194 me.nodename);
f3b18589 195 },
b46a5aa8
TL
196 });
197 }
f3b18589 198 } else if (vm_status === 'paused') {
b46a5aa8
TL
199 top_items.push({
200 text: gettext('Resume'),
201 handler: function() {
202 me.vm_command("resume", {});
f3b18589 203 },
b46a5aa8
TL
204 });
205 }
206
207 // concat our item arrays and add them to the menu
208 me.down('pveMenuButton').setMenuItems(top_items.concat(bottom_items));
b46a5aa8
TL
209 },
210
211 initialize: function() {
212 var me = this;
213
214 me.reload();
215
216 this.callParent();
f3b18589 217 },
b46a5aa8 218});