]> git.proxmox.com Git - pmg-gui.git/blame - js/QuarantineView.js
add an Group objectclass textfield to the LDAPEditor
[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
c407e168
DM
151 var username = Proxmox.UserName.replace(/\@quarantine$/, '');
152 me.lookupReference('usernameinfo').update({username: username});
0277bfeb
DM
153
154 // show login on requestexception
155 // fixme: what about other errors
156 Ext.Ajax.on('requestexception', function(conn, response, options) {
157 if (response.status == 401) { // auth failure
158 me.logout();
159 }
160 });
161
258d48b5
DM
162 var qa = PMG.Utils.extractQuarantineAction();
163 if (qa) {
164 var token = 'pmgSpamQuarantine';
165 if (qa.action === 'blacklist') { token = 'pmgUserBlacklist'; }
166 if (qa.action === 'whitelist') { token = 'pmgUserWhitelist'; }
207471c0
DC
167 if (qa.cselect) {
168 token += ':' + qa.cselect;
169 }
258d48b5 170 this.redirectTo(token, true);
207471c0
DC
171 if (qa.action) {
172 me.execQuarantineAction(qa);
173 }
258d48b5
DM
174 } else {
175 // select treeitem and load page from url fragment
207471c0 176
033228c0 177 var token = Ext.util.History.getToken() || 'pmgSpamQuarantine';
258d48b5
DM
178 this.redirectTo(token, true);
179 }
0277bfeb
DM
180 }
181 },
182
183 plugins: 'viewport',
184
185 layout: 'border',
186
187 items: [
188 {
189 region: 'north',
190 xtype: 'container',
191 layout: {
192 type: 'hbox',
193 align: 'middle'
194 },
c45e23e4
DC
195 margin: '2 5 2 5',
196 height: 38,
0277bfeb
DM
197 items: [
198 {
199 xtype: 'proxmoxlogo'
200 },
201 {
202 xtype: 'versioninfo'
203 },
204 {
205 flex: 1
206 },
207 {
208 baseCls: 'x-plain',
209 reference: 'usernameinfo',
210 padding: '0 5',
211 tpl: Ext.String.format(gettext("You are logged in as '{0}'"), '{username}')
99bba12c
DC
212 },
213 {
214 reference: 'logoutButton',
215 xtype: 'button',
216 iconCls: 'fa fa-sign-out',
217 text: gettext('Logout')
0277bfeb
DM
218 }
219 ]
220 },
221 {
222 xtype: 'quarantinenavigationtree',
223 reference: 'navtree',
224 minWidth: 177,
225 border: false,
226 region: 'west',
227 // we have to define it here until extjs 6.2
228 // because of a bug where a viewcontroller does not detect
229 // the selectionchange event of a treelist
230 listeners: {
231 selectionchange: 'navigate'
232 }
233 },
234 {
235 xtype: 'panel',
236 layout: 'card',
237 region: 'center',
238 border: false,
239 reference: 'contentpanel',
240 }
241 ]
242});