]>
Commit | Line | Data |
---|---|---|
1774f148 DC |
1 | Ext.define('pve-security-groups', { |
2 | extend: 'Ext.data.Model', | |
3 | ||
4 | fields: [ 'group', 'comment', 'digest' ], | |
5 | idProperty: 'group' | |
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 | ||
15 | initComponent : function() { | |
8e4bf8c5 DM |
16 | var me = this; |
17 | ||
d5e771ce | 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'; | |
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 | ||
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', | |
48 | value: me.group_name | |
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, | |
8e4bf8c5 DM |
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 | ||
123e1c80 DC |
72 | stateful: true, |
73 | stateId: 'grid-securitygroups', | |
74 | ||
8e4bf8c5 DM |
75 | rule_panel: undefined, |
76 | ||
77 | addBtn: undefined, | |
78 | removeBtn: undefined, | |
79 | editBtn: undefined, | |
80 | ||
81 | base_url: "/cluster/firewall/groups", | |
82 | ||
83 | initComponent: function() { | |
8e4bf8c5 DM |
84 | var me = this; |
85 | ||
86 | if (me.rule_panel == undefined) { | |
87 | throw "no rule panel specified"; | |
88 | } | |
89 | ||
90 | if (me.base_url == undefined) { | |
91 | throw "no base_url specified"; | |
92 | } | |
93 | ||
94 | var store = new Ext.data.Store({ | |
1774f148 | 95 | model: 'pve-security-groups', |
8e4bf8c5 | 96 | proxy: { |
56a353b9 | 97 | type: 'proxmox', |
8e4bf8c5 DM |
98 | url: '/api2/json' + me.base_url |
99 | }, | |
8e4bf8c5 DM |
100 | sorters: { |
101 | property: 'group', | |
102 | order: 'DESC' | |
103 | } | |
104 | }); | |
105 | ||
106 | var sm = Ext.create('Ext.selection.RowModel', {}); | |
107 | ||
108 | var reload = function() { | |
109 | var oldrec = sm.getSelection()[0]; | |
110 | store.load(function(records, operation, success) { | |
111 | if (oldrec) { | |
112 | var rec = store.findRecord('group', oldrec.data.group); | |
113 | if (rec) { | |
114 | sm.select(rec); | |
115 | } | |
116 | } | |
117 | }); | |
118 | }; | |
119 | ||
120 | var run_editor = function() { | |
121 | var rec = sm.getSelection()[0]; | |
122 | if (!rec) { | |
123 | return; | |
124 | } | |
125 | var win = Ext.create('PVE.SecurityGroupEdit', { | |
126 | digest: rec.data.digest, | |
127 | group_name: rec.data.group, | |
128 | group_comment: rec.data.comment | |
129 | }); | |
130 | win.show(); | |
131 | win.on('destroy', reload); | |
132 | }; | |
133 | ||
5720fafa | 134 | me.editBtn = new Proxmox.button.Button({ |
8e4bf8c5 DM |
135 | text: gettext('Edit'), |
136 | disabled: true, | |
137 | selModel: sm, | |
138 | handler: run_editor | |
139 | }); | |
140 | ||
5720fafa | 141 | me.addBtn = new Proxmox.button.Button({ |
8e4bf8c5 DM |
142 | text: gettext('Create'), |
143 | handler: function() { | |
144 | sm.deselectAll(); | |
145 | var win = Ext.create('PVE.SecurityGroupEdit', {}); | |
146 | win.show(); | |
147 | win.on('destroy', reload); | |
148 | } | |
149 | }); | |
150 | ||
3b1ca3ff | 151 | me.removeBtn = Ext.create('Proxmox.button.StdRemoveButton', { |
8e4bf8c5 | 152 | selModel: sm, |
3b1ca3ff DC |
153 | baseurl: me.base_url + '/', |
154 | enableFn: function(rec) { | |
155 | return (rec && me.base_url); | |
156 | }, | |
157 | callback: function() { | |
158 | reload(); | |
8e4bf8c5 DM |
159 | } |
160 | }); | |
161 | ||
162 | Ext.apply(me, { | |
163 | store: store, | |
164 | tbar: [ '<b>' + gettext('Group') + ':</b>', me.addBtn, me.removeBtn, me.editBtn ], | |
165 | selModel: sm, | |
166 | columns: [ | |
123e1c80 | 167 | { header: gettext('Group'), dataIndex: 'group', width: '100' }, |
2eb0767b | 168 | { header: gettext('Comment'), dataIndex: 'comment', renderer: Ext.String.htmlEncode, flex: 1 } |
8e4bf8c5 DM |
169 | ], |
170 | listeners: { | |
171 | itemdblclick: run_editor, | |
172 | select: function(sm, rec) { | |
173 | var url = '/cluster/firewall/groups/' + rec.data.group; | |
174 | me.rule_panel.setBaseUrl(url); | |
175 | }, | |
176 | deselect: function() { | |
177 | me.rule_panel.setBaseUrl(undefined); | |
178 | }, | |
179 | show: reload | |
180 | } | |
181 | }); | |
182 | ||
183 | me.callParent(); | |
184 | ||
185 | store.load(); | |
186 | } | |
187 | }); | |
188 | ||
189 | Ext.define('PVE.SecurityGroups', { | |
190 | extend: 'Ext.panel.Panel', | |
191 | alias: 'widget.pveSecurityGroups', | |
192 | ||
193 | title: 'Security Groups', | |
194 | ||
195 | initComponent: function() { | |
196 | var me = this; | |
197 | ||
198 | var rule_panel = Ext.createWidget('pveFirewallRules', { | |
199 | region: 'center', | |
200 | allow_groups: false, | |
201 | list_refs_url: '/cluster/firewall/refs', | |
202 | tbar_prefix: '<b>' + gettext('Rules') + ':</b>', | |
8e4bf8c5 DM |
203 | border: false |
204 | }); | |
205 | ||
206 | var sglist = Ext.createWidget('pveSecurityGroupList', { | |
207 | region: 'west', | |
208 | rule_panel: rule_panel, | |
123e1c80 | 209 | width: '25%', |
8e4bf8c5 DM |
210 | border: false, |
211 | split: true | |
212 | }); | |
213 | ||
214 | ||
215 | Ext.apply(me, { | |
216 | layout: 'border', | |
217 | items: [ sglist, rule_panel ], | |
218 | listeners: { | |
219 | show: function() { | |
220 | sglist.fireEvent('show', sglist); | |
221 | } | |
222 | } | |
223 | }); | |
224 | ||
225 | me.callParent(); | |
226 | } | |
227 | }); |