]>
Commit | Line | Data |
---|---|---|
5c7a1b15 DM |
1 | Ext.define('PBS.MainView', { |
2 | extend: 'Ext.container.Container', | |
3 | xtype: 'mainview', | |
4 | ||
5 | title: 'Proxmox Backup Server', | |
6 | ||
7 | controller: { | |
8 | xclass: 'Ext.app.ViewController', | |
9 | routes: { | |
10 | ':path:subpath': { | |
11 | action: 'changePath', | |
12 | before: 'beforeChangePath', | |
13 | conditions : { | |
14 | ':path' : '(?:([%a-zA-Z0-9\\-\\_\\s,]+))', | |
15 | ':subpath' : '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?' | |
16 | } | |
17 | } | |
18 | }, | |
19 | ||
20 | beforeChangePath: function(path, subpath, action) { | |
21 | var me = this; | |
22 | ||
b0ee976f DM |
23 | if (!Ext.ClassManager.getByAlias('widget.'+ path)) { |
24 | console.warn('xtype "'+path+'" not found'); | |
25 | action.stop(); | |
26 | return; | |
27 | } | |
28 | ||
29 | var lastpanel = me.lookupReference('contentpanel').getLayout().getActiveItem(); | |
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 | |
37 | if (lastpanel.getActiveTab().getItemId() !== subpath) { | |
38 | // set the active tab | |
39 | lastpanel.setActiveTab(subpath); | |
40 | } | |
41 | // else we are already there | |
42 | } | |
43 | action.stop(); | |
44 | return; | |
45 | } | |
46 | ||
5c7a1b15 DM |
47 | action.resume(); |
48 | }, | |
49 | ||
b0ee976f | 50 | changePath: function(path,subpath) { |
5c7a1b15 DM |
51 | var me = this; |
52 | var contentpanel = me.lookupReference('contentpanel'); | |
53 | var lastpanel = contentpanel.getLayout().getActiveItem(); | |
54 | ||
b0ee976f DM |
55 | var obj = contentpanel.add({ xtype: path }); |
56 | var treelist = me.lookupReference('navtree'); | |
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) { | |
65 | var newpath = path; | |
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 | } | |
82 | ||
83 | }, | |
84 | ||
85 | navigate: function(treelist, item) { | |
86 | this.redirectTo(item.get('path')); | |
5c7a1b15 DM |
87 | }, |
88 | ||
89 | init: function(view) { | |
90 | var me = this; | |
91 | console.log("init"); | |
92 | ||
93 | } | |
94 | }, | |
95 | ||
96 | plugins: 'viewport', | |
97 | ||
98 | layout: { type: 'border' }, | |
99 | ||
100 | items: [ | |
101 | { | |
102 | region: 'north', | |
103 | xtype: 'container', | |
104 | layout: { | |
105 | type: 'hbox', | |
106 | align: 'middle' | |
107 | }, | |
108 | margin: '2 5 2 5', | |
109 | height: 38, | |
110 | items: [ | |
111 | { | |
112 | xtype: 'proxmoxlogo' | |
113 | }, | |
114 | { | |
e4dc0a14 | 115 | xtype: 'versioninfo' |
5c7a1b15 DM |
116 | }, |
117 | { | |
118 | flex: 1 | |
119 | }, | |
120 | { | |
121 | baseCls: 'x-plain', | |
122 | reference: 'usernameinfo', | |
123 | padding: '0 5', | |
124 | tpl: Ext.String.format(gettext("You are logged in as {0}"), "'{username}'") | |
125 | }, | |
126 | { | |
127 | reference: 'logoutButton', | |
128 | xtype: 'button', | |
129 | iconCls: 'fa fa-sign-out', | |
130 | text: gettext('Logout') | |
131 | } | |
132 | ] | |
133 | }, | |
134 | { | |
135 | xtype: 'panel', | |
136 | scrollable: 'y', | |
137 | border: false, | |
138 | region: 'west', | |
139 | layout: { | |
140 | type: 'vbox', | |
141 | align: 'stretch' | |
142 | }, | |
b0ee976f DM |
143 | items: [{ |
144 | xtype: 'navigationtree', | |
145 | minWidth: 180, | |
146 | reference: 'navtree', | |
147 | // we have to define it here until extjs 6.2 | |
148 | // because of a bug where a viewcontroller does not detect | |
149 | // the selectionchange event of a treelist | |
150 | listeners: { | |
151 | selectionchange: 'navigate' | |
152 | } | |
153 | }, { | |
154 | xtype: 'box', | |
155 | cls: 'x-treelist-nav', | |
156 | flex: 1 | |
157 | }] | |
5c7a1b15 DM |
158 | }, |
159 | { | |
160 | xtype: 'panel', | |
161 | layout: { type: 'card' }, | |
162 | region: 'center', | |
163 | border: false, | |
164 | reference: 'contentpanel' | |
165 | } | |
166 | ] | |
167 | }); | |
168 | ||
169 |