]> git.proxmox.com Git - pmg-gui.git/blob - js/RuleConfiguration.js
drop jslint hints
[pmg-gui.git] / js / RuleConfiguration.js
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 var me = this;
27 var infoPanel = me.lookupReference('infopanel');
28 var 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 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();
49 },
50 },
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: {
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 var me = this;
75 me.lookupReference('rulegrid').getStore().load();
76 },
77
78 addRule: function() {
79 var me = this;
80 var 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 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 },
112 failure: function(response, opts) {
113 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
114 },
115 });
116 },
117 );
118 },
119
120 init: function(view) {
121 var grid = this.lookupReference('rulegrid');
122 Proxmox.Utils.monStoreErrors(grid, grid.getStore(), true);
123 },
124
125 control: {
126 'grid[reference=rulegrid]': {
127 itemdblclick: 'showEditWindow',
128 selectionchange: 'selectedRuleChange',
129 },
130 'button[reference=addButton]': {
131 click: 'addRule',
132 },
133 },
134 },
135
136 viewModel: {
137 data: {
138 selectedRule: undefined,
139 baseUrl: '/config/ruledb/rules',
140 },
141 },
142
143 items: [
144 {
145 xtype: 'grid',
146 layout: 'fit',
147 title: 'Rules',
148 reference: 'rulegrid',
149 region: 'center',
150
151 bind: {
152 selection: '{selectedRule}',
153 },
154
155 dockedItems: {
156 xtype: 'toolbar',
157 reference: 'mytb',
158 items: [
159 {
160 xtype: 'button',
161 text: gettext('Add'),
162 iconCls: 'fa fa-plus-circle',
163 reference: 'addButton',
164 },
165 {
166 xtype: 'proxmoxStdRemoveButton',
167 text: gettext('Remove'),
168 iconCls: 'fa fa-minus-circle',
169 reference: 'removeButton',
170 callback: 'reload',
171 getRecordName: function(rec) { return rec.data.name; },
172 bind: {
173 baseurl: '{baseUrl}',
174 },
175 },
176 '->',
177 {
178 text: gettext('Factory Defaults'),
179 handler: 'onFactoryDefaults',
180 },
181 ],
182 },
183
184 viewConfig: {
185 getRowClass: function(record, rowIndex) {
186 return record.get('active') ? 'enabled' : 'disabled';
187 },
188 },
189
190 store: {
191 autoLoad: true,
192 model: 'pmg-rule-list',
193 reference: 'rulesStore',
194 proxy: {
195 type: 'proxmox',
196 url: '/api2/json/config/ruledb/rules',
197 },
198 sorters: [
199 {
200 property: 'priority',
201 direction: 'DESC',
202 },
203 {
204 property: 'name',
205 },
206 ],
207 },
208
209 sortableColumns: false,
210 columns: [
211 {
212 text: 'Active',
213 dataIndex: 'active',
214 hidden: true,
215 },
216 {
217 text: 'Name',
218 dataIndex: 'name',
219 flex: 1,
220 },
221 {
222 text: 'Priority',
223 dataIndex: 'priority',
224 },
225 {
226 text: 'Direction',
227 dataIndex: 'direction',
228 renderer: PMG.Utils.format_rule_direction,
229 },
230 {
231 text: '',
232 xtype: 'actioncolumn',
233 align: 'center',
234 width: 70,
235 items: [
236 {
237 iconCls: 'fa fa-fw fa-pencil',
238 tooltip: 'Edit',
239 handler: 'editIconClick',
240 },
241 {
242 getClass: function(val, meta, rec) {
243 return 'fa fa-fw fa-' + (rec.get('active') ? 'toggle-on' : 'toggle-off');
244 },
245 getTip: function(val, meta, rec) {
246 return rec.get('active') ? 'Deactivate' : 'Activate';
247 },
248 handler: 'toggleIconClick',
249 },
250 ],
251 },
252 ],
253 },
254 {
255 region: 'east',
256 reference: 'infopanel',
257 xtype: 'pmgRuleInfo',
258 split: true,
259 width: 440,
260 },
261 ],
262 });