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