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