]> git.proxmox.com Git - proxmox-backup.git/blob - www/MainView.js
ui: re-new ticket every 15 minutes
[proxmox-backup.git] / www / MainView.js
1 Ext.define('PBS.MainView', {
2 extend: 'Ext.container.Container',
3 xtype: 'mainview',
4
5 title: 'Proxmox Backup Server',
6
7 controller: {
8 xclass: 'Ext.app.ViewController',
9 routes: {
10 ':path:subpath': {
11 action: 'changePath',
12 before: 'beforeChangePath',
13 conditions : {
14 ':path' : '(?:([%a-zA-Z0-9\\-\\_\\s,]+))',
15 ':subpath' : '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?'
16 }
17 }
18 },
19
20 beforeChangePath: function(path, subpath, action) {
21 var me = this;
22
23 if (!Ext.ClassManager.getByAlias('widget.'+ path)) {
24 console.warn('xtype "'+path+'" not found');
25 action.stop();
26 return;
27 }
28
29 var lastpanel = me.lookupReference('contentpanel').getLayout().getActiveItem();
30 if (lastpanel && lastpanel.xtype === path) {
31 // we have the right component already,
32 // we just need to select the correct tab
33 // default to the first
34 subpath = subpath || 0;
35 if (lastpanel.getActiveTab) {
36 // we assume lastpanel is a tabpanel
37 if (lastpanel.getActiveTab().getItemId() !== subpath) {
38 // set the active tab
39 lastpanel.setActiveTab(subpath);
40 }
41 // else we are already there
42 }
43 action.stop();
44 return;
45 }
46
47 action.resume();
48 },
49
50 changePath: function(path,subpath) {
51 var me = this;
52 var contentpanel = me.lookupReference('contentpanel');
53 var lastpanel = contentpanel.getLayout().getActiveItem();
54
55 var obj = contentpanel.add({ xtype: path });
56 var treelist = me.lookupReference('navtree');
57
58 treelist.suspendEvents();
59 treelist.select(path);
60 treelist.resumeEvents();
61
62 if (Ext.isFunction(obj.setActiveTab)) {
63 obj.setActiveTab(subpath || 0);
64 obj.addListener('tabchange', function(tabpanel, newc, oldc) {
65 var newpath = path;
66
67 // only add the subpath part for the
68 // non-default tabs
69 if (tabpanel.items.findIndex('id', newc.id) !== 0) {
70 newpath += ":" + newc.getItemId();
71 }
72
73 me.redirectTo(newpath);
74 });
75 }
76
77 contentpanel.setActiveItem(obj);
78
79 if (lastpanel) {
80 contentpanel.remove(lastpanel, { destroy: true });
81 }
82
83 },
84
85 logout: function() {
86 PBS.app.logout();
87 },
88
89 navigate: function(treelist, item) {
90 this.redirectTo(item.get('path'));
91 },
92
93 control: {
94 'button[reference=logoutButton]': {
95 click: 'logout'
96 }
97 },
98
99 init: function(view) {
100 var me = this;
101
102 me.lookupReference('usernameinfo').update({username:Proxmox.UserName});
103
104 // get ticket periodically
105 Ext.TaskManager.start({
106 run: function() {
107 var ticket = Proxmox.Utils.authOK();
108 if (!ticket || !Proxmox.UserName) {
109 return;
110 }
111
112 Ext.Ajax.request({
113 params: {
114 username: Proxmox.UserName,
115 password: ticket
116 },
117 url: '/api2/json/access/ticket',
118 method: 'POST',
119 failure: function() {
120 me.logout();
121 },
122 success: function(response, opts) {
123 var obj = Ext.decode(response.responseText);
124 PMG.Utils.updateLoginData(obj.data);
125 }
126 });
127 },
128 interval: 15*60*1000
129 });
130 }
131 },
132
133 plugins: 'viewport',
134
135 layout: { type: 'border' },
136
137 items: [
138 {
139 region: 'north',
140 xtype: 'container',
141 layout: {
142 type: 'hbox',
143 align: 'middle'
144 },
145 margin: '2 5 2 5',
146 height: 38,
147 items: [
148 {
149 xtype: 'proxmoxlogo'
150 },
151 {
152 xtype: 'versioninfo'
153 },
154 {
155 flex: 1
156 },
157 {
158 baseCls: 'x-plain',
159 reference: 'usernameinfo',
160 padding: '0 5',
161 tpl: Ext.String.format(gettext("You are logged in as {0}"), "'{username}'")
162 },
163 {
164 xtype: 'button',
165 baseCls: 'x-btn',
166 cls: 'x-btn-default-toolbar-small proxmox-inline-button',
167 iconCls: 'fa fa-book x-btn-icon-el-default-toolbar-small ',
168 text: gettext('Documentation'),
169 href: '/docs/index.html',
170 margin: '0 5 0 0',
171 },
172 {
173 reference: 'logoutButton',
174 xtype: 'button',
175 iconCls: 'fa fa-sign-out',
176 text: gettext('Logout')
177 }
178 ]
179 },
180 {
181 xtype: 'panel',
182 scrollable: 'y',
183 border: false,
184 region: 'west',
185 layout: {
186 type: 'vbox',
187 align: 'stretch'
188 },
189 items: [{
190 xtype: 'navigationtree',
191 minWidth: 180,
192 reference: 'navtree',
193 // we have to define it here until extjs 6.2
194 // because of a bug where a viewcontroller does not detect
195 // the selectionchange event of a treelist
196 listeners: {
197 selectionchange: 'navigate'
198 }
199 }, {
200 xtype: 'box',
201 cls: 'x-treelist-nav',
202 flex: 1
203 }]
204 },
205 {
206 xtype: 'panel',
207 layout: { type: 'card' },
208 region: 'center',
209 border: false,
210 reference: 'contentpanel'
211 }
212 ]
213 });
214
215