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