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