]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Config.js
hide irrelevant buttons and tabs for container templates
[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 onlineHelp: 'chapter_pct',
6
7 initComponent: function() {
8 var me = this;
9
10 var nodename = me.pveSelNode.data.node;
11 if (!nodename) {
12 throw "no node name specified";
13 }
14
15 var vmid = me.pveSelNode.data.vmid;
16 if (!vmid) {
17 throw "no VM ID specified";
18 }
19
20 var template = !!me.pveSelNode.data.template;
21
22 var running = !!me.pveSelNode.data.uptime;
23
24 var caps = Ext.state.Manager.get('GuiCap');
25
26 var base_url = '/nodes/' + nodename + '/lxc/' + vmid;
27
28 me.statusStore = Ext.create('Proxmox.data.ObjectStore', {
29 url: '/api2/json' + base_url + '/status/current',
30 interval: 1000
31 });
32
33 var vm_command = function(cmd, params) {
34 Proxmox.Utils.API2Request({
35 params: params,
36 url: base_url + "/status/" + cmd,
37 waitMsgTarget: me,
38 method: 'POST',
39 failure: function(response, opts) {
40 Ext.Msg.alert('Error', response.htmlStatus);
41 }
42 });
43 };
44
45 var startBtn = Ext.create('Ext.Button', {
46 text: gettext('Start'),
47 disabled: !caps.vms['VM.PowerMgmt'] || running,
48 hidden: template,
49 handler: function() {
50 vm_command('start');
51 },
52 iconCls: 'fa fa-play'
53 });
54
55 var stopBtn = Ext.create('Ext.menu.Item',{
56 text: gettext('Stop'),
57 disabled: !caps.vms['VM.PowerMgmt'],
58 confirmMsg: Proxmox.Utils.format_task_description('vzstop', vmid),
59 dangerous: true,
60 handler: function() {
61 vm_command("stop");
62 },
63 iconCls: 'fa fa-stop'
64 });
65
66 var shutdownBtn = Ext.create('PVE.button.Split', {
67 text: gettext('Shutdown'),
68 disabled: !caps.vms['VM.PowerMgmt'] || !running,
69 hidden: template,
70 confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid),
71 handler: function() {
72 vm_command('shutdown');
73 },
74 menu: {
75 items:[stopBtn]
76 },
77 iconCls: 'fa fa-power-off'
78 });
79
80 var migrateBtn = Ext.create('Ext.Button', {
81 text: gettext('Migrate'),
82 disabled: !caps.vms['VM.Migrate'],
83 hidden: PVE.data.ResourceStore.getNodes().length < 2,
84 handler: function() {
85 var win = Ext.create('PVE.window.Migrate', {
86 vmtype: 'lxc',
87 nodename: nodename,
88 vmid: vmid
89 });
90 win.show();
91 },
92 iconCls: 'fa fa-send-o'
93 });
94
95 var moreBtn = Ext.create('Proxmox.button.Button', {
96 text: gettext('More'),
97 menu: { items: [
98 {
99 text: gettext('Clone'),
100 iconCls: 'fa fa-fw fa-clone',
101 hidden: caps.vms['VM.Clone'] ? false : true,
102 handler: function() {
103 PVE.window.Clone.wrap(nodename, vmid, template, 'lxc');
104 }
105 },
106 {
107 text: gettext('Convert to template'),
108 disabled: template,
109 xtype: 'pveMenuItem',
110 iconCls: 'fa fa-fw fa-file-o',
111 hidden: caps.vms['VM.Allocate'] ? false : true,
112 confirmMsg: Proxmox.Utils.format_task_description('vztemplate', vmid),
113 handler: function() {
114 Proxmox.Utils.API2Request({
115 url: base_url + '/template',
116 waitMsgTarget: me,
117 method: 'POST',
118 failure: function(response, opts) {
119 Ext.Msg.alert('Error', response.htmlStatus);
120 }
121 });
122 }
123 },
124 {
125 iconCls: 'fa fa-heartbeat ',
126 hidden: !caps.nodes['Sys.Console'],
127 text: gettext('Manage HA'),
128 handler: function() {
129 var ha = me.pveSelNode.data.hastate;
130 Ext.create('PVE.ha.VMResourceEdit', {
131 vmid: vmid,
132 guestType: 'ct',
133 isCreate: (!ha || ha === 'unmanaged')
134 }).show();
135 }
136 },
137 {
138 text: gettext('Remove'),
139 disabled: !caps.vms['VM.Allocate'],
140 itemId: 'removeBtn',
141 handler: function() {
142 Ext.create('PVE.window.SafeDestroy', {
143 url: base_url,
144 item: { type: 'CT', id: vmid }
145 }).show();
146 },
147 iconCls: 'fa fa-trash-o'
148 }
149 ]}
150 });
151
152 var vm = me.pveSelNode.data;
153
154 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
155 disabled: !caps.vms['VM.Console'],
156 consoleType: 'lxc',
157 consoleName: vm.name,
158 hidden: template,
159 nodename: nodename,
160 vmid: vmid
161 });
162
163 Ext.apply(me, {
164 title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename),
165 hstateid: 'lxctab',
166 tbar: [ startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ],
167 defaults: { statusStore: me.statusStore },
168 items: [
169 {
170 title: gettext('Summary'),
171 xtype: 'pveLxcSummary',
172 iconCls: 'fa fa-book',
173 itemId: 'summary'
174 }
175 ]
176 });
177
178 if (caps.vms['VM.Console'] && !template) {
179 me.items.push(
180 {
181 title: gettext('Console'),
182 itemId: 'consolejs',
183 iconCls: 'fa fa-terminal',
184 xtype: 'pveNoVncConsole',
185 vmid: vmid,
186 consoleType: 'lxc',
187 xtermjs: true,
188 nodename: nodename
189 }
190 );
191 }
192
193 me.items.push(
194 {
195 title: gettext('Resources'),
196 itemId: 'resources',
197 expandedOnInit: true,
198 iconCls: 'fa fa-cube',
199 xtype: 'pveLxcRessourceView'
200 },
201 {
202 title: gettext('Network'),
203 iconCls: 'fa fa-exchange',
204 itemId: 'network',
205 xtype: 'pveLxcNetworkView'
206 },
207 {
208 title: gettext('DNS'),
209 iconCls: 'fa fa-globe',
210 itemId: 'dns',
211 xtype: 'pveLxcDNS'
212 },
213 {
214 title: gettext('Options'),
215 itemId: 'options',
216 iconCls: 'fa fa-gear',
217 xtype: 'pveLxcOptions'
218 },
219 {
220 title: gettext('Task History'),
221 itemId: 'tasks',
222 iconCls: 'fa fa-list',
223 xtype: 'proxmoxNodeTasks',
224 nodename: nodename,
225 vmidFilter: vmid
226 }
227 );
228
229 if (caps.vms['VM.Backup']) {
230 me.items.push({
231 title: gettext('Backup'),
232 iconCls: 'fa fa-floppy-o',
233 xtype: 'pveBackupView',
234 itemId: 'backup'
235 },
236 {
237 title: gettext('Replication'),
238 iconCls: 'fa fa-retweet',
239 xtype: 'pveReplicaView',
240 itemId: 'replication'
241 });
242 }
243
244 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) && !template) {
245 me.items.push({
246 title: gettext('Snapshots'),
247 iconCls: 'fa fa-history',
248 xtype: 'pveLxcSnapshotTree',
249 itemId: 'snapshot'
250 });
251 }
252
253 if (caps.vms['VM.Console']) {
254 me.items.push(
255 {
256 xtype: 'pveFirewallRules',
257 title: gettext('Firewall'),
258 iconCls: 'fa fa-shield',
259 allow_iface: true,
260 base_url: base_url + '/firewall/rules',
261 list_refs_url: base_url + '/firewall/refs',
262 itemId: 'firewall'
263 },
264 {
265 xtype: 'pveFirewallOptions',
266 groups: ['firewall'],
267 iconCls: 'fa fa-gear',
268 onlineHelp: 'pve_firewall_vm_container_configuration',
269 title: gettext('Options'),
270 base_url: base_url + '/firewall/options',
271 fwtype: 'vm',
272 itemId: 'firewall-options'
273 },
274 {
275 xtype: 'pveFirewallAliases',
276 title: gettext('Alias'),
277 groups: ['firewall'],
278 iconCls: 'fa fa-external-link',
279 base_url: base_url + '/firewall/aliases',
280 itemId: 'firewall-aliases'
281 },
282 {
283 xtype: 'pveIPSet',
284 title: gettext('IPSet'),
285 groups: ['firewall'],
286 iconCls: 'fa fa-list-ol',
287 base_url: base_url + '/firewall/ipset',
288 list_refs_url: base_url + '/firewall/refs',
289 itemId: 'firewall-ipset'
290 },
291 {
292 title: gettext('Log'),
293 groups: ['firewall'],
294 iconCls: 'fa fa-list',
295 onlineHelp: 'chapter_pve_firewall',
296 itemId: 'firewall-fwlog',
297 xtype: 'proxmoxLogView',
298 url: '/api2/extjs' + base_url + '/firewall/log'
299 }
300 );
301 }
302
303 if (caps.vms['Permissions.Modify']) {
304 me.items.push({
305 xtype: 'pveACLView',
306 title: gettext('Permissions'),
307 itemId: 'permissions',
308 iconCls: 'fa fa-unlock',
309 path: '/vms/' + vmid
310 });
311 }
312
313 me.callParent();
314
315 me.mon(me.statusStore, 'load', function(s, records, success) {
316 var status;
317 if (!success) {
318 status = 'unknown';
319 } else {
320 var rec = s.data.get('status');
321 status = rec ? rec.data.value : 'unknown';
322 rec = s.data.get('template');
323 template = rec.data.value || false;
324 }
325 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
326 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
327 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
328 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
329 consoleBtn.setDisabled(template);
330 });
331
332 me.on('afterrender', function() {
333 me.statusStore.startUpdate();
334 });
335
336 me.on('destroy', function() {
337 me.statusStore.stopUpdate();
338 });
339 }
340 });