]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/dc/SecurityGroups.js
26172bf359670b1f0664848633a32ecc5e96e048
[pve-manager.git] / www / manager6 / dc / SecurityGroups.js
1 Ext.define('pve-security-groups', {
2 extend: 'Ext.data.Model',
3
4 fields: ['group', 'comment', 'digest'],
5 idProperty: 'group',
6 });
7
8 Ext.define('PVE.SecurityGroupEdit', {
9 extend: 'Proxmox.window.Edit',
10
11 base_url: "/cluster/firewall/groups",
12
13 allow_iface: false,
14
15 initComponent: function() {
16 var me = this;
17
18 me.isCreate = me.group_name === undefined;
19
20 var subject;
21
22 me.url = '/api2/extjs' + me.base_url;
23 me.method = 'POST';
24
25 var items = [
26 {
27 xtype: 'textfield',
28 name: 'group',
29 value: me.group_name || '',
30 fieldLabel: gettext('Name'),
31 allowBlank: false,
32 },
33 {
34 xtype: 'textfield',
35 name: 'comment',
36 value: me.group_comment || '',
37 fieldLabel: gettext('Comment'),
38 },
39 ];
40
41 if (me.isCreate) {
42 subject = gettext('Security Group');
43 } else {
44 subject = gettext('Security Group') + " '" + me.group_name + "'";
45 items.push({
46 xtype: 'hiddenfield',
47 name: 'rename',
48 value: me.group_name,
49 });
50 }
51
52 var ipanel = Ext.create('Proxmox.panel.InputPanel', {
53 // InputPanel does not have a 'create' property, does it need a 'isCreate'
54 isCreate: me.isCreate,
55 items: items,
56 });
57
58
59 Ext.apply(me, {
60 subject: subject,
61 items: [ipanel],
62 });
63
64 me.callParent();
65 },
66 });
67
68 Ext.define('PVE.SecurityGroupList', {
69 extend: 'Ext.grid.Panel',
70 alias: 'widget.pveSecurityGroupList',
71
72 stateful: true,
73 stateId: 'grid-securitygroups',
74
75 rulePanel: undefined,
76
77 addBtn: undefined,
78 removeBtn: undefined,
79 editBtn: undefined,
80
81 base_url: "/cluster/firewall/groups",
82
83 initComponent: function() {
84 let me = this;
85 if (!me.base_url) {
86 throw "no base_url specified";
87 }
88
89 let store = new Ext.data.Store({
90 model: 'pve-security-groups',
91 proxy: {
92 type: 'proxmox',
93 url: '/api2/json' + me.base_url,
94 },
95 sorters: {
96 property: 'group',
97 direction: 'ASC',
98 },
99 });
100
101 let sm = Ext.create('Ext.selection.RowModel', {});
102
103 let reload = function() {
104 let oldrec = sm.getSelection()[0];
105 store.load((records, operation, success) => {
106 if (oldrec) {
107 let rec = store.findRecord('group', oldrec.data.group, 0, false, true, true);
108 if (rec) {
109 sm.select(rec);
110 }
111 }
112 });
113 };
114
115 let run_editor = function() {
116 let rec = sm.getSelection()[0];
117 if (!rec) {
118 return;
119 }
120 Ext.create('PVE.SecurityGroupEdit', {
121 digest: rec.data.digest,
122 group_name: rec.data.group,
123 group_comment: rec.data.comment,
124 listeners: {
125 destroy: () => reload(),
126 },
127 autoShow: true,
128 });
129 };
130
131 me.editBtn = new Proxmox.button.Button({
132 text: gettext('Edit'),
133 disabled: true,
134 selModel: sm,
135 handler: run_editor,
136 });
137 me.addBtn = new Proxmox.button.Button({
138 text: gettext('Create'),
139 handler: function() {
140 sm.deselectAll();
141 var win = Ext.create('PVE.SecurityGroupEdit', {});
142 win.show();
143 win.on('destroy', reload);
144 },
145 });
146
147 me.removeBtn = Ext.create('Proxmox.button.StdRemoveButton', {
148 selModel: sm,
149 baseurl: me.base_url + '/',
150 enableFn: function(rec) {
151 return rec && me.base_url;
152 },
153 callback: () => reload(),
154 });
155
156 Ext.apply(me, {
157 store: store,
158 tbar: ['<b>' + gettext('Group') + ':</b>', me.addBtn, me.removeBtn, me.editBtn],
159 selModel: sm,
160 columns: [
161 {
162 header: gettext('Group'),
163 dataIndex: 'group',
164 width: '100',
165 },
166 {
167 header: gettext('Comment'),
168 dataIndex: 'comment',
169 renderer: Ext.String.htmlEncode,
170 flex: 1,
171 },
172 ],
173 listeners: {
174 itemdblclick: run_editor,
175 select: function(_sm, rec) {
176 if (!me.rulePanel) {
177 me.rulePanel = me.up('panel').down('pveFirewallRules');
178 }
179 me.rulePanel.setBaseUrl(`/cluster/firewall/groups/${rec.data.group}`);
180 },
181 deselect: function() {
182 if (!me.rulePanel) {
183 me.rulePanel = me.up('panel').down('pveFirewallRules');
184 }
185 me.rulePanel.setBaseUrl(undefined);
186 },
187 show: reload,
188 },
189 });
190
191 me.callParent();
192
193 store.load();
194 },
195 });
196
197 Ext.define('PVE.SecurityGroups', {
198 extend: 'Ext.panel.Panel',
199 alias: 'widget.pveSecurityGroups',
200
201 title: 'Security Groups',
202 onlineHelp: 'pve_firewall_security_groups',
203
204 layout: 'border',
205
206 items: [
207 {
208 xtype: 'pveFirewallRules',
209 region: 'center',
210 allow_groups: false,
211 list_refs_url: '/cluster/firewall/refs',
212 tbar_prefix: '<b>' + gettext('Rules') + ':</b>',
213 border: false,
214 },
215 {
216 xtype: 'pveSecurityGroupList',
217 region: 'west',
218 width: '25%',
219 border: false,
220 split: true,
221 },
222 ],
223 listeners: {
224 show: function() {
225 let sglist = this.down('pveSecurityGroupList');
226 sglist.fireEvent('show', sglist);
227 },
228 },
229 });