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