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