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