]> git.proxmox.com Git - pmg-gui.git/blob - js/UserBlackWhiteList.js
add missing clearbeforeload arguments for monStoreErrors
[pmg-gui.git] / js / UserBlackWhiteList.js
1 Ext.define('pmg-address-list', {
2 extend: 'Ext.data.Model',
3 fields: [ 'address' ],
4 idProperty: 'address'
5 });
6
7 // base class - do not use directly
8 Ext.define('PMG.UserBlackWhiteList', {
9 extend: 'Ext.grid.GridPanel',
10
11 border: false,
12 listname: undefined, // 'blacklist' or 'whitelist',
13
14 controller: {
15
16 xclass: 'Ext.app.ViewController',
17
18 onAddAddress: function() {
19 var me = this.getView();
20 var params = me.getStore().getProxy().getExtraParams() || {};
21
22 var url = '/quarantine/' + me.listname;
23
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
38 var config = {
39 method: 'POST',
40 url: url,
41 create: true,
42 isAdd: true,
43 items: items
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
64 var params = me.getStore().getProxy().getExtraParams() || {};
65 var url = '/quarantine/' + me.listname + '/' + rec.getId();
66
67 Proxmox.Utils.API2Request({
68 url: url + '?' + Ext.Object.toQueryString(params),
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 });
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
88 init: function(view) {
89 if (PMG.view === 'quarantineview') {
90 this.lookupReference('email').setVisible(false);
91 }
92 Proxmox.Utils.monStoreErrors(view.getView(), view.getStore(), true);
93 },
94
95 control: {
96 'combobox':{
97 change: {
98 fn: 'changeEmail',
99 buffer: 500
100 }
101 }
102 }
103 },
104
105 tbar: [
106 {
107 xtype: 'combobox',
108 displayField: 'mail',
109 valueField: 'mail',
110 store: {
111 proxy: {
112 type: 'proxmox',
113 url: '/api2/json/quarantine/quarusers'
114 }
115 },
116 queryParam: false,
117 queryCaching: false,
118 editable: true,
119 reference: 'email',
120 name: 'email',
121 fieldLabel: 'E-Mail',
122 },
123 {
124 text: gettext('Add'),
125 handler: 'onAddAddress'
126 },
127 {
128 xtype: 'proxmoxButton',
129 text: gettext('Remove'),
130 disabled: true,
131 handler: 'onRemoveAddress',
132 confirmMsg: function(rec) {
133 var me = this;
134
135 var name = rec.getId();
136 return Ext.String.format(
137 gettext('Are you sure you want to remove entry {0}'),
138 "'" + Ext.String.htmlEncode(name) + "'");
139 }
140 }
141 ],
142
143 columns: [
144 {
145 header: gettext('Address'),
146 dataIndex: 'address',
147 renderer: Ext.String.htmlEncode,
148 flex: 1
149 }
150 ]
151 });
152
153 Ext.define('PMG.UserBlacklist', {
154 extend: 'PMG.UserBlackWhiteList',
155 xtype: 'pmgUserBlacklist',
156
157 title: gettext('Blacklist'),
158
159 listname: 'blacklist',
160
161 store: {
162 model: 'pmg-address-list',
163 autoLoad: true,
164 proxy: {
165 type: 'proxmox',
166 url: "/api2/json/quarantine/blacklist"
167 },
168 },
169
170 dockedItems: [
171 {
172 dock: 'top',
173 bodyStyle: {
174 padding: '10px',
175 'border-left': '0px',
176 'border-right': '0px',
177 },
178 html: gettext('With this feature, you can manually mark E-mails from certain domains or addresses as spam.') + '<br><br>' +
179 '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
180 '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
181 '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
182
183 }
184 ]
185 });
186
187 Ext.define('PMG.UserWhitelist', {
188 extend: 'PMG.UserBlackWhiteList',
189 xtype: 'pmgUserWhitelist',
190
191 title: gettext('Whitelist'),
192
193 listname: 'whitelist',
194
195 store: {
196 model: 'pmg-address-list',
197 autoLoad: true,
198 proxy: {
199 type: 'proxmox',
200 url: "/api2/json/quarantine/whitelist"
201 },
202 },
203
204 dockedItems: [
205 {
206 dock: 'top',
207 bodyStyle: {
208 padding: '10px',
209 'border-left': '0px',
210 'border-right': '0px',
211 },
212 html: gettext('With this feature, you can manually bypass spam checking for certain domains or E-mail addresses.') + '<br><br>' +
213 '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
214 '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
215 '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
216 }
217 ]
218 });