]> git.proxmox.com Git - pmg-gui.git/blame - js/UserBlackWhiteList.js
add missing htmlEncode
[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();
82 view.getStore().getProxy().setExtraParams({
83 pmail: value
84 });
85 view.getStore().load();
86 },
87
2f8fe1a3 88 init: function(view) {
99bba12c 89 if (PMG.view === 'quarantineview') {
7d51f9ff
DC
90 this.lookupReference('email').setVisible(false);
91 }
2f8fe1a3 92 Proxmox.Utils.monStoreErrors(view.getView(), view.getStore(), true);
7d51f9ff
DC
93 },
94
95 control: {
96 'combobox':{
97 change: {
98 fn: 'changeEmail',
99 buffer: 500
100 }
101 }
161f4504
DM
102 }
103 },
104
105 tbar: [
7d51f9ff
DC
106 {
107 xtype: 'combobox',
108 displayField: 'mail',
109 valueField: 'mail',
110 store: {
111 proxy: {
112 type: 'proxmox',
113 url: '/api2/json/quarantine/quarusers'
96fba078
DC
114 },
115 fields: [
116 {
117 name: 'mail',
118 renderer: Ext.htmlEncode
119 }
120 ]
7d51f9ff
DC
121 },
122 queryParam: false,
123 queryCaching: false,
124 editable: true,
125 reference: 'email',
126 name: 'email',
127 fieldLabel: 'E-Mail',
128 },
161f4504
DM
129 {
130 text: gettext('Add'),
131 handler: 'onAddAddress'
132 },
133 {
134 xtype: 'proxmoxButton',
135 text: gettext('Remove'),
136 disabled: true,
137 handler: 'onRemoveAddress',
138 confirmMsg: function(rec) {
139 var me = this;
140
141 var name = rec.getId();
142 return Ext.String.format(
143 gettext('Are you sure you want to remove entry {0}'),
144 "'" + Ext.String.htmlEncode(name) + "'");
145 }
146 }
147 ],
148
149 columns: [
150 {
151 header: gettext('Address'),
152 dataIndex: 'address',
153 renderer: Ext.String.htmlEncode,
154 flex: 1
155 }
156 ]
157});
158
0277bfeb 159Ext.define('PMG.UserBlacklist', {
161f4504
DM
160 extend: 'PMG.UserBlackWhiteList',
161 xtype: 'pmgUserBlacklist',
0277bfeb
DM
162
163 title: gettext('Blacklist'),
161f4504
DM
164
165 listname: 'blacklist',
166
167 store: {
168 model: 'pmg-address-list',
169 autoLoad: true,
170 proxy: {
171 type: 'proxmox',
172 url: "/api2/json/quarantine/blacklist"
173 },
174 },
175
176 dockedItems: [
177 {
178 dock: 'top',
50531ef9
DC
179 bodyStyle: {
180 padding: '10px',
181 'border-left': '0px',
182 'border-right': '0px',
183 },
161f4504
DM
184 html: gettext('With this feature, you can manually mark E-mails from certain domains or addresses as spam.') + '<br><br>' +
185 '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
186 '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
187 '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
188
189 }
190 ]
0277bfeb
DM
191});
192
193Ext.define('PMG.UserWhitelist', {
161f4504 194 extend: 'PMG.UserBlackWhiteList',
0277bfeb
DM
195 xtype: 'pmgUserWhitelist',
196
197 title: gettext('Whitelist'),
0277bfeb 198
161f4504 199 listname: 'whitelist',
0277bfeb 200
161f4504
DM
201 store: {
202 model: 'pmg-address-list',
203 autoLoad: true,
204 proxy: {
205 type: 'proxmox',
206 url: "/api2/json/quarantine/whitelist"
207 },
208 },
0277bfeb 209
161f4504
DM
210 dockedItems: [
211 {
212 dock: 'top',
50531ef9
DC
213 bodyStyle: {
214 padding: '10px',
215 'border-left': '0px',
216 'border-right': '0px',
217 },
161f4504
DM
218 html: gettext('With this feature, you can manually bypass spam checking for certain domains or E-mail addresses.') + '<br><br>' +
219 '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
220 '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
221 '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
222 }
223 ]
224});