]>
git.proxmox.com Git - pmg-gui.git/blob - js/MainView.js
1bcd83572a039a349da5d7a8d6eca64a5b842741
2 Ext
.define('PMG.MainView', {
3 extend
: 'Ext.container.Container',
6 title
: 'Proxmox Mail Gateway',
9 xclass
: 'Ext.app.ViewController',
13 before
: 'beforeChangePath',
15 ':path' : '(?:([%a-zA-Z0-9\\-\\_\\s,]+))',
16 ':subpath' : '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?'
21 beforeChangePath: function(path
, subpath
, action
) {
24 if (!Ext
.ClassManager
.getByAlias('widget.'+ path
)) {
25 console
.warn('xtype "'+path
+'" not found');
30 var lastpanel
= me
.lookupReference('contentpanel').getLayout().getActiveItem();
31 if (lastpanel
&& lastpanel
.xtype
=== path
) {
32 // we have the right component already,
33 // we just need to select the correct tab
34 // default to the first
35 subpath
= subpath
|| 0;
36 if (lastpanel
.getActiveTab
) {
37 // we assume lastpanel is a tabpanel
38 if (lastpanel
.getActiveTab().getItemId() !== subpath
) {
40 lastpanel
.setActiveTab(subpath
);
42 // else we are already there
51 changePath: function(path
,subpath
) {
53 var contentpanel
= me
.lookupReference('contentpanel');
54 var lastpanel
= contentpanel
.getLayout().getActiveItem();
56 var obj
= contentpanel
.add({ xtype
: path
});
57 var treelist
= me
.lookupReference('navtree');
59 treelist
.suspendEvents();
60 treelist
.select(path
);
61 treelist
.resumeEvents();
63 if (Ext
.isFunction(obj
.setActiveTab
)) {
64 obj
.setActiveTab(subpath
|| 0);
65 obj
.addListener('tabchange', function(tabpanel
, newc
, oldc
) {
68 // only add the subpath part for the
70 if (tabpanel
.items
.findIndex('id', newc
.id
) !== 0) {
71 newpath
+= ":" + newc
.getItemId();
74 me
.redirectTo(newpath
);
78 contentpanel
.setActiveItem(obj
);
81 contentpanel
.remove(lastpanel
, { destroy
: true });
90 navigate: function(treelist
, item
) {
91 this.redirectTo(item
.get('path'));
95 'button[reference=logoutButton]': {
100 init: function(view
) {
104 me
.lookupReference('usernameinfo').update({username
:Proxmox
.UserName
});
106 // show login on requestexception
107 // fixme: what about other errors
108 Ext
.Ajax
.on('requestexception', function(conn
, response
, options
) {
109 if (response
.status
== 401) { // auth failure
114 // get ticket periodically
115 Ext
.TaskManager
.start({
117 var ticket
= Proxmox
.Utils
.authOK();
118 if (!ticket
|| !Proxmox
.UserName
) {
124 username
: Proxmox
.UserName
,
127 url
: '/api2/json/access/ticket',
129 failure: function() {
132 success: function(response
, opts
) {
133 var obj
= Ext
.decode(response
.responseText
);
134 PMG
.Utils
.updateLoginData(obj
.data
);
141 // select treeitem and load page from url fragment
142 var token
= Ext
.util
.History
.getToken() || 'pmgDashboard';
143 this.redirectTo(token
, true);
150 layout
: { type
: 'border' },
174 reference
: 'usernameinfo',
176 tpl
: Ext
.String
.format(gettext("You are logged in as {0}"), "'{username}'")
179 xtype
: 'proxmoxHelpButton',
182 iconCls
: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ',
184 listenToGlobalEvent
: false,
185 onlineHelp
: 'pmg_documentation_index'
188 reference
: 'logoutButton',
190 iconCls
: 'fa fa-sign-out',
191 text
: gettext('Logout')
205 xtype
: 'navigationtree',
207 reference
: 'navtree',
208 // we have to define it here until extjs 6.2
209 // because of a bug where a viewcontroller does not detect
210 // the selectionchange event of a treelist
212 selectionchange
: 'navigate'
216 cls
: 'x-treelist-nav',
222 layout
: { type
: 'card' },
225 reference
: 'contentpanel'