]> git.proxmox.com Git - pve-manager.git/blob - www/manager/qemu/Config.js
fix bug #115: simplify GUI for users without permissions
[pve-manager.git] / www / manager / qemu / Config.js
1 Ext.define('PVE.qemu.Config', {
2 extend: 'PVE.panel.Config',
3 alias: 'widget.PVE.qemu.Config',
4
5 initComponent: function() {
6 var me = this;
7
8 var nodename = me.pveSelNode.data.node;
9 if (!nodename) {
10 throw "no node name specified";
11 }
12
13 var vmid = me.pveSelNode.data.vmid;
14 if (!vmid) {
15 throw "no VM ID specified";
16 }
17
18 var caps = Ext.state.Manager.get('GuiCap');
19
20 me.statusStore = Ext.create('PVE.data.ObjectStore', {
21 url: "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/status/current",
22 interval: 1000
23 });
24
25 var vm_command = function(cmd, params) {
26 PVE.Utils.API2Request({
27 params: params,
28 url: '/nodes/' + nodename + '/qemu/' + vmid + "/status/" + cmd,
29 waitMsgTarget: me,
30 method: 'POST',
31 failure: function(response, opts) {
32 Ext.Msg.alert('Error', response.htmlStatus);
33 }
34 });
35 };
36
37 var startBtn = Ext.create('Ext.Button', {
38 text: gettext('Start'),
39 disabled: !caps.vms['VM.PowerMgmt'],
40 handler: function() {
41 vm_command('start');
42 }
43 });
44
45 var stopBtn = Ext.create('PVE.button.Button', {
46 text: gettext('Stop'),
47 disabled: !caps.vms['VM.PowerMgmt'],
48 confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid),
49 handler: function() {
50 vm_command("stop", { timeout: 30 });
51 }
52 });
53
54 var migrateBtn = Ext.create('Ext.Button', {
55 text: gettext('Migrate'),
56 disabled: !caps.vms['VM.Migrate'],
57 handler: function() {
58 var win = Ext.create('PVE.window.Migrate', {
59 vmtype: 'qemu',
60 nodename: nodename,
61 vmid: vmid
62 });
63 win.show();
64 }
65 });
66
67 var resetBtn = Ext.create('PVE.button.Button', {
68 text: gettext('Reset'),
69 disabled: !caps.vms['VM.PowerMgmt'],
70 confirmMsg: Ext.String.format(gettext("Do you really want to reset VM {0}?"), vmid),
71 handler: function() {
72 vm_command("reset");
73 }
74 });
75
76 var shutdownBtn = Ext.create('PVE.button.Button', {
77 text: gettext('Shutdown'),
78 disabled: !caps.vms['VM.PowerMgmt'],
79 confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid),
80 handler: function() {
81 vm_command('shutdown', { timeout: 30 });
82 }
83 });
84
85 var removeBtn = Ext.create('PVE.button.Button', {
86 text: gettext('Remove'),
87 disabled: !caps.vms['VM.Allocate'],
88 confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid),
89 handler: function() {
90 PVE.Utils.API2Request({
91 url: '/nodes/' + nodename + '/qemu/' + vmid,
92 method: 'DELETE',
93 waitMsgTarget: me,
94 failure: function(response, opts) {
95 Ext.Msg.alert('Error', response.htmlStatus);
96 }
97 });
98 }
99 });
100
101 var vmname = me.pveSelNode.data.name;
102
103 var consoleBtn = Ext.create('Ext.Button', {
104 text: gettext('Console'),
105 disabled: !caps.vms['VM.Console'],
106 handler: function() {
107 PVE.Utils.openConoleWindow('kvm', vmid, nodename, vmname);
108 }
109 });
110
111 var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")";
112
113 Ext.apply(me, {
114 title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"),
115 hstateid: 'kvmtab',
116 tbar: [ startBtn, shutdownBtn, stopBtn, resetBtn,
117 removeBtn, migrateBtn, consoleBtn ],
118 defaults: { statusStore: me.statusStore },
119 items: [
120 {
121 title: gettext('Summary'),
122 xtype: 'pveQemuSummary',
123 itemId: 'summary'
124 },
125 {
126 title: gettext('Hardware'),
127 itemId: 'hardware',
128 xtype: 'PVE.qemu.HardwareView'
129 },
130 {
131 title: gettext('Options'),
132 itemId: 'options',
133 xtype: 'PVE.qemu.Options'
134 }
135 ]
136 });
137
138 if (caps.vms['VM.Monitor']) {
139 me.items.push({
140 title: gettext('Monitor'),
141 itemId: 'monitor',
142 xtype: 'pveQemuMonitor'
143 });
144 }
145
146 if (caps.vms['VM.Backup']) {
147 me.items.push({
148 title: gettext('Backup'),
149 xtype: 'pveBackupView',
150 itemId: 'backup'
151 });
152 }
153
154 if (caps.vms['Permissions.Modify']) {
155 me.items.push({
156 xtype: 'pveACLView',
157 title: gettext('Permissions'),
158 itemId: 'permissions',
159 path: '/vms/' + vmid
160 });
161 }
162
163 me.callParent();
164
165 me.statusStore.on('load', function(s, records, success) {
166 var status;
167 if (!success) {
168 me.workspace.checkVmMigration(me.pveSelNode);
169 status = 'unknown';
170 } else {
171 var rec = s.data.get('status');
172 status = rec ? rec.data.value : 'unknown';
173 }
174
175 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running');
176 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
177 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
178 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
179 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
180 });
181
182 me.on('afterrender', function() {
183 me.statusStore.startUpdate();
184 });
185
186 me.on('destroy', function() {
187 me.statusStore.stopUpdate();
188 });
189 }
190 });