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