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