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