]> git.proxmox.com Git - pmg-gui.git/blame - js/QuarantineView.js
quarantine: use new controller for virus and attachment quarantines
[pmg-gui.git] / js / QuarantineView.js
CommitLineData
0277bfeb
DM
1Ext.define('PMG.QuarantineNavigationTree', {
2 extend: 'Ext.list.Tree',
3 xtype: 'quarantinenavigationtree',
4
5 select: function(path) {
28eb60c0
TL
6 let me = this;
7 let item = me.getStore().findRecord('path', path, 0, false, true, true);
0277bfeb
DM
8 me.setSelection(item);
9 },
10
11 store: {
0277bfeb
DM
12 root: {
13 expanded: true,
14 children: [
15 {
16 text: gettext('Spam Quarantine'),
17 iconCls: 'fa fa-cubes',
18 path: 'pmgSpamQuarantine',
19 expanded: true,
20 children: [
21 {
22 text: gettext('Whitelist'),
3cac8c4e 23 iconCls: 'fa fa-file-o',
0277bfeb 24 path: 'pmgUserWhitelist',
c87d46fb 25 leaf: true,
0277bfeb
DM
26 },
27 {
28 text: gettext('Blacklist'),
3cac8c4e 29 iconCls: 'fa fa-file',
0277bfeb 30 path: 'pmgUserBlacklist',
c87d46fb
TL
31 leaf: true,
32 },
33 ],
34 },
35 ],
36 },
0277bfeb
DM
37 },
38
39 animation: false,
40 expanderOnly: true,
41 expanderFirst: false,
13f8df5c 42 ui: 'pve-nav',
0277bfeb
DM
43});
44
45Ext.define('PMG.QuarantineView', {
46 extend: 'Ext.container.Container',
47 xtype: 'quarantineview',
48
49 title: 'Proxmox Mail Gateway Quarantine',
50
51 controller: {
52 xclass: 'Ext.app.ViewController',
53 routes: {
54 ':path:subpath': {
55 action: 'changePath',
56 before: 'beforeChangePath',
c87d46fb
TL
57 conditions: {
58 ':path': '(?:([%a-zA-Z0-9\\-\\_\\s,]+))',
59 ':subpath': '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?',
60 },
61 },
0277bfeb
DM
62 },
63
e810c530 64 beforeChangePath: function(path, subpathOrAction, action) {
28eb60c0 65 let me = this;
0277bfeb 66
e810c530
TL
67 let subpath = subpathOrAction;
68 if (!action) {
69 action = subpathOrAction;
70 subpath = undefined;
71 }
72
0277bfeb
DM
73 if (!Ext.ClassManager.getByAlias('widget.'+ path)) {
74 console.warn('xtype "'+path+'" not found');
75 action.stop();
76 return;
77 }
78
28eb60c0 79 let lastpanel = me.lookupReference('contentpanel').getLayout().getActiveItem();
0277bfeb
DM
80 if (lastpanel && lastpanel.xtype === path) {
81 // we have the right component already,
82 // we just need to select the correct tab
83 // default to the first
84 subpath = subpath || 0;
85 if (lastpanel.getActiveTab) {
86 // we assume lastpanel is a tabpanel
5a768cc5 87 if (lastpanel.getActiveTab().getItemId() !== subpath) {
0277bfeb
DM
88 // set the active tab
89 lastpanel.setActiveTab(subpath);
90 }
5a768cc5 91 // else we are already there
0277bfeb
DM
92 }
93 action.stop();
94 return;
95 }
96
97 action.resume();
98 },
99
c87d46fb 100 changePath: function(path, subpath) {
28eb60c0
TL
101 let me = this;
102 let contentpanel = me.lookupReference('contentpanel');
103 let lastpanel = contentpanel.getLayout().getActiveItem();
0277bfeb 104
28eb60c0
TL
105 let obj = contentpanel.add({ xtype: path, cselect: subpath });
106 let treelist = me.lookupReference('navtree');
0277bfeb
DM
107
108 treelist.suspendEvents();
109 treelist.select(path);
110 treelist.resumeEvents();
111
112 if (Ext.isFunction(obj.setActiveTab)) {
113 obj.setActiveTab(subpath || 0);
114 obj.addListener('tabchange', function(tabpanel, newc, oldc) {
28eb60c0 115 let newpath = path;
0277bfeb
DM
116
117 // only add the subpath part for the
118 // non-default tabs
119 if (tabpanel.items.findIndex('id', newc.id) !== 0) {
120 newpath += ":" + newc.getItemId();
121 }
122
123 me.redirectTo(newpath);
124 });
125 }
126
127 contentpanel.setActiveItem(obj);
128
129 if (lastpanel) {
130 contentpanel.remove(lastpanel, { destroy: true });
131 }
132 },
133
134 logout: function() {
99bba12c 135 PMG.app.logout();
0277bfeb
DM
136 },
137
590a3b9f 138 changeLanguage: function() {
903548bc 139 Ext.create('Proxmox.window.LanguageEditWindow', {
c87d46fb 140 cookieName: 'PMGLangCookie',
590a3b9f
DC
141 }).show();
142 },
143
0277bfeb
DM
144 navigate: function(treelist, item) {
145 this.redirectTo(item.get('path'));
146 },
147
258d48b5 148 execQuarantineAction: function(qa) {
2fa0b505 149 PMG.Utils.doQuarantineAction(qa.action, qa.cselect);
258d48b5
DM
150 },
151
99bba12c 152 control: {
590a3b9f 153 '[reference=logoutButton]': {
c87d46fb 154 click: 'logout',
590a3b9f
DC
155 },
156 '[reference=languageButton]': {
157 click: 'changeLanguage',
158 },
99bba12c
DC
159 },
160
0277bfeb 161 init: function(view) {
28eb60c0 162 let me = this;
0277bfeb
DM
163
164 // load username
28eb60c0 165 let username = Proxmox.UserName.replace(/@quarantine$/, '');
590a3b9f 166 me.lookupReference('usernameinfo').setText(username);
0277bfeb
DM
167
168 // show login on requestexception
169 // fixme: what about other errors
170 Ext.Ajax.on('requestexception', function(conn, response, options) {
28eb60c0 171 if (response.status === 401) { // auth failure
0277bfeb
DM
172 me.logout();
173 }
174 });
175
28eb60c0
TL
176 let qa = PMG.Utils.extractQuarantineAction();
177 let token;
258d48b5 178 if (qa) {
cac4542e 179 token = 'pmgSpamQuarantine';
258d48b5
DM
180 if (qa.action === 'blacklist') { token = 'pmgUserBlacklist'; }
181 if (qa.action === 'whitelist') { token = 'pmgUserWhitelist'; }
207471c0
DC
182 if (qa.cselect) {
183 token += ':' + qa.cselect;
184 }
258d48b5 185 this.redirectTo(token, true);
207471c0
DC
186 if (qa.action) {
187 me.execQuarantineAction(qa);
188 }
258d48b5
DM
189 } else {
190 // select treeitem and load page from url fragment
c87d46fb 191
cac4542e 192 token = Ext.util.History.getToken() || 'pmgSpamQuarantine';
258d48b5
DM
193 this.redirectTo(token, true);
194 }
c87d46fb 195 },
0277bfeb
DM
196 },
197
198 plugins: 'viewport',
199
de0ebd99 200 layout: {
c87d46fb 201 type: 'border',
de0ebd99 202 },
0277bfeb
DM
203
204 items: [
205 {
206 region: 'north',
207 xtype: 'container',
208 layout: {
209 type: 'hbox',
c87d46fb 210 align: 'middle',
0277bfeb 211 },
11f43687 212 margin: '2 0 2 5',
c45e23e4 213 height: 38,
0277bfeb
DM
214 items: [
215 {
c87d46fb 216 xtype: 'proxmoxlogo',
0277bfeb
DM
217 },
218 {
11f43687 219 padding: '0 0 0 5',
c87d46fb 220 xtype: 'versioninfo',
0277bfeb
DM
221 },
222 {
c87d46fb 223 flex: 1,
0277bfeb
DM
224 },
225 {
590a3b9f 226 xtype: 'button',
0277bfeb 227 reference: 'usernameinfo',
590a3b9f
DC
228 style: {
229 // proxmox dark grey p light grey as border
230 backgroundColor: '#464d4d',
c87d46fb 231 borderColor: '#ABBABA',
590a3b9f
DC
232 },
233 margin: '0 5 0 0',
234 iconCls: 'fa fa-user',
235 menu: [
236 {
237 iconCls: 'fa fa-language',
238 text: gettext('Language'),
239 reference: 'languageButton',
240 },
241 '-',
242 {
243 reference: 'logoutButton',
244 iconCls: 'fa fa-sign-out',
c87d46fb 245 text: gettext('Logout'),
590a3b9f
DC
246 },
247 ],
99bba12c 248 },
c87d46fb 249 ],
0277bfeb
DM
250 },
251 {
3d233789
TL
252 xtype: 'panel',
253 scrollable: 'y',
0277bfeb
DM
254 border: false,
255 region: 'west',
3d233789
TL
256 layout: {
257 type: 'vbox',
258 align: 'stretch',
c87d46fb 259 },
3d233789
TL
260 items: [
261 {
262 xtype: 'quarantinenavigationtree',
263 reference: 'navtree',
264 minWidth: 180,
265 // we have to define it here until extjs 6.2 because of a bug where a
266 // viewcontroller does not detect the selectionchange event of a treelist
267 listeners: {
268 selectionchange: 'navigate',
269 },
270 },
271 {
272 xtype: 'box',
273 cls: 'x-treelist-pve-nav',
274 flex: 1,
275 },
276 ],
0277bfeb
DM
277 },
278 {
279 xtype: 'panel',
de0ebd99 280 layout: {
c87d46fb 281 type: 'card',
de0ebd99 282 },
0277bfeb
DM
283 region: 'center',
284 border: false,
c87d46fb
TL
285 reference: 'contentpanel',
286 },
287 ],
0277bfeb 288});