]>
git.proxmox.com Git - proxmox-backup.git/blob - www/MainView.js
1 Ext
.define('PBS.MainView', {
2 extend
: 'Ext.container.Container',
5 title
: 'Proxmox Backup Server',
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
, subpath
, action
) {
25 let isDataStore
= PBS
.Utils
.isDataStorePath(path
);
27 xtype
= 'pbsDataStorePanel';
28 datastore
= PBS
.Utils
.getDataStoreFromPath(path
);
31 if (!Ext
.ClassManager
.getByAlias(`widget.${xtype}`)) {
32 console
.warn(`xtype ${xtype} not found`);
37 var lastpanel
= me
.lookupReference('contentpanel').getLayout().getActiveItem();
38 if (lastpanel
&& lastpanel
.xtype
=== xtype
) {
40 if (datastore
=== lastpanel
.datastore
) {
45 // we have the right component already,
46 // we just need to select the correct tab
47 // default to the first
48 subpath
= subpath
|| 0;
49 if (lastpanel
.getActiveTab
) {
50 // we assume lastpanel is a tabpanel
51 if (lastpanel
.getActiveTab().getItemId() !== subpath
) {
53 lastpanel
.setActiveTab(subpath
);
55 // else we are already there
65 changePath: function(path
, subpath
) {
67 var contentpanel
= me
.lookupReference('contentpanel');
68 var lastpanel
= contentpanel
.getLayout().getActiveItem();
71 if (PBS
.Utils
.isDataStorePath(path
)) {
72 let datastore
= PBS
.Utils
.getDataStoreFromPath(path
);
73 obj
= contentpanel
.add({
74 xtype
: 'pbsDataStorePanel',
75 nodename
: 'localhost',
79 obj
= contentpanel
.add({
81 nodename
: 'localhost',
86 var treelist
= me
.lookupReference('navtree');
88 treelist
.suspendEvents();
89 if (subpath
=== undefined) {
90 treelist
.select(path
);
92 treelist
.select(path
+ ':' + subpath
);
94 treelist
.resumeEvents();
96 if (Ext
.isFunction(obj
.setActiveTab
)) {
97 obj
.setActiveTab(subpath
|| 0);
98 obj
.addListener('tabchange', function(tabpanel
, newc
, oldc
) {
101 // only add the subpath part for the
103 if (tabpanel
.items
.findIndex('id', newc
.id
) !== 0) {
104 newpath
+= ":" + newc
.getItemId();
107 me
.redirectTo(newpath
);
111 contentpanel
.setActiveItem(obj
);
114 contentpanel
.remove(lastpanel
, { destroy
: true });
123 navigate: function(treelist
, item
) {
124 this.redirectTo(item
.get('path'));
128 '[reference=logoutButton]': {
133 init: function(view
) {
136 PBS
.data
.RunningTasksStore
.startUpdate();
137 me
.lookupReference('usernameinfo').setText(Proxmox
.UserName
);
139 // show login on requestexception
140 // fixme: what about other errors
141 Ext
.Ajax
.on('requestexception', function(conn
, response
, options
) {
142 if (response
.status
== 401) { // auth failure
147 // get ticket periodically
148 Ext
.TaskManager
.start({
150 var ticket
= Proxmox
.Utils
.authOK();
151 if (!ticket
|| !Proxmox
.UserName
) {
157 username
: Proxmox
.UserName
,
160 url
: '/api2/json/access/ticket',
162 failure: function() {
165 success: function(response
, opts
) {
166 var obj
= Ext
.decode(response
.responseText
);
167 PBS
.Utils
.updateLoginData(obj
.data
);
175 // select treeitem and load page from url fragment, if set
176 let token
= Ext
.util
.History
.getToken() || 'pbsDashboard';
177 this.redirectTo(token
, true);
183 layout
: { type
: 'border' },
197 xtype
: 'proxmoxlogo',
202 xtype
: 'versioninfo',
206 html
: '<a href="https://bugzilla.proxmox.com" target="_blank">BETA</a>',
216 cls
: 'x-btn-default-toolbar-small proxmox-inline-button',
217 iconCls
: 'fa fa-book x-btn-icon-el-default-toolbar-small ',
218 text
: gettext('Documentation'),
219 href
: '/docs/index.html',
223 xtype
: 'pbsTaskButton',
228 reference
: 'usernameinfo',
230 // proxmox dark grey p light grey as border
231 backgroundColor
: '#464d4d',
232 borderColor
: '#ABBABA'
235 iconCls
: 'fa fa-user',
238 reference
: 'logoutButton',
239 iconCls
: 'fa fa-sign-out',
240 text
: gettext('Logout'),
256 xtype
: 'navigationtree',
258 reference
: 'navtree',
259 // we have to define it here until extjs 6.2
260 // because of a bug where a viewcontroller does not detect
261 // the selectionchange event of a treelist
263 selectionchange
: 'navigate'
267 cls
: 'x-treelist-nav',
273 layout
: { type
: 'card' },
276 reference
: 'contentpanel'