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