]> git.proxmox.com Git - pmg-gui.git/blame - js/UserBlackWhiteList.js
limit userlist to the respective list
[pmg-gui.git] / js / UserBlackWhiteList.js
CommitLineData
ff735274 1/*global Proxmox*/
161f4504
DM
2Ext.define('pmg-address-list', {
3 extend: 'Ext.data.Model',
4 fields: [ 'address' ],
5 idProperty: 'address'
6});
7
8// base class - do not use directly
9Ext.define('PMG.UserBlackWhiteList', {
10 extend: 'Ext.grid.GridPanel',
11
50531ef9 12 border: false,
161f4504
DM
13 listname: undefined, // 'blacklist' or 'whitelist',
14
c41c3600
DC
15 selModel: 'checkboxmodel',
16
64fb657f 17 emptyText: gettext('No data in database'),
5810fc6b 18
161f4504
DM
19 controller: {
20
21 xclass: 'Ext.app.ViewController',
22
23 onAddAddress: function() {
24 var me = this.getView();
7d51f9ff 25 var params = me.getStore().getProxy().getExtraParams() || {};
161f4504
DM
26
27 var url = '/quarantine/' + me.listname;
28
7d51f9ff
DC
29 var items = [{
30 xtype: 'proxmoxtextfield',
31 name: 'address',
c41c3600
DC
32 minLength: 3,
33 regex: /^[^\,\;\s]*$/, // no whitespace no , and no ;
7d51f9ff
DC
34 fieldLabel: gettext("Address")
35 }];
36
37 Ext.Object.each(params, function(key, value) {
38 items.push({
39 xtype: 'hidden',
40 name: key,
771bd0b9 41 value: value
7d51f9ff
DC
42 });
43 });
44
161f4504
DM
45 var config = {
46 method: 'POST',
47 url: url,
573a6e8b 48 onlineHelp: 'pmg_userblackwhitelist',
18b5b6ad 49 isCreate: true,
161f4504 50 isAdd: true,
7d51f9ff 51 items: items
161f4504
DM
52 };
53
54 if (me.listname === 'blacklist') {
55 config.subject = gettext("Blacklist");
56 } else if (me.listname == 'whitelist') {
57 config.subject = gettext("Whitelist");
58 } else {
59 throw "unknown list - internal error";
60 }
61
62 var win = Ext.createWidget('proxmoxWindowEdit', config);
131ba4f6 63 win.on('destroy', function() { me.store.load(); });
161f4504
DM
64 win.show();
65 },
66
67 onRemoveAddress: function() {
68 var me = this.getView();
c41c3600
DC
69 var records = me.selModel.getSelection();
70 if (records.length < 1) {
c17f9fe4
DC
71 return;
72 }
161f4504 73
c41c3600
DC
74 var url = '/quarantine/' + me.listname + '/';
75
76 url += records.map(function(rec) {
77 return encodeURIComponent(rec.getId());
78 }).join(',');
79
7d51f9ff 80 var params = me.getStore().getProxy().getExtraParams() || {};
161f4504
DM
81
82 Proxmox.Utils.API2Request({
7d51f9ff 83 url: url + '?' + Ext.Object.toQueryString(params),
161f4504
DM
84 method: 'DELETE',
85 waitMsgTarget: me,
86 callback: function(options, success, response) {
87 me.store.load();
88 },
89 failure: function (response, opts) {
90 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
91 }
92 });
7d51f9ff
DC
93 },
94
95 changeEmail: function(combobox, value) {
96 var view = this.getView();
a32f9554
DC
97 if (value && combobox.isValid()) {
98 view.getStore().getProxy().setExtraParams({
99 pmail: value
100 });
101 view.getStore().load();
102 }
7d51f9ff
DC
103 },
104
2f8fe1a3 105 init: function(view) {
c1f045cd 106 var emailcb = this.lookupReference('email');
99bba12c 107 if (PMG.view === 'quarantineview') {
c1f045cd 108 emailcb.setVisible(false);
e8dbe195 109 view.getStore().load();
c1f045cd
DC
110 } else {
111 emailcb.getStore().getProxy().setExtraParams({
112 list: view.listname === 'blacklist' ? 'BL' : 'WL'
113 });
7d51f9ff 114 }
2f8fe1a3 115 Proxmox.Utils.monStoreErrors(view.getView(), view.getStore(), true);
7d51f9ff
DC
116 },
117
118 control: {
119 'combobox':{
120 change: {
121 fn: 'changeEmail',
122 buffer: 500
123 }
124 }
161f4504
DM
125 }
126 },
127
128 tbar: [
7d51f9ff
DC
129 {
130 xtype: 'combobox',
131 displayField: 'mail',
a32f9554
DC
132 vtype: 'email',
133 allowBlank: false,
7d51f9ff
DC
134 valueField: 'mail',
135 store: {
136 proxy: {
137 type: 'proxmox',
138 url: '/api2/json/quarantine/quarusers'
96fba078
DC
139 },
140 fields: [
141 {
142 name: 'mail',
143 renderer: Ext.htmlEncode
144 }
145 ]
7d51f9ff
DC
146 },
147 queryParam: false,
148 queryCaching: false,
149 editable: true,
150 reference: 'email',
151 name: 'email',
771bd0b9 152 fieldLabel: 'E-Mail'
7d51f9ff 153 },
161f4504
DM
154 {
155 text: gettext('Add'),
156 handler: 'onAddAddress'
157 },
158 {
159 xtype: 'proxmoxButton',
160 text: gettext('Remove'),
161 disabled: true,
162 handler: 'onRemoveAddress',
c41c3600
DC
163 confirmMsg: function() {
164 var me = this.up('gridpanel');
165
166 var selection = me.selModel.getSelection();
167 var text;
168 var param;
169
170 if (selection.length > 1) {
171 text = gettext('Are you sure you want to remove {0} entries');
172 param = selection.length.toString();
173 } else if (selection.length > 0) {
174 var rec = selection[0];
175 var name = rec.getId();
176 text = gettext('Are you sure you want to remove entry {0}');
177 param = "'" + Ext.String.htmlEncode(name) + "'";
178 }
161f4504 179
c41c3600
DC
180 if (text && param) {
181 return Ext.String.format(text, param);
182 }
161f4504
DM
183 }
184 }
185 ],
186
187 columns: [
188 {
189 header: gettext('Address'),
190 dataIndex: 'address',
191 renderer: Ext.String.htmlEncode,
192 flex: 1
193 }
194 ]
195});
196
0277bfeb 197Ext.define('PMG.UserBlacklist', {
161f4504
DM
198 extend: 'PMG.UserBlackWhiteList',
199 xtype: 'pmgUserBlacklist',
0277bfeb
DM
200
201 title: gettext('Blacklist'),
161f4504
DM
202
203 listname: 'blacklist',
204
205 store: {
206 model: 'pmg-address-list',
e8dbe195 207 autoDestroy: true,
161f4504
DM
208 proxy: {
209 type: 'proxmox',
210 url: "/api2/json/quarantine/blacklist"
c41c3600
DC
211 },
212 sorters: {
213 property: 'address'
771bd0b9 214 }
161f4504
DM
215 },
216
217 dockedItems: [
218 {
219 dock: 'top',
50531ef9
DC
220 bodyStyle: {
221 padding: '10px',
222 'border-left': '0px',
771bd0b9 223 'border-right': '0px'
50531ef9 224 },
161f4504
DM
225 html: gettext('With this feature, you can manually mark E-mails from certain domains or addresses as spam.') + '<br><br>' +
226 '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
227 '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
228 '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
229
230 }
231 ]
0277bfeb
DM
232});
233
234Ext.define('PMG.UserWhitelist', {
161f4504 235 extend: 'PMG.UserBlackWhiteList',
0277bfeb
DM
236 xtype: 'pmgUserWhitelist',
237
238 title: gettext('Whitelist'),
0277bfeb 239
161f4504 240 listname: 'whitelist',
0277bfeb 241
161f4504
DM
242 store: {
243 model: 'pmg-address-list',
e8dbe195 244 autoDestroy: true,
161f4504
DM
245 proxy: {
246 type: 'proxmox',
247 url: "/api2/json/quarantine/whitelist"
c41c3600
DC
248 },
249 sorters: {
250 property: 'address'
771bd0b9 251 }
161f4504 252 },
0277bfeb 253
161f4504
DM
254 dockedItems: [
255 {
256 dock: 'top',
50531ef9
DC
257 bodyStyle: {
258 padding: '10px',
259 'border-left': '0px',
771bd0b9 260 'border-right': '0px'
50531ef9 261 },
161f4504
DM
262 html: gettext('With this feature, you can manually bypass spam checking for certain domains or E-mail addresses.') + '<br><br>' +
263 '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
264 '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
265 '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
266 }
267 ]
268});