]>
Commit | Line | Data |
---|---|---|
5c7a1b15 DM |
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 | ||
b0ee976f DM |
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 | ||
5c7a1b15 DM |
47 | action.resume(); |
48 | }, | |
49 | ||
b0ee976f | 50 | changePath: function(path,subpath) { |
5c7a1b15 DM |
51 | var me = this; |
52 | var contentpanel = me.lookupReference('contentpanel'); | |
53 | var lastpanel = contentpanel.getLayout().getActiveItem(); | |
54 | ||
b0ee976f DM |
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 | ||
34f956bc DM |
85 | logout: function() { |
86 | PBS.app.logout(); | |
87 | }, | |
88 | ||
b0ee976f DM |
89 | navigate: function(treelist, item) { |
90 | this.redirectTo(item.get('path')); | |
5c7a1b15 DM |
91 | }, |
92 | ||
34f956bc DM |
93 | control: { |
94 | 'button[reference=logoutButton]': { | |
95 | click: 'logout' | |
96 | } | |
97 | }, | |
98 | ||
5c7a1b15 DM |
99 | init: function(view) { |
100 | var me = this; | |
5c7a1b15 | 101 | |
87b4d953 | 102 | me.lookupReference('usernameinfo').update({username:Proxmox.UserName}); |
a602faeb | 103 | |
8af272fd TL |
104 | // show login on requestexception |
105 | // fixme: what about other errors | |
106 | Ext.Ajax.on('requestexception', function(conn, response, options) { | |
107 | if (response.status == 401) { // auth failure | |
108 | me.logout(); | |
109 | } | |
110 | }); | |
111 | ||
a602faeb TL |
112 | // get ticket periodically |
113 | Ext.TaskManager.start({ | |
114 | run: function() { | |
115 | var ticket = Proxmox.Utils.authOK(); | |
116 | if (!ticket || !Proxmox.UserName) { | |
117 | return; | |
118 | } | |
119 | ||
120 | Ext.Ajax.request({ | |
121 | params: { | |
122 | username: Proxmox.UserName, | |
123 | password: ticket | |
124 | }, | |
125 | url: '/api2/json/access/ticket', | |
126 | method: 'POST', | |
127 | failure: function() { | |
128 | me.logout(); | |
129 | }, | |
130 | success: function(response, opts) { | |
131 | var obj = Ext.decode(response.responseText); | |
323515c2 | 132 | PBS.Utils.updateLoginData(obj.data); |
a602faeb TL |
133 | } |
134 | }); | |
135 | }, | |
136 | interval: 15*60*1000 | |
137 | }); | |
5c7a1b15 DM |
138 | } |
139 | }, | |
140 | ||
141 | plugins: 'viewport', | |
142 | ||
143 | layout: { type: 'border' }, | |
144 | ||
145 | items: [ | |
146 | { | |
147 | region: 'north', | |
148 | xtype: 'container', | |
149 | layout: { | |
150 | type: 'hbox', | |
151 | align: 'middle' | |
152 | }, | |
153 | margin: '2 5 2 5', | |
154 | height: 38, | |
155 | items: [ | |
156 | { | |
157 | xtype: 'proxmoxlogo' | |
158 | }, | |
159 | { | |
e4dc0a14 | 160 | xtype: 'versioninfo' |
5c7a1b15 DM |
161 | }, |
162 | { | |
163 | flex: 1 | |
164 | }, | |
165 | { | |
166 | baseCls: 'x-plain', | |
167 | reference: 'usernameinfo', | |
168 | padding: '0 5', | |
169 | tpl: Ext.String.format(gettext("You are logged in as {0}"), "'{username}'") | |
170 | }, | |
9c01e73c TL |
171 | { |
172 | xtype: 'button', | |
173 | baseCls: 'x-btn', | |
174 | cls: 'x-btn-default-toolbar-small proxmox-inline-button', | |
175 | iconCls: 'fa fa-book x-btn-icon-el-default-toolbar-small ', | |
176 | text: gettext('Documentation'), | |
177 | href: '/docs/index.html', | |
178 | margin: '0 5 0 0', | |
179 | }, | |
5c7a1b15 DM |
180 | { |
181 | reference: 'logoutButton', | |
182 | xtype: 'button', | |
183 | iconCls: 'fa fa-sign-out', | |
184 | text: gettext('Logout') | |
185 | } | |
186 | ] | |
187 | }, | |
188 | { | |
189 | xtype: 'panel', | |
190 | scrollable: 'y', | |
191 | border: false, | |
192 | region: 'west', | |
193 | layout: { | |
194 | type: 'vbox', | |
195 | align: 'stretch' | |
196 | }, | |
b0ee976f DM |
197 | items: [{ |
198 | xtype: 'navigationtree', | |
199 | minWidth: 180, | |
200 | reference: 'navtree', | |
201 | // we have to define it here until extjs 6.2 | |
202 | // because of a bug where a viewcontroller does not detect | |
203 | // the selectionchange event of a treelist | |
204 | listeners: { | |
205 | selectionchange: 'navigate' | |
206 | } | |
207 | }, { | |
208 | xtype: 'box', | |
209 | cls: 'x-treelist-nav', | |
210 | flex: 1 | |
211 | }] | |
5c7a1b15 DM |
212 | }, |
213 | { | |
214 | xtype: 'panel', | |
215 | layout: { type: 'card' }, | |
216 | region: 'center', | |
217 | border: false, | |
218 | reference: 'contentpanel' | |
219 | } | |
220 | ] | |
221 | }); | |
222 | ||
223 |