]>
git.proxmox.com Git - pmg-gui.git/blob - js/MainView.js
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 });
89 navigate: function(treelist
, item
) {
90 this.redirectTo(item
.get('path'));
93 changeLanguage: function() {
94 Ext
.create('Proxmox.window.LanguageEditWindow', {
95 cookieName
: 'PMGLangCookie',
100 '[reference=logoutButton]': {
103 '[reference=languageButton]': {
104 click
: 'changeLanguage',
108 init: function(view
) {
112 me
.lookupReference('usernameinfo').setText(Proxmox
.UserName
);
114 // show login on requestexception
115 // fixme: what about other errors
116 Ext
.Ajax
.on('requestexception', function(conn
, response
, options
) {
117 if (response
.status
== 401) { // auth failure
122 // get ticket periodically
123 Ext
.TaskManager
.start({
125 var ticket
= Proxmox
.Utils
.authOK();
126 if (!ticket
|| !Proxmox
.UserName
) {
132 username
: Proxmox
.UserName
,
135 url
: '/api2/json/access/ticket',
137 failure: function() {
140 success: function(response
, opts
) {
141 var obj
= Ext
.decode(response
.responseText
);
142 PMG
.Utils
.updateLoginData(obj
.data
);
146 interval
: 15*60*1000,
149 // select treeitem and load page from url fragment
150 var token
= Ext
.util
.History
.getToken() || 'pmgDashboard';
151 this.redirectTo(token
, true);
157 layout
: { type
: 'border' },
171 xtype
: 'proxmoxlogo',
175 xtype
: 'versioninfo',
181 xtype
: 'proxmoxHelpButton',
182 text
: gettext('Documentation'),
185 iconCls
: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ',
187 listenToGlobalEvent
: false,
188 onlineHelp
: 'pmg_documentation_index',
192 reference
: 'usernameinfo',
194 // proxmox dark grey p light grey as border
195 backgroundColor
: '#464d4d',
196 borderColor
: '#ABBABA',
199 iconCls
: 'fa fa-user',
202 iconCls
: 'fa fa-language',
203 text
: gettext('Language'),
204 reference
: 'languageButton',
208 reference
: 'logoutButton',
209 iconCls
: 'fa fa-sign-out',
210 text
: gettext('Logout'),
226 xtype
: 'navigationtree',
228 reference
: 'navtree',
229 // we have to define it here until extjs 6.2
230 // because of a bug where a viewcontroller does not detect
231 // the selectionchange event of a treelist
233 selectionchange
: 'navigate',
237 cls
: 'x-treelist-nav',
243 layout
: { type
: 'card' },
246 reference
: 'contentpanel',