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