]>
git.proxmox.com Git - pmg-gui.git/blob - js/MainView.js
1 Ext
.define('PMG.MainView', {
2 extend
: 'Ext.container.Container',
5 title
: 'Proxmox Mail Gateway',
8 xclass
: 'Ext.app.ViewController',
12 before
: 'beforeChangePath',
14 ':path': '(?:([%a-zA-Z0-9\\-\\_\\s,]+))',
15 ':subpath': '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?',
20 beforeChangePath: function(path
, subpathOrAction
, action
) {
23 let subpath
= subpathOrAction
;
25 action
= subpathOrAction
;
29 if (!Ext
.ClassManager
.getByAlias('widget.'+ path
)) {
30 console
.warn('xtype "'+path
+'" not found');
35 let lastpanel
= me
.lookupReference('contentpanel').getLayout().getActiveItem();
36 if (lastpanel
&& lastpanel
.xtype
=== path
) {
37 // we have the right component already,
38 // we just need to select the correct tab
39 // default to the first
40 subpath
= subpath
|| 0;
41 if (lastpanel
.getActiveTab
) {
42 // we assume lastpanel is a tabpanel
43 if (lastpanel
.getActiveTab().getItemId() !== subpath
) {
45 lastpanel
.setActiveTab(subpath
);
47 // else we are already there
56 changePath: function(path
, subpath
) {
58 let contentpanel
= me
.lookupReference('contentpanel');
59 let lastpanel
= contentpanel
.getLayout().getActiveItem();
61 let obj
= contentpanel
.add({ xtype
: path
});
62 let treelist
= me
.lookupReference('navtree');
64 treelist
.suspendEvents();
65 treelist
.select(path
);
66 treelist
.resumeEvents();
68 if (Ext
.isFunction(obj
.setActiveTab
)) {
69 obj
.setActiveTab(subpath
|| 0);
70 obj
.addListener('tabchange', function(tabpanel
, newc
, oldc
) {
73 // only add the subpath part for the
75 if (tabpanel
.items
.findIndex('id', newc
.id
) !== 0) {
76 newpath
+= ":" + newc
.getItemId();
79 me
.redirectTo(newpath
);
83 contentpanel
.setActiveItem(obj
);
86 contentpanel
.remove(lastpanel
, { destroy
: true });
94 navigate: function(treelist
, item
) {
95 this.redirectTo(item
.get('path'));
98 changeLanguage: function() {
99 Ext
.create('Proxmox.window.LanguageEditWindow', {
100 cookieName
: 'PMGLangCookie',
105 '[reference=logoutButton]': {
108 '[reference=languageButton]': {
109 click
: 'changeLanguage',
113 init: function(view
) {
117 me
.lookupReference('usernameinfo').setText(Proxmox
.UserName
);
119 // show login on requestexception
120 // fixme: what about other errors
121 Ext
.Ajax
.on('requestexception', function(conn
, response
, options
) {
122 if (response
.status
=== 401) { // auth failure
127 // get ticket periodically
128 Ext
.TaskManager
.start({
130 let ticket
= Proxmox
.Utils
.authOK();
131 if (!ticket
|| !Proxmox
.UserName
) {
137 username
: Proxmox
.UserName
,
140 url
: '/api2/json/access/ticket',
142 failure: function() {
145 success: function(response
, opts
) {
146 let obj
= Ext
.decode(response
.responseText
);
147 PMG
.Utils
.updateLoginData(obj
.data
);
151 interval
: 15*60*1000,
154 // select treeitem and load page from url fragment
155 let token
= Ext
.util
.History
.getToken() || 'pmgDashboard';
156 this.redirectTo(token
, { force
: true });
162 layout
: { type
: 'border' },
176 xtype
: 'proxmoxlogo',
180 xtype
: 'versioninfo',
186 xtype
: 'proxmoxHelpButton',
187 text
: gettext('Documentation'),
190 iconCls
: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ',
192 listenToGlobalEvent
: false,
193 onlineHelp
: 'pmg_documentation_index',
197 reference
: 'usernameinfo',
199 // proxmox dark grey p light grey as border
200 backgroundColor
: '#464d4d',
201 borderColor
: '#ABBABA',
204 iconCls
: 'fa fa-user',
207 iconCls
: 'fa fa-gear',
208 text
: gettext('My Settings'),
209 handler
: () => Ext
.create('PMG.window.Settings').show(),
212 iconCls
: 'fa fa-paint-brush',
213 text
: gettext('Theme'),
214 handler
: () => Ext
.create('Proxmox.window.ThemeEditWindow', {
215 cookieName
: 'PMGThemeCookie',
220 iconCls
: 'fa fa-language',
221 text
: gettext('Language'),
222 reference
: 'languageButton',
226 reference
: 'logoutButton',
227 iconCls
: 'fa fa-sign-out',
228 text
: gettext('Logout'),
245 xtype
: 'navigationtree',
247 reference
: 'navtree',
248 // we have to define it here until extjs 6.2 because of a bug where a
249 // viewcontroller does not detect the selectionchange event of a treelist
251 selectionchange
: 'navigate',
256 cls
: 'x-treelist-pve-nav',
263 layout
: { type
: 'card' },
266 reference
: 'contentpanel',