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