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