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