]>
Commit | Line | Data |
---|---|---|
2c1d504e | 1 | /*global Proxmox*/ |
9d91eeb0 DC |
2 | Ext.define('PMG.MainView', { |
3 | extend: 'Ext.container.Container', | |
4 | xtype: 'mainview', | |
5 | ||
6 | title: 'Proxmox Mail Gateway', | |
7 | ||
8 | controller: { | |
9 | xclass: 'Ext.app.ViewController', | |
10 | routes: { | |
11 | ':path:subpath': { | |
12 | action: 'changePath', | |
13 | before: 'beforeChangePath', | |
14 | conditions : { | |
6355fc2c DC |
15 | ':path' : '(?:([%a-zA-Z0-9\\-\\_\\s,]+))', |
16 | ':subpath' : '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?' | |
9d91eeb0 DC |
17 | } |
18 | } | |
19 | }, | |
20 | ||
21 | beforeChangePath: function(path, subpath, action) { | |
22 | var me = this; | |
23 | ||
24 | if (!Ext.ClassManager.getByAlias('widget.'+ path)) { | |
25 | console.warn('xtype "'+path+'" not found'); | |
26 | action.stop(); | |
27 | return; | |
28 | } | |
29 | ||
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 | |
2468e1a1 | 38 | if (lastpanel.getActiveTab().getItemId() !== subpath) { |
9d91eeb0 DC |
39 | // set the active tab |
40 | lastpanel.setActiveTab(subpath); | |
41 | } | |
2468e1a1 | 42 | // else we are already there |
9d91eeb0 DC |
43 | } |
44 | action.stop(); | |
45 | return; | |
46 | } | |
47 | ||
48 | action.resume(); | |
49 | }, | |
50 | ||
51 | changePath: function(path,subpath) { | |
52 | var me = this; | |
53 | var contentpanel = me.lookupReference('contentpanel'); | |
54 | var lastpanel = contentpanel.getLayout().getActiveItem(); | |
55 | ||
56 | var obj = contentpanel.add({ xtype: path }); | |
57 | var treelist = me.lookupReference('navtree'); | |
58 | ||
59 | treelist.suspendEvents(); | |
60 | treelist.select(path); | |
61 | treelist.resumeEvents(); | |
62 | ||
63 | if (Ext.isFunction(obj.setActiveTab)) { | |
64 | obj.setActiveTab(subpath || 0); | |
65 | obj.addListener('tabchange', function(tabpanel, newc, oldc) { | |
66 | var newpath = path; | |
67 | ||
68 | // only add the subpath part for the | |
69 | // non-default tabs | |
70 | if (tabpanel.items.findIndex('id', newc.id) !== 0) { | |
71 | newpath += ":" + newc.getItemId(); | |
72 | } | |
73 | ||
74 | me.redirectTo(newpath); | |
75 | }); | |
76 | } | |
77 | ||
78 | contentpanel.setActiveItem(obj); | |
79 | ||
80 | if (lastpanel) { | |
81 | contentpanel.remove(lastpanel, { destroy: true }); | |
82 | } | |
83 | ||
84 | }, | |
85 | ||
86 | logout: function() { | |
99bba12c | 87 | PMG.app.logout(); |
9d91eeb0 DC |
88 | }, |
89 | ||
90 | navigate: function(treelist, item) { | |
91 | this.redirectTo(item.get('path')); | |
92 | }, | |
93 | ||
94 | control: { | |
95 | 'button[reference=logoutButton]': { | |
96 | click: 'logout' | |
97 | } | |
98 | }, | |
99 | ||
100 | init: function(view) { | |
101 | var me = this; | |
102 | ||
103 | // load username | |
104 | me.lookupReference('usernameinfo').update({username:Proxmox.UserName}); | |
105 | ||
106 | // show login on requestexception | |
107 | // fixme: what about other errors | |
108 | Ext.Ajax.on('requestexception', function(conn, response, options) { | |
109 | if (response.status == 401) { // auth failure | |
110 | me.logout(); | |
111 | } | |
112 | }); | |
113 | ||
114 | // get ticket periodically | |
115 | Ext.TaskManager.start({ | |
116 | run: function() { | |
117 | var ticket = Proxmox.Utils.authOK(); | |
118 | if (!ticket || !Proxmox.UserName) { | |
119 | return; | |
120 | } | |
121 | ||
122 | Ext.Ajax.request({ | |
123 | params: { | |
124 | username: Proxmox.UserName, | |
125 | password: ticket | |
126 | }, | |
127 | url: '/api2/json/access/ticket', | |
128 | method: 'POST', | |
129 | failure: function() { | |
130 | me.logout(); | |
131 | }, | |
132 | success: function(response, opts) { | |
133 | var obj = Ext.decode(response.responseText); | |
134 | PMG.Utils.updateLoginData(obj.data); | |
135 | } | |
136 | }); | |
137 | }, | |
138 | interval: 15*60*1000 | |
139 | }); | |
140 | ||
141 | // select treeitem and load page from url fragment | |
033228c0 | 142 | var token = Ext.util.History.getToken() || 'pmgDashboard'; |
9d91eeb0 DC |
143 | this.redirectTo(token, true); |
144 | ||
145 | } | |
146 | }, | |
147 | ||
148 | plugins: 'viewport', | |
149 | ||
ea07c9aa | 150 | layout: { type: 'border' }, |
9d91eeb0 DC |
151 | |
152 | items: [ | |
153 | { | |
154 | region: 'north', | |
155 | xtype: 'container', | |
156 | layout: { | |
157 | type: 'hbox', | |
158 | align: 'middle' | |
159 | }, | |
c45e23e4 DC |
160 | margin: '2 5 2 5', |
161 | height: 38, | |
9d91eeb0 DC |
162 | items: [ |
163 | { | |
164 | xtype: 'proxmoxlogo' | |
165 | }, | |
166 | { | |
167 | xtype: 'versioninfo' | |
168 | }, | |
1a119c52 SI |
169 | { |
170 | padding: 3, | |
171 | xtype: 'box', | |
172 | html: '<a href="https://bugzilla.proxmox.com" target="_blank">BETA</a>' | |
173 | }, | |
9d91eeb0 DC |
174 | { |
175 | flex: 1 | |
176 | }, | |
177 | { | |
178 | baseCls: 'x-plain', | |
179 | reference: 'usernameinfo', | |
180 | padding: '0 5', | |
64fb657f | 181 | tpl: Ext.String.format(gettext("You are logged in as {0}"), "'{username}'") |
9d91eeb0 | 182 | }, |
6a3d1c51 DM |
183 | { |
184 | xtype: 'proxmoxHelpButton', | |
0c503218 | 185 | text: gettext('Documentation'), |
6a3d1c51 DM |
186 | hidden: false, |
187 | baseCls: 'x-btn', | |
188 | iconCls: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ', | |
c45e23e4 | 189 | margin: '0 5 0 0', |
6a3d1c51 DM |
190 | listenToGlobalEvent: false, |
191 | onlineHelp: 'pmg_documentation_index' | |
192 | }, | |
9d91eeb0 DC |
193 | { |
194 | reference: 'logoutButton', | |
195 | xtype: 'button', | |
196 | iconCls: 'fa fa-sign-out', | |
749af060 | 197 | text: gettext('Logout') |
9d91eeb0 DC |
198 | } |
199 | ] | |
200 | }, | |
201 | { | |
2c866ec9 DC |
202 | xtype: 'panel', |
203 | scrollable: 'y', | |
9d91eeb0 DC |
204 | border: false, |
205 | region: 'west', | |
2c866ec9 DC |
206 | layout: { |
207 | type: 'vbox', | |
208 | align: 'stretch' | |
209 | }, | |
210 | items: [{ | |
211 | xtype: 'navigationtree', | |
212 | minWidth: 180, | |
213 | reference: 'navtree', | |
214 | // we have to define it here until extjs 6.2 | |
215 | // because of a bug where a viewcontroller does not detect | |
216 | // the selectionchange event of a treelist | |
217 | listeners: { | |
218 | selectionchange: 'navigate' | |
219 | } | |
220 | }, { | |
221 | xtype: 'box', | |
222 | cls: 'x-treelist-nav', | |
223 | flex: 1 | |
224 | }] | |
9d91eeb0 DC |
225 | }, |
226 | { | |
227 | xtype: 'panel', | |
ea07c9aa | 228 | layout: { type: 'card' }, |
9d91eeb0 DC |
229 | region: 'center', |
230 | border: false, | |
749af060 | 231 | reference: 'contentpanel' |
9d91eeb0 DC |
232 | } |
233 | ] | |
234 | }); |