]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/dc/StorageView.js
SafeDestroy: remove viewModel - it not flexible enough
[pve-manager.git] / www / manager6 / dc / StorageView.js
CommitLineData
2f8915cf
DM
1
2Ext.define('PVE.dc.StorageView', {
3 extend: 'Ext.grid.GridPanel',
4
5 alias: ['widget.pveStorageView'],
6
7 initComponent : function() {
8 var me = this;
9
10 var store = new Ext.data.Store({
11 model: 'pve-storage',
12 proxy: {
13 type: 'pve',
14 url: "/api2/json/storage"
15 },
a9f71282
DC
16 sorters: {
17 property: 'storage',
18 order: 'DESC'
2f8915cf
DM
19 }
20 });
21
22 var reload = function() {
23 store.load();
24 };
25
26 var sm = Ext.create('Ext.selection.RowModel', {});
27
28 var run_editor = function() {
29 var rec = sm.getSelection()[0];
30 if (!rec) {
31 return;
32 }
33 var type = rec.data.type;
a9f71282 34
2f8915cf
DM
35 var editor;
36 if (type === 'dir') {
37 editor = 'PVE.storage.DirEdit';
38 } else if (type === 'nfs') {
39 editor = 'PVE.storage.NFSEdit';
40 } else if (type === 'glusterfs') {
41 editor = 'PVE.storage.GlusterFsEdit';
42 } else if (type === 'lvm') {
43 editor = 'PVE.storage.LVMEdit';
c3378f7b
DC
44 } else if (type === 'lvmthin') {
45 editor = 'PVE.storage.LvmThinEdit';
2f8915cf
DM
46 } else if (type === 'iscsi') {
47 editor = 'PVE.storage.IScsiEdit';
48 } else if (type === 'rbd') {
49 editor = 'PVE.storage.RBDEdit';
50 } else if (type === 'sheepdog') {
51 editor = 'PVE.storage.SheepdogEdit';
52 } else if (type === 'zfs') {
53 editor = 'PVE.storage.ZFSEdit';
54 } else if (type === 'zfspool') {
55 editor = 'PVE.storage.ZFSPoolEdit';
56 } else {
57 return;
58 }
59 var win = Ext.create(editor, {
60 storageId: rec.data.storage
61 });
62
63 win.show();
64 win.on('destroy', reload);
65 };
a9f71282 66
2f8915cf
DM
67 var edit_btn = new PVE.button.Button({
68 text: gettext('Edit'),
69 disabled: true,
70 selModel: sm,
71 handler: run_editor
72 });
73
74 var remove_btn = new PVE.button.Button({
75 text: gettext('Remove'),
76 disabled: true,
77 selModel: sm,
78 confirmMsg: function (rec) {
79 return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
80 "'" + rec.data.storage + "'");
81 },
82 handler: function(btn, event, rec) {
83 PVE.Utils.API2Request({
84 url: '/storage/' + rec.data.storage,
85 method: 'DELETE',
86 waitMsgTarget: me,
87 callback: function() {
88 reload();
89 },
90 failure: function (response, opts) {
91 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
92 }
93 });
94 }
95 });
96
97 Ext.apply(me, {
98 store: store,
99 selModel: sm,
100 stateful: false,
101 viewConfig: {
102 trackOver: false
103 },
a9f71282 104 tbar: [
2f8915cf
DM
105 {
106 text: gettext('Add'),
107 menu: new Ext.menu.Menu({
108 items: [
109 {
110 text: PVE.Utils.format_storage_type('dir'),
111 iconCls: 'pve-itype-icon-itype',
112 handler: function() {
113 var win = Ext.create('PVE.storage.DirEdit', {});
114 win.on('destroy', reload);
115 win.show();
116 }
117
118 },
119 {
120 text: PVE.Utils.format_storage_type('lvm'),
121 iconCls: 'pve-itype-icon-storage',
122 handler: function() {
123 var win = Ext.create('PVE.storage.LVMEdit', {});
124 win.on('destroy', reload);
125 win.show();
126 }
127 },
c3378f7b
DC
128 {
129 text: PVE.Utils.format_storage_type('lvmthin'),
130 iconCls: 'pve-itype-icon-storage',
131 handler: function() {
132 var win = Ext.create('PVE.storage.LvmThinEdit', {});
133 win.on('destroy', reload);
134 win.show();
135 }
136 },
2f8915cf
DM
137 {
138 text: PVE.Utils.format_storage_type('nfs'),
139 iconCls: 'pve-itype-icon-network-server',
140 handler: function() {
141 var win = Ext.create('PVE.storage.NFSEdit', {});
142 win.on('destroy', reload);
143 win.show();
144 }
145 },
146 {
147 text: PVE.Utils.format_storage_type('iscsi'),
148 iconCls: 'pve-itype-icon-network-server',
149 handler: function() {
150 var win = Ext.create('PVE.storage.IScsiEdit', {});
151 win.on('destroy', reload);
152 win.show();
153 }
154 },
155 {
156 text: PVE.Utils.format_storage_type('glusterfs'),
157 iconCls: 'pve-itype-icon-network-server',
158 handler: function() {
159 var win = Ext.create('PVE.storage.GlusterFsEdit', {});
160 win.on('destroy', reload);
161 win.show();
162 }
163 },
164 {
165 text: PVE.Utils.format_storage_type('rbd'),
166 iconCls: 'pve-itype-icon-network-server',
167 handler: function() {
168 var win = Ext.create('PVE.storage.RBDEdit', {});
169 win.on('destroy', reload);
170 win.show();
171 }
172 },
173 {
174 text: PVE.Utils.format_storage_type('zfs'),
175 iconCls: 'pve-itype-icon-network-server',
176 handler: function() {
177 var win = Ext.create('PVE.storage.ZFSEdit', {});
178 win.on('destroy', reload);
179 win.show();
180 }
181 },
182 {
183 text: PVE.Utils.format_storage_type('zfspool'),
184 iconCls: 'pve-itype-icon-storage',
185 handler: function() {
186 var win = Ext.create('PVE.storage.ZFSPoolEdit', {});
187 win.on('destroy', reload);
188 win.show();
189 }
190 },
191
192/* the following type are conidered unstable
193 * so we do not enable that on the GUI for now
194 {
195 text: PVE.Utils.format_storage_type('sheepdog'),
196 iconCls: 'pve-itype-icon-network-server',
197 handler: function() {
198 var win = Ext.create('PVE.storage.SheepdogEdit', {});
199 win.on('destroy', reload);
200 win.show();
201 }
202 }
203*/
204 ]
205 })
206 },
207 remove_btn,
208 edit_btn
209 ],
210 columns: [
211 {
212 header: 'ID',
213 width: 100,
214 sortable: true,
215 dataIndex: 'storage'
216 },
217 {
218 header: gettext('Type'),
219 width: 60,
220 sortable: true,
221 dataIndex: 'type',
222 renderer: PVE.Utils.format_storage_type
223 },
224 {
225 header: gettext('Content'),
226 width: 150,
227 sortable: true,
228 dataIndex: 'content',
229 renderer: PVE.Utils.format_content_types
230 },
231 {
232 header: gettext('Path') + '/' + gettext('Target'),
233 flex: 1,
234 sortable: true,
235 dataIndex: 'path',
236 renderer: function(value, metaData, record) {
237 if (record.data.target) {
238 return record.data.target;
239 }
240 return value;
241 }
242 },
243 {
244 header: gettext('Shared'),
245 width: 80,
246 sortable: true,
247 dataIndex: 'shared',
248 renderer: PVE.Utils.format_boolean
249 },
250 {
251 header: gettext('Enable'),
252 width: 80,
253 sortable: true,
254 dataIndex: 'disable',
255 renderer: PVE.Utils.format_neg_boolean
256 }
257 ],
258 listeners: {
c0b3df6e 259 activate: reload,
2f8915cf
DM
260 itemdblclick: run_editor
261 }
262 });
263
264 me.callParent();
265 }
266}, function() {
267
268 Ext.define('pve-storage', {
269 extend: 'Ext.data.Model',
a9f71282 270 fields: [
2f8915cf
DM
271 'path', 'type', 'content', 'server', 'portal', 'target', 'export', 'storage',
272 { name: 'shared', type: 'boolean'},
a9f71282 273 { name: 'disable', type: 'boolean'}
2f8915cf
DM
274 ],
275 idProperty: 'storage'
276 });
277
278});