]> git.proxmox.com Git - pmg-gui.git/blob - js/Workspace.js
rename WhoConfiguration.js to ObjectGroupConfiguration.js
[pmg-gui.git] / js / Workspace.js
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
9 Ext.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
22 me.loginData = loginData;
23 Proxmox.CSRFPreventionToken = loginData.CSRFPreventionToken;
24 Proxmox.UserName = loginData.username;
25
26 // creates a session cookie (expire = null)
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
36 Proxmox.Utils.authClear();
37 Proxmox.UserName = null;
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
66 if (!Proxmox.Utils.authOK()) {
67 me.showLogin();
68 } else {
69 if (me.loginData) {
70 me.onLogin(me.loginData);
71 }
72 }
73
74 Ext.TaskManager.start({
75 run: function() {
76 var ticket = Proxmox.Utils.authOK();
77 if (!ticket || !Proxmox.UserName) {
78 return;
79 }
80
81 Ext.Ajax.request({
82 params: {
83 username: Proxmox.UserName,
84 password: ticket
85 },
86 url: '/api2/json/access/ticket',
87 method: 'POST',
88 failure: function() {
89 me.showLogin();
90 },
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
102 Ext.define('PMG.StdWorkspace', {
103 extend: 'PMG.Workspace',
104
105 alias: ['widget.pmgStdWorkspace'],
106
107 onLogin: function(loginData) {
108 var me = this;
109
110 me.updateUserInfo();
111
112 if (loginData) {
113 Proxmox.Utils.API2Request({
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
129 if (Proxmox.UserName) {
130 var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + Proxmox.UserName + "'");
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',
167 layout: {
168 type: 'hbox',
169 align: 'middle'
170 },
171 baseCls: 'x-plain',
172 defaults: {
173 baseCls: 'x-plain'
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"),
202 handler: function() {
203 me.showLogin();
204 // fixme: me.setContent(null);
205 }
206 }
207 ]
208 },
209 {
210 region: 'center',
211 stateful: true,
212 stateId: 'pvecenter',
213 minWidth: 100,
214 minHeight: 100,
215 id: 'content',
216 defaults: { layout: 'fit' },
217 xtype: 'pmgPanelConfig',
218 items: [
219 {
220 xtype: 'panel',
221 title: gettext('Mail Filter'),
222 itemId: 'filter',
223 expandedOnInit: true,
224 items: [{ xtype: 'pmgRuleConfiguration' }]
225 },
226 {
227 xtype: 'panel',
228 groups: ['filter'],
229 title: PMG.Utils.oclass_text['action'],
230 itemId: 'filter-actions',
231 items: [{ xtype: 'pmgActionConfiguration' }]
232 },
233 {
234 xtype: 'panel',
235 groups: ['filter'],
236 title: PMG.Utils.oclass_text['who'],
237 itemId: 'filter-who',
238 items: [{ xtype: 'pmgWhoConfiguration' }]
239 },
240 {
241 xtype: 'panel',
242 groups: ['filter'],
243 title: PMG.Utils.oclass_text['what'],
244 itemId: 'filter-what',
245 items: [{ xtype: 'pmgWhatConfiguration' }]
246
247 },
248 {
249 xtype: 'panel',
250 groups: ['filter'],
251 title: PMG.Utils.oclass_text['when'],
252 itemId: 'filter-when',
253 items: [{ xtype: 'pmgWhenConfiguration' }]
254 },
255 {
256 xtype: 'panel',
257 title: 'Configuration',
258 itemId: 'configuration',
259 expandedOnInit: true,
260 items: [{ xtype: 'pmgSystemConfiguration' }]
261 },
262 {
263 xtype: 'panel',
264 groups: ['configuration'],
265 title: gettext('Mail Proxy'),
266 itemId: 'config-mail-proxy',
267 items: [{ xtype: 'pmgMailProxyConfiguration' }]
268 },
269 {
270 xtype: 'panel',
271 groups: ['configuration'],
272 title: gettext('Spam Detector'),
273 itemId: 'config-spam',
274 items: [{ xtype: 'pmgSpamDetectorConfiguration' }]
275 },
276 {
277 xtype: 'panel',
278 groups: ['configuration'],
279 title: gettext('Virus Detector'),
280 itemId: 'config-virus',
281 items: [{ xtype: 'pmgVirusDetectorConfiguration' }]
282 },
283 {
284 xtype: 'panel',
285 groups: ['configuration'],
286 title: gettext('User Management'),
287 itemId: 'config-users',
288 html: "User Management"
289 },
290 {
291 xtype: 'panel',
292 groups: ['configuration'],
293 title: gettext('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: gettext('Administration'),
308 itemId: 'admin',
309 expandedOnInit: true,
310 items: [{ xtype: 'pmgServerAdministration' }]
311 },
312 {
313 xtype: 'panel',
314 groups: ['admin'],
315 title: gettext('Statistics'),
316 itemId: 'statistics',
317 html: "Statistics"
318 },
319 {
320 xtype: 'panel',
321 groups: ['admin'],
322 title: gettext('Quarantine'),
323 itemId: 'quarantine',
324 html: "Quarantine"
325 },
326 {
327 xtype: 'panel',
328 groups: ['admin'],
329 title: gettext('Tracking Center'),
330 itemId: 'tracking',
331 html: "Tracking Center"
332 },
333 {
334 xtype: 'panel',
335 groups: ['admin'],
336 title: gettext('Queues'),
337 itemId: 'queues',
338 html: "Queues"
339 }
340 ]
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 });