]>
git.proxmox.com Git - pmg-gui.git/blob - js/QuarantineView.js
2 Ext
.define('PMG.QuarantineNavigationTree', {
3 extend
: 'Ext.list.Tree',
4 xtype
: 'quarantinenavigationtree',
6 select: function(path
) {
8 var item
= me
.getStore().findRecord('path', path
, 0, false, true, true);
17 text
: gettext('Spam Quarantine'),
18 iconCls
: 'fa fa-cubes',
19 path
: 'pmgSpamQuarantine',
23 text
: gettext('Whitelist'),
24 iconCls
: 'fa fa-file-o',
25 path
: 'pmgUserWhitelist',
29 text
: gettext('Blacklist'),
30 iconCls
: 'fa fa-file',
31 path
: 'pmgUserBlacklist',
46 Ext
.define('PMG.QuarantineView', {
47 extend
: 'Ext.container.Container',
48 xtype
: 'quarantineview',
50 title
: 'Proxmox Mail Gateway Quarantine',
53 xclass
: 'Ext.app.ViewController',
57 before
: 'beforeChangePath',
59 ':path' : '(?:([%a-zA-Z0-9\\-\\_\\s,]+))',
60 ':subpath' : '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?'
65 beforeChangePath: function(path
, subpath
, action
) {
68 if (!Ext
.ClassManager
.getByAlias('widget.'+ path
)) {
69 console
.warn('xtype "'+path
+'" not found');
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
) {
84 lastpanel
.setActiveTab(subpath
);
86 // else we are already there
95 changePath: function(path
,subpath
) {
97 var contentpanel
= me
.lookupReference('contentpanel');
98 var lastpanel
= contentpanel
.getLayout().getActiveItem();
100 var obj
= contentpanel
.add({ xtype
: path
, cselect
: subpath
});
101 var treelist
= me
.lookupReference('navtree');
103 treelist
.suspendEvents();
104 treelist
.select(path
);
105 treelist
.resumeEvents();
107 if (Ext
.isFunction(obj
.setActiveTab
)) {
108 obj
.setActiveTab(subpath
|| 0);
109 obj
.addListener('tabchange', function(tabpanel
, newc
, oldc
) {
112 // only add the subpath part for the
114 if (tabpanel
.items
.findIndex('id', newc
.id
) !== 0) {
115 newpath
+= ":" + newc
.getItemId();
118 me
.redirectTo(newpath
);
122 contentpanel
.setActiveItem(obj
);
125 contentpanel
.remove(lastpanel
, { destroy
: true });
133 navigate: function(treelist
, item
) {
134 this.redirectTo(item
.get('path'));
137 execQuarantineAction: function(qa
) {
138 PMG
.Utils
.doQuarantineAction(qa
.action
, qa
.cselect
);
142 'button[reference=logoutButton]': {
147 init: function(view
) {
151 var username
= Proxmox
.UserName
.replace(/\@quarantine$/, '');
152 me
.lookupReference('usernameinfo').update({username
: username
});
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
162 var qa
= PMG
.Utils
.extractQuarantineAction();
165 token
= 'pmgSpamQuarantine';
166 if (qa
.action
=== 'blacklist') { token
= 'pmgUserBlacklist'; }
167 if (qa
.action
=== 'whitelist') { token
= 'pmgUserWhitelist'; }
169 token
+= ':' + qa
.cselect
;
171 this.redirectTo(token
, true);
173 me
.execQuarantineAction(qa
);
176 // select treeitem and load page from url fragment
178 token
= Ext
.util
.History
.getToken() || 'pmgSpamQuarantine';
179 this.redirectTo(token
, true);
212 reference
: 'usernameinfo',
214 tpl
: Ext
.String
.format(gettext("You are logged in as {0}"), "'{username}'")
217 reference
: 'logoutButton',
219 iconCls
: 'fa fa-sign-out',
220 text
: gettext('Logout')
225 xtype
: 'quarantinenavigationtree',
226 reference
: 'navtree',
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
234 selectionchange
: 'navigate'
244 reference
: 'contentpanel'