]> git.proxmox.com Git - pmg-gui.git/blob - js/UserBlackWhiteList.js
add missing encodeURIComponent
[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 onlineHelp: 'pmg_userblackwhitelist',
45 isCreate: true,
46 isAdd: true,
47 items: items
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);
59 win.on('destroy', function() { me.store.load(); });
60 win.show();
61 },
62
63 onRemoveAddress: function() {
64 var me = this.getView();
65 var rec = me.selModel.getSelection()[0];
66 if (!rec) {
67 return;
68 }
69
70 var params = me.getStore().getProxy().getExtraParams() || {};
71 var url = '/quarantine/' + me.listname + '/' + encodeURIComponent(rec.getId());
72
73 Proxmox.Utils.API2Request({
74 url: url + '?' + Ext.Object.toQueryString(params),
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 });
84 },
85
86 changeEmail: function(combobox, value) {
87 var view = this.getView();
88 if (value && combobox.isValid()) {
89 view.getStore().getProxy().setExtraParams({
90 pmail: value
91 });
92 view.getStore().load();
93 }
94 },
95
96 init: function(view) {
97 if (PMG.view === 'quarantineview') {
98 this.lookupReference('email').setVisible(false);
99 view.getStore().load();
100 }
101 Proxmox.Utils.monStoreErrors(view.getView(), view.getStore(), true);
102 },
103
104 control: {
105 'combobox':{
106 change: {
107 fn: 'changeEmail',
108 buffer: 500
109 }
110 }
111 }
112 },
113
114 tbar: [
115 {
116 xtype: 'combobox',
117 displayField: 'mail',
118 vtype: 'email',
119 allowBlank: false,
120 valueField: 'mail',
121 store: {
122 proxy: {
123 type: 'proxmox',
124 url: '/api2/json/quarantine/quarusers'
125 },
126 fields: [
127 {
128 name: 'mail',
129 renderer: Ext.htmlEncode
130 }
131 ]
132 },
133 queryParam: false,
134 queryCaching: false,
135 editable: true,
136 reference: 'email',
137 name: 'email',
138 fieldLabel: 'E-Mail'
139 },
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
170 Ext.define('PMG.UserBlacklist', {
171 extend: 'PMG.UserBlackWhiteList',
172 xtype: 'pmgUserBlacklist',
173
174 title: gettext('Blacklist'),
175
176 listname: 'blacklist',
177
178 store: {
179 model: 'pmg-address-list',
180 autoDestroy: true,
181 proxy: {
182 type: 'proxmox',
183 url: "/api2/json/quarantine/blacklist"
184 }
185 },
186
187 dockedItems: [
188 {
189 dock: 'top',
190 bodyStyle: {
191 padding: '10px',
192 'border-left': '0px',
193 'border-right': '0px'
194 },
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 ]
202 });
203
204 Ext.define('PMG.UserWhitelist', {
205 extend: 'PMG.UserBlackWhiteList',
206 xtype: 'pmgUserWhitelist',
207
208 title: gettext('Whitelist'),
209
210 listname: 'whitelist',
211
212 store: {
213 model: 'pmg-address-list',
214 autoDestroy: true,
215 proxy: {
216 type: 'proxmox',
217 url: "/api2/json/quarantine/whitelist"
218 }
219 },
220
221 dockedItems: [
222 {
223 dock: 'top',
224 bodyStyle: {
225 padding: '10px',
226 'border-left': '0px',
227 'border-right': '0px'
228 },
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 });