]> git.proxmox.com Git - pmg-gui.git/blame - js/UserBlackWhiteList.js
jslint: if needs a block
[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
5810fc6b
DC
15 emptyText: gettext('No data in database.'),
16
161f4504
DM
17 controller: {
18
19 xclass: 'Ext.app.ViewController',
20
21 onAddAddress: function() {
22 var me = this.getView();
7d51f9ff 23 var params = me.getStore().getProxy().getExtraParams() || {};
161f4504
DM
24
25 var url = '/quarantine/' + me.listname;
26
7d51f9ff
DC
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,
771bd0b9 37 value: value
7d51f9ff
DC
38 });
39 });
40
de0ebd99
DC
41 /*jslint confusion: true*/
42 /* create is an function */
161f4504
DM
43 var config = {
44 method: 'POST',
45 url: url,
46 create: true,
47 isAdd: true,
7d51f9ff 48 items: items
161f4504 49 };
de0ebd99 50 /*jslint confusion: false*/
161f4504
DM
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);
131ba4f6 61 win.on('destroy', function() { me.store.load(); });
161f4504
DM
62 win.show();
63 },
64
65 onRemoveAddress: function() {
66 var me = this.getView();
67 var rec = me.selModel.getSelection()[0];
c17f9fe4
DC
68 if (!rec) {
69 return;
70 }
161f4504 71
7d51f9ff 72 var params = me.getStore().getProxy().getExtraParams() || {};
161f4504
DM
73 var url = '/quarantine/' + me.listname + '/' + rec.getId();
74
75 Proxmox.Utils.API2Request({
7d51f9ff 76 url: url + '?' + Ext.Object.toQueryString(params),
161f4504
DM
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 });
7d51f9ff
DC
86 },
87
88 changeEmail: function(combobox, value) {
89 var view = this.getView();
a32f9554
DC
90 if (value && combobox.isValid()) {
91 view.getStore().getProxy().setExtraParams({
92 pmail: value
93 });
94 view.getStore().load();
95 }
7d51f9ff
DC
96 },
97
2f8fe1a3 98 init: function(view) {
99bba12c 99 if (PMG.view === 'quarantineview') {
7d51f9ff 100 this.lookupReference('email').setVisible(false);
e8dbe195 101 view.getStore().load();
7d51f9ff 102 }
2f8fe1a3 103 Proxmox.Utils.monStoreErrors(view.getView(), view.getStore(), true);
7d51f9ff
DC
104 },
105
106 control: {
107 'combobox':{
108 change: {
109 fn: 'changeEmail',
110 buffer: 500
111 }
112 }
161f4504
DM
113 }
114 },
115
116 tbar: [
7d51f9ff
DC
117 {
118 xtype: 'combobox',
119 displayField: 'mail',
a32f9554
DC
120 vtype: 'email',
121 allowBlank: false,
7d51f9ff
DC
122 valueField: 'mail',
123 store: {
124 proxy: {
125 type: 'proxmox',
126 url: '/api2/json/quarantine/quarusers'
96fba078
DC
127 },
128 fields: [
129 {
130 name: 'mail',
131 renderer: Ext.htmlEncode
132 }
133 ]
7d51f9ff
DC
134 },
135 queryParam: false,
136 queryCaching: false,
137 editable: true,
138 reference: 'email',
139 name: 'email',
771bd0b9 140 fieldLabel: 'E-Mail'
7d51f9ff 141 },
161f4504
DM
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
0277bfeb 172Ext.define('PMG.UserBlacklist', {
161f4504
DM
173 extend: 'PMG.UserBlackWhiteList',
174 xtype: 'pmgUserBlacklist',
0277bfeb
DM
175
176 title: gettext('Blacklist'),
161f4504
DM
177
178 listname: 'blacklist',
179
180 store: {
181 model: 'pmg-address-list',
e8dbe195 182 autoDestroy: true,
161f4504
DM
183 proxy: {
184 type: 'proxmox',
185 url: "/api2/json/quarantine/blacklist"
771bd0b9 186 }
161f4504
DM
187 },
188
189 dockedItems: [
190 {
191 dock: 'top',
50531ef9
DC
192 bodyStyle: {
193 padding: '10px',
194 'border-left': '0px',
771bd0b9 195 'border-right': '0px'
50531ef9 196 },
161f4504
DM
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 ]
0277bfeb
DM
204});
205
206Ext.define('PMG.UserWhitelist', {
161f4504 207 extend: 'PMG.UserBlackWhiteList',
0277bfeb
DM
208 xtype: 'pmgUserWhitelist',
209
210 title: gettext('Whitelist'),
0277bfeb 211
161f4504 212 listname: 'whitelist',
0277bfeb 213
161f4504
DM
214 store: {
215 model: 'pmg-address-list',
e8dbe195 216 autoDestroy: true,
161f4504
DM
217 proxy: {
218 type: 'proxmox',
219 url: "/api2/json/quarantine/whitelist"
771bd0b9 220 }
161f4504 221 },
0277bfeb 222
161f4504
DM
223 dockedItems: [
224 {
225 dock: 'top',
50531ef9
DC
226 bodyStyle: {
227 padding: '10px',
228 'border-left': '0px',
771bd0b9 229 'border-right': '0px'
50531ef9 230 },
161f4504
DM
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});