]>
git.proxmox.com Git - pmg-gui.git/blob - js/QuarantineView.js
1 Ext
.define('PMG.QuarantineNavigationTree', {
2 extend
: 'Ext.list.Tree',
3 xtype
: 'quarantinenavigationtree',
5 select: function(path
) {
7 var item
= me
.getStore().findRecord('path', path
, 0, false, true, true);
12 xcalss
: 'Ext.data.TreeStore',
17 text
: gettext('Spam Quarantine'),
18 iconCls
: 'fa fa-cubes',
19 path
: 'pmgSpamQuarantine',
23 text
: gettext('Whitelist'),
24 //iconCls: 'fa fa-cubes',
25 path
: 'pmgUserWhitelist',
29 text
: gettext('Blacklist'),
30 //iconCls: 'fa fa-cubes',
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
) {
83 // we are already there
86 lastpanel
.setActiveTab(subpath
);
96 changePath: function(path
,subpath
) {
98 var contentpanel
= me
.lookupReference('contentpanel');
99 var lastpanel
= contentpanel
.getLayout().getActiveItem();
101 var obj
= contentpanel
.add({ xtype
: path
, cselect
: subpath
});
102 var treelist
= me
.lookupReference('navtree');
104 treelist
.suspendEvents();
105 treelist
.select(path
);
106 treelist
.resumeEvents();
108 if (Ext
.isFunction(obj
.setActiveTab
)) {
109 obj
.setActiveTab(subpath
|| 0);
110 obj
.addListener('tabchange', function(tabpanel
, newc
, oldc
) {
113 // only add the subpath part for the
115 if (tabpanel
.items
.findIndex('id', newc
.id
) !== 0) {
116 newpath
+= ":" + newc
.getItemId();
119 me
.redirectTo(newpath
);
123 contentpanel
.setActiveItem(obj
);
126 contentpanel
.remove(lastpanel
, { destroy
: true });
134 navigate: function(treelist
, item
) {
135 this.redirectTo(item
.get('path'));
138 execQuarantineAction: function(qa
) {
139 Proxmox
.Utils
.API2Request({
140 url
: '/api2/extjs/quarantine/content',
146 success: function(response
) {
147 Ext
.Msg
.alert(gettext('Info'), "Action " + qa
.action
+ ' ' +
148 qa
.cselect
+ ' successful');
150 failure: function(response
, opts
) {
151 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
157 'button[reference=logoutButton]': {
162 init: function(view
) {
166 me
.lookupReference('usernameinfo').update({username
:Proxmox
.UserName
});
168 // show login on requestexception
169 // fixme: what about other errors
170 Ext
.Ajax
.on('requestexception', function(conn
, response
, options
) {
171 if (response
.status
== 401) { // auth failure
176 var qa
= PMG
.Utils
.extractQuarantineAction();
178 var token
= 'pmgSpamQuarantine';
179 if (qa
.action
=== 'blacklist') { token
= 'pmgUserBlacklist'; }
180 if (qa
.action
=== 'whitelist') { token
= 'pmgUserWhitelist'; }
182 token
+= ':' + qa
.cselect
;
184 this.redirectTo(token
, true);
186 me
.execQuarantineAction(qa
);
189 // select treeitem and load page from url fragment
191 var token
= Ext
.util
.History
.getToken() || 'pmgSpamQuarantine';
192 this.redirectTo(token
, true);
223 reference
: 'usernameinfo',
225 tpl
: Ext
.String
.format(gettext("You are logged in as '{0}'"), '{username}')
228 reference
: 'logoutButton',
230 iconCls
: 'fa fa-sign-out',
231 text
: gettext('Logout')
236 xtype
: 'quarantinenavigationtree',
237 reference
: 'navtree',
241 // we have to define it here until extjs 6.2
242 // because of a bug where a viewcontroller does not detect
243 // the selectionchange event of a treelist
245 selectionchange
: 'navigate'
253 reference
: 'contentpanel',