]> git.proxmox.com Git - pmg-gui.git/blame - js/MainView.js
add colors and icons to trackingcenter
[pmg-gui.git] / js / MainView.js
CommitLineData
2c1d504e 1/*global Proxmox*/
9d91eeb0
DC
2Ext.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
afbec2f8
DC
141 var provider = Ext.state.Manager.getProvider();
142 if (!provider || provider.prefix !== 'ext-pmg-') {
143 provider = new Ext.state.LocalStorageProvider({
144 prefix: 'ext-pmg-' });
145 Ext.state.Manager.setProvider(provider);
146 }
a27e6c36 147
9d91eeb0 148 // select treeitem and load page from url fragment
033228c0 149 var token = Ext.util.History.getToken() || 'pmgDashboard';
9d91eeb0
DC
150 this.redirectTo(token, true);
151
152 }
153 },
154
155 plugins: 'viewport',
156
ea07c9aa 157 layout: { type: 'border' },
9d91eeb0
DC
158
159 items: [
160 {
161 region: 'north',
162 xtype: 'container',
163 layout: {
164 type: 'hbox',
165 align: 'middle'
166 },
167 margin: '4 5 4 5',
168 items: [
169 {
170 xtype: 'proxmoxlogo'
171 },
172 {
173 xtype: 'versioninfo'
174 },
175 {
176 flex: 1
177 },
178 {
179 baseCls: 'x-plain',
180 reference: 'usernameinfo',
181 padding: '0 5',
182 tpl: Ext.String.format(gettext("You are logged in as '{0}'"), '{username}')
183 },
6a3d1c51
DM
184 {
185 xtype: 'proxmoxHelpButton',
186 hidden: false,
187 baseCls: 'x-btn',
188 iconCls: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ',
189 listenToGlobalEvent: false,
190 onlineHelp: 'pmg_documentation_index'
191 },
9d91eeb0
DC
192 {
193 reference: 'logoutButton',
194 xtype: 'button',
195 iconCls: 'fa fa-sign-out',
749af060 196 text: gettext('Logout')
9d91eeb0
DC
197 }
198 ]
199 },
200 {
2c866ec9
DC
201 xtype: 'panel',
202 scrollable: 'y',
9d91eeb0
DC
203 border: false,
204 region: 'west',
2c866ec9
DC
205 layout: {
206 type: 'vbox',
207 align: 'stretch'
208 },
209 items: [{
210 xtype: 'navigationtree',
211 minWidth: 180,
212 reference: 'navtree',
213 // we have to define it here until extjs 6.2
214 // because of a bug where a viewcontroller does not detect
215 // the selectionchange event of a treelist
216 listeners: {
217 selectionchange: 'navigate'
218 }
219 }, {
220 xtype: 'box',
221 cls: 'x-treelist-nav',
222 flex: 1
223 }]
9d91eeb0
DC
224 },
225 {
226 xtype: 'panel',
ea07c9aa 227 layout: { type: 'card' },
9d91eeb0
DC
228 region: 'center',
229 border: false,
749af060 230 reference: 'contentpanel'
9d91eeb0
DC
231 }
232 ]
233});