]> git.proxmox.com Git - pmg-gui.git/blame - js/Workspace.js
avoid to many gettext entries
[pmg-gui.git] / js / Workspace.js
CommitLineData
fe81f069
DM
1/*
2 * Workspace base class
3 *
4 * popup login window when auth fails (call onLogin handler)
5 * update (re-login) ticket every 15 minutes
6 *
7 */
8
9Ext.define('PMG.Workspace', {
10 extend: 'Ext.container.Viewport',
11
12 title: 'Proxmox Mail Gateway',
13
14 loginData: null, // Data from last login call
15
16 onLogin: function(loginData) {},
17
18 // private
19 updateLoginData: function(loginData) {
20 var me = this;
21
fe81f069 22 me.loginData = loginData;
2c7b542d
DM
23 Proxmox.CSRFPreventionToken = loginData.CSRFPreventionToken;
24 Proxmox.UserName = loginData.username;
fe81f069 25
3fd52fba 26 // creates a session cookie (expire = null)
fe81f069
DM
27 // that way the cookie gets deleted after browser window close
28 Ext.util.Cookies.set('PMGAuthCookie', loginData.ticket, null, '/', null, true);
29 me.onLogin(loginData);
30 },
31
32 // private
33 showLogin: function() {
34 var me = this;
35
2c7b542d
DM
36 Proxmox.Utils.authClear();
37 Proxmox.UserName = null;
fe81f069
DM
38 me.loginData = null;
39
40 if (!me.login) {
41 me.login = Ext.create('PMG.window.LoginWindow', {
42 handler: function(data) {
43 me.login = null;
44 me.updateLoginData(data);
45 }
46 });
47 }
48 me.onLogin(null);
49 me.login.show();
50 },
51
52 initComponent : function() {
53 var me = this;
54
55 Ext.tip.QuickTipManager.init();
56
57 // fixme: what about other errors
58 Ext.Ajax.on('requestexception', function(conn, response, options) {
59 if (response.status == 401) { // auth failure
60 me.showLogin();
61 }
62 });
63
64 me.callParent();
65
2c7b542d 66 if (!Proxmox.Utils.authOK()) {
fe81f069 67 me.showLogin();
3fd52fba 68 } else {
fe81f069
DM
69 if (me.loginData) {
70 me.onLogin(me.loginData);
71 }
72 }
73
74 Ext.TaskManager.start({
75 run: function() {
2c7b542d
DM
76 var ticket = Proxmox.Utils.authOK();
77 if (!ticket || !Proxmox.UserName) {
fe81f069
DM
78 return;
79 }
80
81 Ext.Ajax.request({
3fd52fba 82 params: {
2c7b542d 83 username: Proxmox.UserName,
fe81f069
DM
84 password: ticket
85 },
86 url: '/api2/json/access/ticket',
87 method: 'POST',
a3588c0c
DM
88 failure: function() {
89 me.showLogin();
90 },
fe81f069
DM
91 success: function(response, opts) {
92 var obj = Ext.decode(response.responseText);
93 me.updateLoginData(obj.data);
94 }
95 });
96 },
97 interval: 15*60*1000
98 });
99 }
100});
101
102Ext.define('PMG.StdWorkspace', {
103 extend: 'PMG.Workspace',
104
105 alias: ['widget.pmgStdWorkspace'],
106
fe81f069
DM
107 onLogin: function(loginData) {
108 var me = this;
109
110 me.updateUserInfo();
111
112 if (loginData) {
2c7b542d 113 Proxmox.Utils.API2Request({
fe81f069
DM
114 url: '/version',
115 method: 'GET',
116 success: function(response) {
117 PMG.VersionInfo = response.result.data;
118 me.updateVersionInfo();
119 }
120 });
121 }
122 },
123
124 updateUserInfo: function() {
125 var me = this;
126
127 var ui = me.query('#userinfo')[0];
128
2c7b542d
DM
129 if (Proxmox.UserName) {
130 var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + Proxmox.UserName + "'");
fe81f069
DM
131 ui.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg + '</div>');
132 } else {
133 ui.update('');
134 }
135 ui.updateLayout();
136 },
137
138 updateVersionInfo: function() {
139 var me = this;
140
141 var ui = me.query('#versioninfo')[0];
142
143 if (PMG.VersionInfo) {
144 var version = PMG.VersionInfo.version + '-' + PMG.VersionInfo.release + '/' +
145 PMG.VersionInfo.repoid;
146 ui.update('Mail Gateway ' + version);
147 } else {
148 ui.update('Mail Gateway');
149 }
150 ui.updateLayout();
151 },
152
153 initComponent : function() {
154 var me = this;
155
156 Ext.History.init();
157
158 // var sprovider = Ext.create('PVE.StateProvider');
159 // Ext.state.Manager.setProvider(sprovider);
160
161 Ext.apply(me, {
162 layout: { type: 'border' },
163 border: false,
164 items: [
165 {
166 region: 'north',
3fd52fba 167 layout: {
fe81f069
DM
168 type: 'hbox',
169 align: 'middle'
170 },
3fd52fba 171 baseCls: 'x-plain',
fe81f069 172 defaults: {
3fd52fba 173 baseCls: 'x-plain'
fe81f069
DM
174 },
175 border: false,
176 margin: '2 0 2 5',
177 items: [
178 {
179 html: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' +
180 '<img style="padding-top:4px;padding-right:5px" src="/pve2/images/proxmox_logo.png"/></a>'
181 },
182 {
183 minWidth: 200,
184 id: 'versioninfo',
185 html: 'Mail Gateway'
186 },
187 {
188 flex: 1
189 },
190 {
191 pack: 'end',
192 id: 'userinfo',
193 stateful: false
194 },
195 {
196 pack: 'end',
197 margin: '0 5 0 10',
198 xtype: 'button',
199 baseCls: 'x-btn',
200 iconCls: 'fa fa-sign-out',
201 text: gettext("Logout"),
3fd52fba
DM
202 handler: function() {
203 me.showLogin();
204 // fixme: me.setContent(null);
fe81f069
DM
205 }
206 }
207 ]
208 },
209 {
210 region: 'center',
211 stateful: true,
212 stateId: 'pvecenter',
213 minWidth: 100,
214 minHeight: 100,
215 id: 'content',
03912e15 216 defaults: { layout: 'fit' },
3fd52fba
DM
217 xtype: 'pmgPanelConfig',
218 items: [
219 {
220 xtype: 'panel',
221 title: 'Mail Filter',
222 itemId: 'filter',
223 expandedOnInit: true,
f1e32362 224 items: [{ xtype: 'pmgRuleConfiguration' }]
3fd52fba
DM
225 },
226 {
227 xtype: 'panel',
228 groups: ['filter'],
229 title: 'Actions',
230 itemId: 'filter-actions',
231 html: "Actions"
232 },
233 {
234 xtype: 'panel',
235 groups: ['filter'],
236 title: 'Who',
237 itemId: 'filter-who',
238 html: "Who"
239 },
240 {
241 xtype: 'panel',
242 groups: ['filter'],
243 title: 'What',
244 itemId: 'filter-what',
245 html: "What"
246 },
247 {
248 xtype: 'panel',
249 groups: ['filter'],
250 title: 'When',
251 itemId: 'filter-when',
252 html: "When"
253 },
254
255 {
256 xtype: 'panel',
257 title: 'Configuration',
258 itemId: 'configuration',
259 expandedOnInit: true,
e119071c 260 items: [{ xtype: 'pmgSystemConfiguration' }]
3fd52fba
DM
261 },
262 {
263 xtype: 'panel',
264 groups: ['configuration'],
265 title: 'Mail Proxy',
266 itemId: 'config-mail-proxy',
34c3efce 267 items: [{ xtype: 'pmgMailProxyConfiguration' }]
3fd52fba
DM
268 },
269 {
270 xtype: 'panel',
271 groups: ['configuration'],
272 title: 'Spam Detector',
273 itemId: 'config-spam',
4b5ee25e 274 items: [{ xtype: 'pmgSpamDetectorConfiguration' }]
3fd52fba
DM
275 },
276 {
277 xtype: 'panel',
278 groups: ['configuration'],
279 title: 'Virus Detector',
280 itemId: 'config-virus',
281 html: "Virus Detector"
282 },
283 {
284 xtype: 'panel',
285 groups: ['configuration'],
286 title: 'User Management',
287 itemId: 'config-users',
288 html: "User Management"
289 },
290 {
291 xtype: 'panel',
292 groups: ['configuration'],
293 title: 'Cluster',
294 itemId: 'config-cluster',
295 html: "Cluster"
296 },
297 {
298 xtype: 'panel',
299 groups: ['configuration'],
300 title: 'License',
301 itemId: 'config-license',
302 html: "License"
303 },
304
305 {
306 xtype: 'panel',
307 title: 'Administration',
308 itemId: 'admin',
309 expandedOnInit: true,
f1e32362 310 items: [{ xtype: 'pmgServerAdministration' }]
3fd52fba
DM
311 },
312 {
313 xtype: 'panel',
314 groups: ['admin'],
315 title: 'Statistics',
316 itemId: 'statistics',
317 html: "Statistics"
318 },
319 {
320 xtype: 'panel',
321 groups: ['admin'],
322 title: 'Quarantine',
323 itemId: 'quarantine',
324 html: "Quarantine"
325 },
326 {
327 xtype: 'panel',
328 groups: ['admin'],
329 title: 'Tracking Center',
330 itemId: 'tracking',
331 html: "Tracking Center"
332 },
333 {
334 xtype: 'panel',
335 groups: ['admin'],
336 title: 'Queues',
337 itemId: 'queues',
338 html: "Queues"
fe81f069 339 }
3fd52fba 340 ]
fe81f069
DM
341 }
342 ]
343 });
344
345 me.callParent();
346
347 me.updateUserInfo();
348
349 // on resize, center all modal windows
350 Ext.on('resize', function(){
351 var wins = Ext.ComponentQuery.query('window[modal]');
352 if (wins.length > 0) {
353 wins.forEach(function(win){
354 win.alignTo(me, 'c-c');
355 });
356 }
357 });
358 }
359});