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