]> git.proxmox.com Git - proxmox-backup.git/blob - www/NavigationTree.js
6524a5c39612ce03eebed196c9b5c10041d91bfd
[proxmox-backup.git] / www / NavigationTree.js
1 Ext.define('pbs-datastore-list', {
2 extend: 'Ext.data.Model',
3 fields: ['name', 'comment'],
4 proxy: {
5 type: 'proxmox',
6 url: "/api2/json/admin/datastore",
7 },
8 idProperty: 'store',
9 });
10
11 Ext.define('PBS.store.NavigationStore', {
12 extend: 'Ext.data.TreeStore',
13
14 storeId: 'NavigationStore',
15
16 root: {
17 expanded: true,
18 children: [
19 {
20 text: gettext('Dashboard'),
21 iconCls: 'fa fa-tachometer',
22 path: 'pbsDashboard',
23 leaf: true,
24 },
25 {
26 text: gettext('Configuration'),
27 iconCls: 'fa fa-gears',
28 path: 'pbsSystemConfiguration',
29 expanded: true,
30 children: [
31 {
32 text: gettext('User Management'),
33 iconCls: 'fa fa-user',
34 path: 'pbsUserView',
35 leaf: true,
36 },
37 {
38 text: gettext('Permissions'),
39 iconCls: 'fa fa-unlock',
40 path: 'pbsACLView',
41 leaf: true,
42 },
43 {
44 text: gettext('Remotes'),
45 iconCls: 'fa fa-server',
46 path: 'pbsRemoteView',
47 leaf: true,
48 },
49 {
50 text: gettext('Subscription'),
51 iconCls: 'fa fa-support',
52 path: 'pbsSubscription',
53 leaf: true,
54 },
55 ],
56 },
57 {
58 text: gettext('Administration'),
59 iconCls: 'fa fa-wrench',
60 path: 'pbsServerAdministration',
61 expanded: true,
62 leaf: false,
63 children: [
64 {
65 text: gettext('Disks'),
66 iconCls: 'fa fa-hdd-o',
67 path: 'pmxDiskList',
68 leaf: false,
69 children: [
70 {
71 text: Proxmox.Utils.directoryText,
72 iconCls: 'fa fa-folder',
73 path: 'pbsDirectoryList',
74 leaf: true,
75 },
76 {
77 text: "ZFS",
78 iconCls: 'fa fa-th-large',
79 path: 'pbsZFSList',
80 leaf: true,
81 },
82 ],
83 },
84 ],
85 },
86 {
87 text: gettext('Datastore'),
88 iconCls: 'fa fa-archive',
89 id: 'datastores',
90 expanded: true,
91 expandable: false,
92 leaf: false,
93 children: [
94 {
95 text: gettext('Add Datastore'),
96 iconCls: 'fa fa-plus-circle',
97 leaf: true,
98 id: 'addbutton',
99 },
100 ],
101 },
102 ],
103 },
104 });
105
106 Ext.define('PBS.view.main.NavigationTree', {
107 extend: 'Ext.list.Tree',
108 xtype: 'navigationtree',
109
110 controller: {
111 xclass: 'Ext.app.ViewController',
112
113 init: function(view) {
114 view.rstore = Ext.create('Proxmox.data.UpdateStore', {
115 autoStart: true,
116 interval: 15 * 1000,
117 storeId: 'pbs-datastore-list',
118 storeid: 'pbs-datastore-list',
119 model: 'pbs-datastore-list',
120 });
121
122 view.rstore.on('load', this.onLoad, this);
123 view.on('destroy', view.rstore.stopUpdate);
124 },
125
126 onLoad: function(store, records, success) {
127 if (!success) return;
128 var view = this.getView();
129
130 let root = view.getStore().getRoot();
131
132 records.sort((a, b) => a.id.localeCompare(b.id));
133
134 var list = root.findChild('id', 'datastores', false);
135 var length = records.length;
136 var lookup_hash = {};
137 let j = 0;
138 for (let i = 0; i < length; i++) {
139 let name = records[i].id;
140 lookup_hash[name] = true;
141
142 while (name.localeCompare(list.getChildAt(j).data.text) > 0 &&
143 (j + 1) < list.childNodes.length) {
144 j++;
145 }
146
147 if (list.getChildAt(j).data.text.localeCompare(name) !== 0) {
148 list.insertChild(j, {
149 text: name,
150 path: `DataStore-${name}`,
151 iconCls: 'fa fa-database',
152 leaf: true,
153 });
154 }
155 }
156
157 var erase_list = [];
158 list.eachChild(function(node) {
159 let name = node.data.text;
160 if (!lookup_hash[name] && node.data.id !== 'addbutton') {
161 erase_list.push(node);
162 }
163 });
164
165 Ext.Array.forEach(erase_list, function(node) { list.removeChild(node, true); });
166
167 if (view.pathToSelect !== undefined) {
168 let path = view.pathToSelect;
169 delete view.pathToSelect;
170 view.select(path, true);
171 }
172 },
173 },
174
175 listeners: {
176 itemclick: function(tl, info) {
177 if (info.node.data.id === 'datastores') {
178 return false;
179 }
180 if (info.node.data.id === 'addbutton') {
181 let me = this;
182 Ext.create('PBS.DataStoreEdit', {
183 listeners: {
184 destroy: function() {
185 me.rstore.reload();
186 },
187 },
188 }).show();
189 return false;
190 }
191 return true;
192 },
193 },
194
195 select: function(path, silent) {
196 var me = this;
197 if (me.rstore.isLoaded()) {
198 if (silent) {
199 me.suspendEvents(false);
200 }
201 var item = me.getStore().findRecord('path', path, 0, false, true, true);
202 me.setSelection(item);
203 if (silent) {
204 me.resumeEvents(true);
205 }
206 } else {
207 me.pathToSelect = path;
208 }
209 },
210
211 animation: false,
212 expanderOnly: true,
213 expanderFirst: false,
214 store: 'NavigationStore',
215 ui: 'nav',
216 });