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