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