]>
Commit | Line | Data |
---|---|---|
d75b37b8 DC |
1 | Ext.define('pmg-rule-list', { |
2 | extend: 'Ext.data.Model', | |
3 | fields: [ | |
4 | 'id', 'name', | |
5 | { name: 'active', type: 'boolean' }, | |
6 | { name: 'direction', type: 'integer' }, | |
c87d46fb | 7 | { name: 'priority', type: 'integer' }, |
d75b37b8 | 8 | ], |
c87d46fb | 9 | idProperty: 'id', |
d75b37b8 | 10 | }); |
f1e32362 | 11 | |
d75b37b8 DC |
12 | Ext.define('PMG.RulesConfiguration', { |
13 | extend: 'Ext.container.Container', | |
14 | xtype: 'pmgRuleConfiguration', | |
f1e32362 | 15 | |
d75b37b8 | 16 | layout: 'border', |
13fe6e87 | 17 | border: false, |
d75b37b8 | 18 | defaults: { |
c87d46fb | 19 | border: false, |
d75b37b8 DC |
20 | }, |
21 | ||
22 | controller: { | |
23 | xclass: 'Ext.app.ViewController', | |
24 | ||
25 | selectedRuleChange: function(grid, selected, eOpts) { | |
28eb60c0 TL |
26 | let me = this; |
27 | let infoPanel = me.lookupReference('infopanel'); | |
28 | let baseurl = ''; | |
d75b37b8 DC |
29 | |
30 | if (selected.length > 0) { | |
28eb60c0 | 31 | baseurl = `/config/ruledb/rules/${selected[0].data.id}`; |
d75b37b8 DC |
32 | } |
33 | ||
34 | infoPanel.getController().setBaseUrl(baseurl); | |
35 | }, | |
66636ecf | 36 | |
d75b37b8 | 37 | editIconClick: function(gridView, rowindex, colindex, column, e, record) { |
28eb60c0 | 38 | let me = this; |
d75b37b8 DC |
39 | me.showEditWindow(gridView, record); |
40 | }, | |
41 | ||
42 | showEditWindow: function(gridView, record) { | |
28eb60c0 TL |
43 | let me = this; |
44 | let win = Ext.create('PMG.RuleEditor', { | |
45 | url: `/api2/extjs/config/ruledb/rules/${record.data.id}/config`, | |
d75b37b8 DC |
46 | listeners: { |
47 | destroy: function() { | |
48 | gridView.getStore().load(); | |
c87d46fb TL |
49 | }, |
50 | }, | |
d75b37b8 DC |
51 | }); |
52 | win.load(); | |
53 | win.show(); | |
54 | }, | |
55 | ||
56 | toggleIconClick: function(gridView, rowindex, colindex, column, e, record) { | |
28eb60c0 | 57 | let me = this; |
d75b37b8 | 58 | Proxmox.Utils.API2Request({ |
28eb60c0 | 59 | url: `/config/ruledb/rules/${record.data.id}/config`, |
d75b37b8 | 60 | params: { |
c87d46fb | 61 | active: record.data.active ? 0 : 1, |
d75b37b8 DC |
62 | }, |
63 | method: 'PUT', | |
64 | callback: function() { | |
65 | gridView.getStore().load(); | |
66 | }, | |
67 | failure: function(response, opts) { | |
68 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
c87d46fb | 69 | }, |
d75b37b8 DC |
70 | }); |
71 | }, | |
72 | ||
c87d46fb | 73 | reload: function() { |
28eb60c0 | 74 | let me = this; |
d75b37b8 DC |
75 | me.lookupReference('rulegrid').getStore().load(); |
76 | }, | |
66636ecf | 77 | |
d75b37b8 | 78 | addRule: function() { |
28eb60c0 TL |
79 | let me = this; |
80 | let win = Ext.create('PMG.RuleEditor', { | |
d75b37b8 DC |
81 | url: '/api2/extjs/config/ruledb/rules/', |
82 | method: 'POST', | |
18b5b6ad | 83 | isCreate: true, |
d75b37b8 DC |
84 | listeners: { |
85 | destroy: function() { | |
86 | me.lookupReference('rulegrid').getStore().load(); | |
c87d46fb TL |
87 | }, |
88 | }, | |
d75b37b8 DC |
89 | }); |
90 | win.load(); | |
91 | win.show(); | |
92 | }, | |
ad834b6f | 93 | |
8fa824d4 | 94 | onFactoryDefaults: function() { |
28eb60c0 | 95 | let me = this; |
8fa824d4 DC |
96 | |
97 | Ext.Msg.confirm( | |
98 | gettext('Confirm'), | |
99 | gettext('Reset rule database to factory defaults?'), | |
100 | function(button) { | |
101 | if (button !== 'yes') { | |
102 | return; | |
103 | } | |
8fa824d4 DC |
104 | Proxmox.Utils.API2Request({ |
105 | url: '/config/ruledb', | |
106 | method: 'POST', | |
107 | waitMsgTarget: me.getView(), | |
108 | callback: function() { | |
109 | me.reload(); | |
110 | }, | |
c87d46fb | 111 | failure: function(response, opts) { |
8fa824d4 | 112 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); |
c87d46fb | 113 | }, |
8fa824d4 | 114 | }); |
c87d46fb | 115 | }, |
8fa824d4 DC |
116 | ); |
117 | }, | |
118 | ||
9114dc42 | 119 | init: function(view) { |
28eb60c0 | 120 | let grid = this.lookupReference('rulegrid'); |
2f8fe1a3 | 121 | Proxmox.Utils.monStoreErrors(grid, grid.getStore(), true); |
9114dc42 DM |
122 | }, |
123 | ||
d75b37b8 DC |
124 | control: { |
125 | 'grid[reference=rulegrid]': { | |
126 | itemdblclick: 'showEditWindow', | |
c87d46fb | 127 | selectionchange: 'selectedRuleChange', |
d75b37b8 DC |
128 | }, |
129 | 'button[reference=addButton]': { | |
c87d46fb TL |
130 | click: 'addRule', |
131 | }, | |
132 | }, | |
d75b37b8 DC |
133 | }, |
134 | ||
135 | viewModel: { | |
136 | data: { | |
137 | selectedRule: undefined, | |
c87d46fb TL |
138 | baseUrl: '/config/ruledb/rules', |
139 | }, | |
d75b37b8 | 140 | }, |
66636ecf | 141 | |
d75b37b8 DC |
142 | items: [ |
143 | { | |
144 | xtype: 'grid', | |
145 | layout: 'fit', | |
146 | title: 'Rules', | |
147 | reference: 'rulegrid', | |
148 | region: 'center', | |
149 | ||
150 | bind: { | |
c87d46fb | 151 | selection: '{selectedRule}', |
d75b37b8 DC |
152 | }, |
153 | ||
c87d46fb | 154 | dockedItems: { |
d75b37b8 DC |
155 | xtype: 'toolbar', |
156 | reference: 'mytb', | |
157 | items: [ | |
158 | { | |
159 | xtype: 'button', | |
160 | text: gettext('Add'), | |
161 | iconCls: 'fa fa-plus-circle', | |
c87d46fb | 162 | reference: 'addButton', |
d75b37b8 DC |
163 | }, |
164 | { | |
165 | xtype: 'proxmoxStdRemoveButton', | |
166 | text: gettext('Remove'), | |
167 | iconCls: 'fa fa-minus-circle', | |
168 | reference: 'removeButton', | |
169 | callback: 'reload', | |
131ba4f6 | 170 | getRecordName: function(rec) { return rec.data.name; }, |
d75b37b8 | 171 | bind: { |
c87d46fb TL |
172 | baseurl: '{baseUrl}', |
173 | }, | |
8fa824d4 DC |
174 | }, |
175 | '->', | |
176 | { | |
177 | text: gettext('Factory Defaults'), | |
c87d46fb TL |
178 | handler: 'onFactoryDefaults', |
179 | }, | |
180 | ], | |
d75b37b8 | 181 | }, |
66636ecf | 182 | |
d75b37b8 DC |
183 | viewConfig: { |
184 | getRowClass: function(record, rowIndex) { | |
185 | return record.get('active') ? 'enabled' : 'disabled'; | |
c87d46fb | 186 | }, |
d75b37b8 DC |
187 | }, |
188 | ||
189 | store: { | |
190 | autoLoad: true, | |
191 | model: 'pmg-rule-list', | |
192 | reference: 'rulesStore', | |
193 | proxy: { | |
194 | type: 'proxmox', | |
c87d46fb | 195 | url: '/api2/json/config/ruledb/rules', |
d75b37b8 DC |
196 | }, |
197 | sorters: [ | |
198 | { | |
199 | property: 'priority', | |
c87d46fb | 200 | direction: 'DESC', |
d75b37b8 DC |
201 | }, |
202 | { | |
c87d46fb TL |
203 | property: 'name', |
204 | }, | |
205 | ], | |
d75b37b8 DC |
206 | }, |
207 | ||
208 | sortableColumns: false, | |
209 | columns: [ | |
210 | { | |
211 | text: 'Active', | |
212 | dataIndex: 'active', | |
c87d46fb | 213 | hidden: true, |
d75b37b8 DC |
214 | }, |
215 | { | |
216 | text: 'Name', | |
217 | dataIndex: 'name', | |
c87d46fb | 218 | flex: 1, |
d75b37b8 DC |
219 | }, |
220 | { | |
221 | text: 'Priority', | |
c87d46fb | 222 | dataIndex: 'priority', |
d75b37b8 DC |
223 | }, |
224 | { | |
225 | text: 'Direction', | |
226 | dataIndex: 'direction', | |
c87d46fb | 227 | renderer: PMG.Utils.format_rule_direction, |
d75b37b8 DC |
228 | }, |
229 | { | |
1f639768 | 230 | text: '', |
d75b37b8 | 231 | xtype: 'actioncolumn', |
1f639768 DC |
232 | align: 'center', |
233 | width: 70, | |
d75b37b8 DC |
234 | items: [ |
235 | { | |
2b97521b | 236 | iconCls: 'fa fa-fw fa-pencil', |
d75b37b8 | 237 | tooltip: 'Edit', |
c87d46fb | 238 | handler: 'editIconClick', |
d75b37b8 DC |
239 | }, |
240 | { | |
241 | getClass: function(val, meta, rec) { | |
2b97521b | 242 | return 'fa fa-fw fa-' + (rec.get('active') ? 'toggle-on' : 'toggle-off'); |
d75b37b8 DC |
243 | }, |
244 | getTip: function(val, meta, rec) { | |
c87d46fb | 245 | return rec.get('active') ? 'Deactivate' : 'Activate'; |
d75b37b8 | 246 | }, |
c87d46fb TL |
247 | handler: 'toggleIconClick', |
248 | }, | |
249 | ], | |
250 | }, | |
251 | ], | |
d75b37b8 DC |
252 | }, |
253 | { | |
254 | region: 'east', | |
255 | reference: 'infopanel', | |
256 | xtype: 'pmgRuleInfo', | |
257 | split: true, | |
c87d46fb TL |
258 | width: 440, |
259 | }, | |
260 | ], | |
66636ecf | 261 | }); |