]> git.proxmox.com Git - pmg-gui.git/blame - js/RuleInfo.js
change x-fa to fa
[pmg-gui.git] / js / RuleInfo.js
CommitLineData
ad834b6f 1Ext.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 {
c3339ea1
DC
304 header: gettext('Actions'),
305 xtype: 'actioncolumn',
306 width: 65,
307 items: [
308 {
2b97521b 309 iconCls: 'fa fa-fw fa-minus-circle',
c3339ea1
DC
310 tooltip: gettext('Remove'),
311 handler: 'removeIconClick'
312 }
313 ]
314 }
315 ],
316
317 bind: {
318 store: '{objects}',
319 hidden: '{!selectedRule}'
320 },
321 },
322 {
323 xtype: 'tabpanel',
324 title: gettext('Available Objects'),
325 reference: 'availobjects',
326 hidden: true,
327 bind: {
328 hidden: '{!selectedRule}'
329 },
330 defaults: {
331 xtype: 'grid',
332 emptyText: gettext('No Objects'),
333 viewConfig: {
334 plugins: {
335 ptype: 'gridviewdragdrop',
336 dragGroup: 'unusedobjects',
337 dropGroup: 'usedobjects',
338
339 // do not show default grid dragdrop behaviour
340 dropZone: {
341 indicatorHtml: '',
342 indicatorCls: '',
343 handleNodeDrop: Ext.emptyFn
344 }
f71626c2
DM
345 }
346 },
c3339ea1
DC
347 columns: [
348 {
349 header: gettext('Name'),
350 dataIndex: 'name',
351 flex: 1
352 },
353 {
354 header: gettext('Actions'),
355 width: 65,
356 xtype: 'actioncolumn',
357 items: [
358 {
2b97521b 359 iconCls: 'fa fa-fw fa-plus-circle',
c3339ea1
DC
360 tooltip: gettext('Add'),
361 handler: 'addIconClick'
ad834b6f 362 }
c3339ea1 363 ]
ad834b6f 364 }
c3339ea1
DC
365 ],
366 },
367 items: [
368 {
369 title: gettext('Action'),
370 bind: {
371 store: '{actionobjects}'
372 },
373 type: 'action',
374 iconCls: 'fa fa-flag',
ad834b6f 375 },
39700611 376 {
c3339ea1
DC
377 title: gettext('From'),
378 iconCls: 'fa fa-user-circle',
379 type: 'from',
380 bind: {
381 store: '{fromobjects}'
382 },
39700611 383 },
ad834b6f 384 {
c3339ea1
DC
385 title: gettext('To'),
386 iconCls: 'fa fa-user-circle',
387 type: 'to',
388 bind: {
389 store: '{toobjects}'
390 },
391 },
392 {
393 title: gettext('What'),
394 iconCls: 'fa fa-cube',
395 type: 'what',
396 bind: {
397 store: '{whatobjects}'
398 },
399 },
400 {
401 title: gettext('When'),
402 iconCls: 'fa fa-clock-o',
403 type: 'when',
404 bind: {
405 store: '{whenobjects}'
406 },
407 },
ad834b6f 408 ]
ad834b6f 409 }
c3339ea1 410 ]
ad834b6f 411});