]> git.proxmox.com Git - pmg-gui.git/blame - js/QuarantineView.js
Application.js: remove trailing slash from pathname
[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) {
6 var me = this;
7 var item = me.getStore().findRecord('path', path, 0, false, true, true);
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'),
23 //iconCls: 'fa fa-cubes',
24 path: 'pmgUserWhitelist',
25 leaf: true,
26 },
27 {
28 text: gettext('Blacklist'),
29 //iconCls: 'fa fa-cubes',
30 path: 'pmgUserBlacklist',
31 leaf: true,
32 }
33 ]
34 }
35 ]
36 }
37 },
38
39 animation: false,
40 expanderOnly: true,
41 expanderFirst: false,
42 ui: 'nav'
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',
57 conditions : {
58 ':path' : '(?:([%a-zA-Z0-9\-\_\s,]+))',
59 ':subpath' : '(?:(?::)([%a-zA-Z0-9\-\_\s,]+))?'
60 }
61 }
62 },
63
64 beforeChangePath: function(path, subpath, action) {
65 var me = this;
66
67 if (!Ext.ClassManager.getByAlias('widget.'+ path)) {
68 console.warn('xtype "'+path+'" not found');
69 action.stop();
70 return;
71 }
72
73 var lastpanel = me.lookupReference('contentpanel').getLayout().getActiveItem();
74 if (lastpanel && lastpanel.xtype === path) {
75 // we have the right component already,
76 // we just need to select the correct tab
77 // default to the first
78 subpath = subpath || 0;
79 if (lastpanel.getActiveTab) {
80 // we assume lastpanel is a tabpanel
81 if (lastpanel.getActiveTab().getItemId() === subpath) {
82 // we are already there
83 } else {
84 // set the active tab
85 lastpanel.setActiveTab(subpath);
86 }
87 }
88 action.stop();
89 return;
90 }
91
92 action.resume();
93 },
94
95 changePath: function(path,subpath) {
96 var me = this;
97 var contentpanel = me.lookupReference('contentpanel');
98 var lastpanel = contentpanel.getLayout().getActiveItem();
99
207471c0 100 var obj = contentpanel.add({ xtype: path, cselect: subpath });
0277bfeb
DM
101 var treelist = me.lookupReference('navtree');
102
103 treelist.suspendEvents();
104 treelist.select(path);
105 treelist.resumeEvents();
106
107 if (Ext.isFunction(obj.setActiveTab)) {
108 obj.setActiveTab(subpath || 0);
109 obj.addListener('tabchange', function(tabpanel, newc, oldc) {
110 var newpath = path;
111
112 // only add the subpath part for the
113 // non-default tabs
114 if (tabpanel.items.findIndex('id', newc.id) !== 0) {
115 newpath += ":" + newc.getItemId();
116 }
117
118 me.redirectTo(newpath);
119 });
120 }
121
122 contentpanel.setActiveItem(obj);
123
124 if (lastpanel) {
125 contentpanel.remove(lastpanel, { destroy: true });
126 }
127 },
128
129 logout: function() {
99bba12c 130 PMG.app.logout();
0277bfeb
DM
131 },
132
133 navigate: function(treelist, item) {
134 this.redirectTo(item.get('path'));
135 },
136
258d48b5 137 execQuarantineAction: function(qa) {
2fa0b505 138 PMG.Utils.doQuarantineAction(qa.action, qa.cselect);
258d48b5
DM
139 },
140
99bba12c
DC
141 control: {
142 'button[reference=logoutButton]': {
143 click: 'logout'
144 }
145 },
146
0277bfeb
DM
147 init: function(view) {
148 var me = this;
149
150 // load username
151 me.lookupReference('usernameinfo').update({username:Proxmox.UserName});
152
153 // show login on requestexception
154 // fixme: what about other errors
155 Ext.Ajax.on('requestexception', function(conn, response, options) {
156 if (response.status == 401) { // auth failure
157 me.logout();
158 }
159 });
160
258d48b5
DM
161 var qa = PMG.Utils.extractQuarantineAction();
162 if (qa) {
163 var token = 'pmgSpamQuarantine';
164 if (qa.action === 'blacklist') { token = 'pmgUserBlacklist'; }
165 if (qa.action === 'whitelist') { token = 'pmgUserWhitelist'; }
207471c0
DC
166 if (qa.cselect) {
167 token += ':' + qa.cselect;
168 }
258d48b5 169 this.redirectTo(token, true);
207471c0
DC
170 if (qa.action) {
171 me.execQuarantineAction(qa);
172 }
258d48b5
DM
173 } else {
174 // select treeitem and load page from url fragment
207471c0 175
033228c0 176 var token = Ext.util.History.getToken() || 'pmgSpamQuarantine';
258d48b5
DM
177 this.redirectTo(token, true);
178 }
0277bfeb
DM
179 }
180 },
181
182 plugins: 'viewport',
183
184 layout: 'border',
185
186 items: [
187 {
188 region: 'north',
189 xtype: 'container',
190 layout: {
191 type: 'hbox',
192 align: 'middle'
193 },
c45e23e4
DC
194 margin: '2 5 2 5',
195 height: 38,
0277bfeb
DM
196 items: [
197 {
198 xtype: 'proxmoxlogo'
199 },
200 {
201 xtype: 'versioninfo'
202 },
203 {
204 flex: 1
205 },
206 {
207 baseCls: 'x-plain',
208 reference: 'usernameinfo',
209 padding: '0 5',
210 tpl: Ext.String.format(gettext("You are logged in as '{0}'"), '{username}')
99bba12c
DC
211 },
212 {
213 reference: 'logoutButton',
214 xtype: 'button',
215 iconCls: 'fa fa-sign-out',
216 text: gettext('Logout')
0277bfeb
DM
217 }
218 ]
219 },
220 {
221 xtype: 'quarantinenavigationtree',
222 reference: 'navtree',
223 minWidth: 177,
224 border: false,
225 region: 'west',
226 // we have to define it here until extjs 6.2
227 // because of a bug where a viewcontroller does not detect
228 // the selectionchange event of a treelist
229 listeners: {
230 selectionchange: 'navigate'
231 }
232 },
233 {
234 xtype: 'panel',
235 layout: 'card',
236 region: 'center',
237 border: false,
238 reference: 'contentpanel',
239 }
240 ]
241});