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