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