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