]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Config.js
jslint: fix type confusion and property access
[pve-manager.git] / www / manager6 / lxc / Config.js
1 Ext.define('PVE.lxc.Config', {
2 extend: 'PVE.panel.Config',
3 alias: 'widget.PVE.lxc.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 template = me.pveSelNode.data.template;
19
20 var caps = Ext.state.Manager.get('GuiCap');
21
22 var base_url = '/nodes/' + nodename + '/lxc/' + vmid;
23
24 me.statusStore = Ext.create('PVE.data.ObjectStore', {
25 url: '/api2/json' + base_url + '/status/current',
26 interval: 1000
27 });
28
29 var vm_command = function(cmd, params) {
30 PVE.Utils.API2Request({
31 params: params,
32 url: base_url + "/status/" + cmd,
33 waitMsgTarget: me,
34 method: 'POST',
35 failure: function(response, opts) {
36 Ext.Msg.alert('Error', response.htmlStatus);
37 }
38 });
39 };
40
41 var startBtn = Ext.create('Ext.Button', {
42 text: gettext('Start'),
43 disabled: !caps.vms['VM.PowerMgmt'],
44 handler: function() {
45 vm_command('start');
46 },
47 iconCls: 'fa fa-play'
48 });
49
50 var umountBtn = Ext.create('Ext.Button', {
51 text: gettext('Unmount'),
52 disabled: true,
53 hidden: true,
54 handler: function() {
55 vm_command('umount');
56 }
57 });
58
59 var stopBtn = Ext.create('Ext.menu.Item',{
60 text: gettext('Stop'),
61 disabled: !caps.vms['VM.PowerMgmt'],
62 confirmMsg: PVE.Utils.format_task_description('vzstop', vmid),
63 dangerous: true,
64 handler: function() {
65 vm_command("stop");
66 },
67 iconCls: 'fa fa-stop'
68 });
69
70 var shutdownBtn = Ext.create('PVE.button.Split', {
71 text: gettext('Shutdown'),
72 disabled: !caps.vms['VM.PowerMgmt'],
73 confirmMsg: PVE.Utils.format_task_description('vzshutdown', vmid),
74 handler: function() {
75 vm_command('shutdown');
76 },
77 menu: {
78 items:[stopBtn]
79 },
80 iconCls: 'fa fa-power-off'
81 });
82
83 var migrateBtn = Ext.create('Ext.Button', {
84 text: gettext('Migrate'),
85 disabled: !caps.vms['VM.Migrate'],
86 handler: function() {
87 var win = Ext.create('PVE.window.Migrate', {
88 vmtype: 'lxc',
89 nodename: nodename,
90 vmid: vmid
91 });
92 win.show();
93 },
94 iconCls: 'fa fa-send-o'
95 });
96
97 var removeBtn = Ext.create('PVE.button.Button', {
98 text: gettext('Remove'),
99 disabled: !caps.vms['VM.Allocate'],
100 handler: function() {
101 Ext.create('PVE.window.SafeDestroy', {
102 url: base_url,
103 item: { type: 'CT', id: vmid }
104 }).show();
105 },
106 iconCls: 'fa fa-trash-o'
107 });
108
109 var vmname = me.pveSelNode.data.name;
110
111 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
112 disabled: !caps.vms['VM.Console'],
113 consoleType: 'lxc',
114 consoleName: vmname,
115 nodename: nodename,
116 vmid: vmid,
117 iconCls: 'fa fa-terminal'
118 });
119
120 var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'CT " + vmid + "'") + ")";
121
122 Ext.apply(me, {
123 title: Ext.String.format(gettext("Container {0} on node {1}"), descr, "'" + nodename + "'"),
124 hstateid: 'lxctab',
125 tbar: [ startBtn, shutdownBtn, umountBtn, removeBtn,
126 migrateBtn, consoleBtn ],
127 defaults: { statusStore: me.statusStore },
128 items: [
129 {
130 title: gettext('Summary'),
131 xtype: 'pveLxcSummary',
132 itemId: 'summary'
133 },
134 {
135 title: gettext('Resources'),
136 itemId: 'resources',
137 layout: 'fit',
138 plugins: {
139 ptype: 'lazyitems',
140 items: [{
141 xtype: 'pveLxcRessourceView',
142 pveSelNode: me.pveSelNode
143 }]
144 }
145 },
146 {
147 title: gettext('Network'),
148 itemId: 'network',
149 xtype: 'pveLxcNetworkView'
150 },
151 {
152 title: gettext('DNS'),
153 itemId: 'dns',
154 xtype: 'pveLxcDNS'
155 },
156 {
157 title: gettext('Options'),
158 itemId: 'options',
159 xtype: 'pveLxcOptions'
160 },
161 {
162 title: gettext('Task History'),
163 itemId: 'tasks',
164 xtype: 'pveNodeTasks',
165 vmidFilter: vmid
166 }
167 ]
168 });
169
170 if (caps.vms['VM.Backup']) {
171 me.items.push({
172 title: gettext('Backup'),
173 xtype: 'pveBackupView',
174 itemId: 'backup'
175 });
176 }
177
178 if (caps.vms['VM.Console']) {
179 me.items.push({
180 title: gettext('Console'),
181 itemId: 'console',
182 xtype: 'pveNoVncConsole',
183 vmid: vmid,
184 consoleType: 'lxc',
185 nodename: nodename
186 });
187 }
188
189 if (caps.vms['VM.Snapshot']) {
190 me.items.push({
191 title: gettext('Snapshots'),
192 xtype: 'pveLxcSnapshotTree',
193 itemId: 'snapshot'
194 });
195 }
196
197 if (caps.vms['VM.Console']) {
198 me.items.push(
199 {
200 xtype: 'pveFirewallPanel',
201 title: gettext('Firewall'),
202 base_url: base_url + '/firewall',
203 fwtype: 'vm',
204 phstateid: me.hstateid,
205 itemId: 'firewall'
206 }
207 );
208 }
209
210 if (caps.vms['Permissions.Modify']) {
211 me.items.push({
212 xtype: 'pveACLView',
213 title: gettext('Permissions'),
214 itemId: 'permissions',
215 path: '/vms/' + vmid
216 });
217 }
218
219 me.callParent();
220
221 me.mon(me.statusStore, 'load', function(s, records, success) {
222 var status;
223 if (!success) {
224 me.workspace.checkVmMigration(me.pveSelNode);
225 status = 'unknown';
226 } else {
227 var rec = s.data.get('status');
228 status = rec ? rec.data.value : 'unknown';
229 rec = s.data.get('template');
230 template = rec.data.value || false;
231 }
232 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
233 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
234 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
235 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
236 consoleBtn.setDisabled(template);
237
238 if (status === 'mounted') {
239 umountBtn.setDisabled(false);
240 umountBtn.setVisible(true);
241 stopBtn.setDisabled(true);
242 } else {
243 umountBtn.setDisabled(true);
244 umountBtn.setVisible(false);
245 stopBtn.setDisabled(false);
246 }
247 });
248
249 me.on('afterrender', function() {
250 me.statusStore.startUpdate();
251 });
252
253 me.on('destroy', function() {
254 me.statusStore.stopUpdate();
255 });
256 }
257 });