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