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