]> git.proxmox.com Git - proxmox-backup.git/blob - www/NavigationTree.js
ui: add crud for remotes
[proxmox-backup.git] / www / NavigationTree.js
1 Ext.define('PBS.store.NavigationStore', {
2 extend: 'Ext.data.TreeStore',
3
4 storeId: 'NavigationStore',
5
6 root: {
7 expanded: true,
8 children: [
9 {
10 text: gettext('Dashboard'),
11 iconCls: 'fa fa-tachometer',
12 path: 'pbsDashboard',
13 leaf: true
14 },
15 {
16 text: gettext('Configuration'),
17 iconCls: 'fa fa-gears',
18 path: 'pbsSystemConfiguration',
19 expanded: true,
20 children: [
21 {
22 text: gettext('User Management'),
23 iconCls: 'fa fa-user',
24 path: 'pbsUserView',
25 leaf: true
26 },
27 {
28 text: gettext('Permissions'),
29 iconCls: 'fa fa-unlock',
30 path: 'pbsACLView',
31 leaf: true
32 },
33 {
34 text: gettext('Remotes'),
35 iconCls: 'fa fa-server',
36 path: 'pbsRemoteView',
37 leaf: true,
38 },
39 {
40 text: gettext('Data Store'),
41 iconCls: 'fa fa-archive',
42 path: 'pbsDataStoreConfig',
43 leaf: true
44 },
45 {
46 text: gettext('Subscription'),
47 iconCls: 'fa fa-support',
48 path: 'pbsSubscription',
49 leaf: true
50 }
51 ]
52 },
53 {
54 text: gettext('Administration'),
55 iconCls: 'fa fa-wrench',
56 path: 'pbsServerAdministration',
57 leaf: true
58 }
59 ]
60 }
61 });
62
63 Ext.define('PBS.view.main.NavigationTree', {
64 extend: 'Ext.list.Tree',
65 xtype: 'navigationtree',
66
67 controller: {
68 xclass: 'Ext.app.ViewController',
69
70 init: function(view) {
71
72 view.rstore = Ext.create('Proxmox.data.UpdateStore', {
73 autoStart: true,
74 interval: 15 * 1000,
75 storeid: 'pbs-datastore-list',
76 model: 'pbs-datastore-list'
77 });
78
79 view.rstore.on('load', this.onLoad, this);
80 view.on('destroy', view.rstore.stopUpdate);
81 },
82
83 onLoad: function(store, records, success) {
84 var view = this.getView();
85
86 let root = view.getStore().getRoot();
87
88 if (!root.findChild('path', 'pbsDataStoreStatus', false)) {
89 root.appendChild({
90 text: gettext('Data Store'),
91 expanded: true,
92 iconCls: 'fa fa-archive',
93 path: 'pbsDataStoreStatus',
94 leaf: false
95 });
96 }
97
98 // FIXME: newly added always get appended to the end..
99 records.sort((a, b) => {
100 if (a.id > b.id) return 1;
101 if (a.id < b.id) return -1;
102 return 0;
103 });
104
105 var list = root.findChild('path', 'pbsDataStoreStatus', false);
106 var length = records.length;
107 var lookup_hash = {};
108 for (var i = 0; i < length; i++) {
109 var name = records[i].id;
110 lookup_hash[name] = true;
111 if (!list.findChild('text', name, false)) {
112 list.appendChild({
113 text: name,
114 path: `DataStore-${name}`,
115 iconCls: 'fa fa-database',
116 leaf: true
117 });
118 }
119 }
120
121 var erase_list = [];
122 list.eachChild(function(node) {
123 var name = node.data.text;
124 if (!lookup_hash[name]) {
125 erase_list.push(node);
126 }
127 });
128
129 Ext.Array.forEach(erase_list, function(node) { node.erase(); });
130
131 }
132 },
133
134 select: function(path) {
135 var me = this;
136 var item = me.getStore().findRecord('path', path, 0, false, true, true);
137 me.setSelection(item);
138 },
139
140 animation: false,
141 expanderOnly: true,
142 expanderFirst: false,
143 store: 'NavigationStore',
144 ui: 'nav'
145 });