]>
Commit | Line | Data |
---|---|---|
ad834b6f | 1 | Ext.define('PMG.RuleInfo', { |
c3339ea1 DC |
2 | extend: 'Ext.panel.Panel', |
3 | xtype: 'pmgRuleInfo', | |
ad834b6f | 4 | |
c3339ea1 DC |
5 | controller: { |
6 | xclass: 'Ext.app.ViewController', | |
ad834b6f | 7 | |
c3339ea1 DC |
8 | setBaseUrl: function(baseurl) { |
9 | var me = this; | |
10 | me.getViewModel().set('baseurl', baseurl); | |
11 | me.reload(); | |
12 | }, | |
ad834b6f | 13 | |
c3339ea1 DC |
14 | reload: function() { |
15 | var me = this; | |
16 | var viewmodel = me.getViewModel(); | |
17 | var baseurl = viewmodel.get('baseurl'); | |
ad834b6f | 18 | |
c3339ea1 DC |
19 | if (!baseurl) { |
20 | me.setRuleInfo(undefined); | |
21 | return; | |
22 | } | |
ad834b6f | 23 | |
c3339ea1 DC |
24 | Proxmox.Utils.API2Request({ |
25 | url: baseurl + "/config", | |
26 | method: 'GET', | |
27 | success: function(response, opts) { | |
28 | me.setRuleInfo(response.result.data); | |
29 | }, | |
c87d46fb | 30 | failure: function(response, opts) { |
c3339ea1 | 31 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); |
c87d46fb | 32 | }, |
c3339ea1 DC |
33 | }); |
34 | }, | |
ad834b6f | 35 | |
c3339ea1 DC |
36 | removeObjectGroup: function(rec) { |
37 | var me = this; | |
38 | Ext.Msg.confirm( | |
39 | gettext('Confirm'), | |
40 | Ext.String.format( | |
41 | gettext('Are you sure you want to remove entry {0}'), | |
42 | "'" + rec.data.name + "'"), | |
43 | function(button) { | |
44 | if (button === 'yes') { | |
45 | Proxmox.Utils.API2Request({ | |
46 | url: me.getViewModel().get('baseurl') + '/' + rec.data.oclass + '/'+ rec.data.typeid, | |
47 | method: 'DELETE', | |
48 | waitMsgTarget: me.getView(), | |
49 | callback: function() { | |
50 | me.reload(); | |
51 | }, | |
c87d46fb | 52 | failure: function(response, opts) { |
c3339ea1 | 53 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); |
c87d46fb | 54 | }, |
c3339ea1 DC |
55 | }); |
56 | } | |
c87d46fb | 57 | }, |
c3339ea1 DC |
58 | ); |
59 | }, | |
ad834b6f | 60 | |
c3339ea1 DC |
61 | addObjectGroup: function(type, record) { |
62 | var me = this; | |
63 | var baseurl = me.getViewModel().get('baseurl'); | |
64 | var url = baseurl + '/' + type; | |
c87d46fb | 65 | var id = type === 'action'?record.data.ogroup:record.data.id; |
c3339ea1 DC |
66 | Proxmox.Utils.API2Request({ |
67 | url: url, | |
68 | params: { ogroup: id }, | |
69 | method: 'POST', | |
70 | waitMsgTarget: me.getView(), | |
71 | callback: function() { | |
72 | me.reload(); | |
73 | }, | |
c87d46fb | 74 | failure: function(response, opts) { |
c3339ea1 | 75 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); |
c87d46fb | 76 | }, |
c3339ea1 DC |
77 | }); |
78 | }, | |
ad834b6f | 79 | |
c3339ea1 DC |
80 | setRuleInfo: function(ruledata) { |
81 | var me = this; | |
ad834b6f | 82 | |
c3339ea1 | 83 | var viewmodel = me.getViewModel(); |
ad834b6f | 84 | |
c3339ea1 | 85 | if (ruledata === undefined) { |
c3339ea1 DC |
86 | viewmodel.set('selectedRule', null); |
87 | viewmodel.get('objects').setData([]); | |
c3339ea1 | 88 | } else { |
c3339ea1 | 89 | viewmodel.set('selectedRule', ruledata); |
ad834b6f | 90 | |
c3339ea1 DC |
91 | var data = []; |
92 | Ext.Array.each(['from', 'to', 'when', 'what', 'action'], function(oc) { | |
c3339ea1 DC |
93 | var store = viewmodel.get(oc + 'objects'); |
94 | if (ruledata[oc] === undefined || store === undefined) { return; } | |
ad834b6f | 95 | |
c3339ea1 DC |
96 | // we build a filter for the objects, |
97 | // which are already added to the rule, | |
98 | // so what we only show the ones, | |
99 | // which are still available | |
ad834b6f | 100 | |
c3339ea1 DC |
101 | var ids = Ext.Array.pluck(ruledata[oc], 'id'); |
102 | // for the actions, we have a different id field | |
c87d46fb | 103 | var idField = oc === 'action'?'ogroup':'id'; |
c3339ea1 DC |
104 | store.clearFilter(); |
105 | store.addFilter({ | |
c87d46fb | 106 | filterFn: function(record) { |
c3339ea1 DC |
107 | // FIXME |
108 | // actions have the ogroup as a string | |
109 | // -> parseInt | |
c87d46fb TL |
110 | return ids.indexOf(parseInt(record.data[idField], 10)) === -1; |
111 | }, | |
c3339ea1 DC |
112 | }); |
113 | store.load(); | |
114 | Ext.Array.each(ruledata[oc], function(og) { | |
115 | data.push({ oclass: oc, name: og.name, typeid: og.id }); | |
116 | }); | |
ad834b6f | 117 | }); |
ad834b6f | 118 | |
c3339ea1 DC |
119 | viewmodel.get('objects').setData(data); |
120 | } | |
121 | }, | |
ad834b6f | 122 | |
c3339ea1 DC |
123 | removeIconClick: function(gridView, rowindex, colindex, button, event, record) { |
124 | var me = this; | |
125 | me.removeObjectGroup(record); | |
126 | }, | |
127 | ||
128 | removeDrop: function(gridView, data, overModel) { | |
129 | var me = this; | |
130 | var record = data.records[0]; // only one | |
131 | me.removeObjectGroup(record); | |
132 | return true; | |
133 | }, | |
ad834b6f | 134 | |
c3339ea1 DC |
135 | addIconClick: function(gridView, rowindex, colindex, button, event, record) { |
136 | var me = this; | |
137 | me.addObjectGroup(gridView.panel.type, record); | |
138 | return true; | |
139 | }, | |
ad834b6f | 140 | |
c3339ea1 DC |
141 | addDrop: function(gridView, data, overModel) { |
142 | var me = this; | |
143 | var record = data.records[0]; // only one | |
144 | me.addObjectGroup(data.view.panel.type, record); | |
145 | return true; | |
146 | }, | |
ad834b6f | 147 | |
c3339ea1 DC |
148 | control: { |
149 | 'grid[reference=usedobjects]': { | |
c87d46fb | 150 | drop: 'addDrop', |
ad834b6f | 151 | }, |
c3339ea1 | 152 | 'tabpanel[reference=availobjects] > grid': { |
c87d46fb TL |
153 | drop: 'removeDrop', |
154 | }, | |
155 | }, | |
c3339ea1 | 156 | }, |
ad834b6f | 157 | |
c3339ea1 DC |
158 | viewModel: { |
159 | data: { | |
c87d46fb | 160 | baseurl: '', |
c3339ea1 | 161 | }, |
ad834b6f | 162 | |
c3339ea1 DC |
163 | stores: { |
164 | objects: { | |
165 | fields: ['oclass', 'name', 'typeid'], | |
166 | groupField: 'oclass', | |
c87d46fb | 167 | sorters: 'name', |
ad834b6f | 168 | }, |
ad834b6f | 169 | |
c3339ea1 DC |
170 | actionobjects: { |
171 | model: 'pmg-action-list', | |
172 | proxy: { | |
173 | type: 'proxmox', | |
c87d46fb | 174 | url: "/api2/json/config/ruledb/action/objects", |
f71626c2 | 175 | }, |
c87d46fb | 176 | sorters: 'name', |
c3339ea1 DC |
177 | }, |
178 | fromobjects: { | |
179 | model: 'pmg-object-group', | |
180 | proxy: { | |
181 | type: 'proxmox', | |
c87d46fb | 182 | url: "/api2/json/config/ruledb/who", |
c3339ea1 | 183 | }, |
c87d46fb | 184 | sorters: 'name', |
c3339ea1 DC |
185 | }, |
186 | toobjects: { | |
187 | model: 'pmg-object-group', | |
188 | proxy: { | |
189 | type: 'proxmox', | |
c87d46fb | 190 | url: "/api2/json/config/ruledb/who", |
c3339ea1 | 191 | }, |
c87d46fb | 192 | sorters: 'name', |
c3339ea1 DC |
193 | }, |
194 | whatobjects: { | |
195 | model: 'pmg-object-group', | |
196 | proxy: { | |
197 | type: 'proxmox', | |
c87d46fb | 198 | url: "/api2/json/config/ruledb/what", |
c3339ea1 | 199 | }, |
c87d46fb | 200 | sorters: 'name', |
c3339ea1 DC |
201 | }, |
202 | whenobjects: { | |
203 | model: 'pmg-object-group', | |
204 | proxy: { | |
205 | type: 'proxmox', | |
c87d46fb | 206 | url: "/api2/json/config/ruledb/when", |
c3339ea1 | 207 | }, |
c87d46fb TL |
208 | sorters: 'name', |
209 | }, | |
210 | }, | |
c3339ea1 DC |
211 | }, |
212 | ||
213 | ||
214 | defaults: { | |
c87d46fb | 215 | padding: '5 10 5 10', |
c3339ea1 DC |
216 | }, |
217 | ||
218 | bodyPadding: '5 0 5 0', | |
219 | ||
220 | layout: { | |
221 | type: 'vbox', | |
c87d46fb | 222 | align: 'stretch', |
c3339ea1 DC |
223 | }, |
224 | ||
225 | scrollable: true, | |
226 | ||
227 | items: [ | |
228 | { | |
229 | xtype: 'panel', | |
ea07c9aa | 230 | bodyPadding: '10 10 10 10', |
c3339ea1 | 231 | data: { |
c87d46fb | 232 | name: '', |
c3339ea1 DC |
233 | }, |
234 | bind: { | |
235 | data: { | |
df2a647a | 236 | name: '{selectedRule.name:htmlEncode}', |
c3339ea1 DC |
237 | priority: '{selectedRule.priority}', |
238 | active: '{selectedRule.active}', | |
239 | direction: '{selectedRule.direction}', | |
c87d46fb TL |
240 | selected: '{selectedRule}', |
241 | }, | |
c3339ea1 DC |
242 | }, |
243 | tpl: [ | |
244 | '<tpl if="selected">', | |
245 | '<b>{name}</b><br><br>', | |
64fb657f DC |
246 | gettext('Priority') + ': {priority}<br>', |
247 | gettext('Direction') + ': {[PMG.Utils.format_rule_direction(values.direction)]}<br>', | |
248 | gettext('Active') + ': {[Proxmox.Utils.format_boolean(values.active)]}<br>', | |
c3339ea1 DC |
249 | '<tpl else>', |
250 | gettext('Please select a rule.'), | |
c87d46fb TL |
251 | '</tpl>', |
252 | ], | |
c3339ea1 DC |
253 | }, |
254 | { | |
255 | xtype: 'grid', | |
256 | reference: 'usedobjects', | |
257 | hidden: true, | |
258 | emptyText: gettext('No Objects'), | |
259 | features: [{ | |
260 | id: 'group', | |
261 | ftype: 'grouping', | |
262 | enableGroupingMenu: false, | |
263 | collapsible: false, | |
264 | groupHeaderTpl: [ | |
c87d46fb TL |
265 | '{[PMG.Utils.format_oclass(values.name)]}', |
266 | ], | |
c3339ea1 | 267 | }], |
f71626c2 | 268 | |
c3339ea1 | 269 | title: gettext('Used Objects'), |
ad834b6f | 270 | |
c3339ea1 DC |
271 | viewConfig: { |
272 | plugins: { | |
273 | ptype: 'gridviewdragdrop', | |
274 | copy: true, | |
275 | dragGroup: 'usedobjects', | |
276 | dropGroup: 'unusedobjects', | |
277 | ||
278 | // do not show default grid dragdrop behaviour | |
279 | dropZone: { | |
280 | indicatorHtml: '', | |
281 | indicatorCls: '', | |
c87d46fb TL |
282 | handleNodeDrop: Ext.emptyFn, |
283 | }, | |
284 | }, | |
c3339ea1 DC |
285 | }, |
286 | ||
287 | columns: [ | |
288 | { | |
289 | header: gettext('Type'), | |
290 | dataIndex: 'oclass', | |
c87d46fb | 291 | hidden: true, |
f71626c2 DM |
292 | }, |
293 | { | |
c3339ea1 DC |
294 | header: gettext('Name'), |
295 | dataIndex: 'name', | |
c87d46fb | 296 | flex: 1, |
f71626c2 DM |
297 | }, |
298 | { | |
1f639768 | 299 | text: '', |
c3339ea1 | 300 | xtype: 'actioncolumn', |
1f639768 DC |
301 | align: 'center', |
302 | width: 40, | |
c3339ea1 DC |
303 | items: [ |
304 | { | |
2b97521b | 305 | iconCls: 'fa fa-fw fa-minus-circle', |
c3339ea1 | 306 | tooltip: gettext('Remove'), |
c87d46fb TL |
307 | handler: 'removeIconClick', |
308 | }, | |
309 | ], | |
310 | }, | |
c3339ea1 DC |
311 | ], |
312 | ||
313 | bind: { | |
314 | store: '{objects}', | |
c87d46fb TL |
315 | hidden: '{!selectedRule}', |
316 | }, | |
c3339ea1 DC |
317 | }, |
318 | { | |
319 | xtype: 'tabpanel', | |
320 | title: gettext('Available Objects'), | |
321 | reference: 'availobjects', | |
322 | hidden: true, | |
323 | bind: { | |
c87d46fb | 324 | hidden: '{!selectedRule}', |
c3339ea1 DC |
325 | }, |
326 | defaults: { | |
327 | xtype: 'grid', | |
328 | emptyText: gettext('No Objects'), | |
329 | viewConfig: { | |
330 | plugins: { | |
331 | ptype: 'gridviewdragdrop', | |
332 | dragGroup: 'unusedobjects', | |
333 | dropGroup: 'usedobjects', | |
334 | ||
335 | // do not show default grid dragdrop behaviour | |
336 | dropZone: { | |
337 | indicatorHtml: '', | |
338 | indicatorCls: '', | |
c87d46fb TL |
339 | handleNodeDrop: Ext.emptyFn, |
340 | }, | |
341 | }, | |
f71626c2 | 342 | }, |
c3339ea1 DC |
343 | columns: [ |
344 | { | |
345 | header: gettext('Name'), | |
346 | dataIndex: 'name', | |
c87d46fb | 347 | flex: 1, |
c3339ea1 DC |
348 | }, |
349 | { | |
1f639768 | 350 | text: '', |
c3339ea1 | 351 | xtype: 'actioncolumn', |
1f639768 DC |
352 | align: 'center', |
353 | width: 40, | |
c3339ea1 DC |
354 | items: [ |
355 | { | |
2b97521b | 356 | iconCls: 'fa fa-fw fa-plus-circle', |
c3339ea1 | 357 | tooltip: gettext('Add'), |
c87d46fb TL |
358 | handler: 'addIconClick', |
359 | }, | |
360 | ], | |
361 | }, | |
362 | ], | |
c3339ea1 DC |
363 | }, |
364 | items: [ | |
365 | { | |
366 | title: gettext('Action'), | |
367 | bind: { | |
c87d46fb | 368 | store: '{actionobjects}', |
c3339ea1 DC |
369 | }, |
370 | type: 'action', | |
c87d46fb | 371 | iconCls: 'fa fa-flag', |
ad834b6f | 372 | }, |
39700611 | 373 | { |
c3339ea1 DC |
374 | title: gettext('From'), |
375 | iconCls: 'fa fa-user-circle', | |
376 | type: 'from', | |
377 | bind: { | |
c87d46fb TL |
378 | store: '{fromobjects}', |
379 | }, | |
39700611 | 380 | }, |
ad834b6f | 381 | { |
c3339ea1 DC |
382 | title: gettext('To'), |
383 | iconCls: 'fa fa-user-circle', | |
384 | type: 'to', | |
385 | bind: { | |
c87d46fb TL |
386 | store: '{toobjects}', |
387 | }, | |
c3339ea1 DC |
388 | }, |
389 | { | |
390 | title: gettext('What'), | |
391 | iconCls: 'fa fa-cube', | |
392 | type: 'what', | |
393 | bind: { | |
c87d46fb TL |
394 | store: '{whatobjects}', |
395 | }, | |
c3339ea1 DC |
396 | }, |
397 | { | |
398 | title: gettext('When'), | |
399 | iconCls: 'fa fa-clock-o', | |
400 | type: 'when', | |
401 | bind: { | |
c87d46fb TL |
402 | store: '{whenobjects}', |
403 | }, | |
404 | }, | |
405 | ], | |
406 | }, | |
407 | ], | |
ad834b6f | 408 | }); |