]>
Commit | Line | Data |
---|---|---|
2f8915cf DM |
1 | Ext.define('PVE.dc.StorageView', { |
2 | extend: 'Ext.grid.GridPanel', | |
3 | ||
4 | alias: ['widget.pveStorageView'], | |
5 | ||
ba93a9c6 DC |
6 | onlineHelp: 'chapter_storage', |
7 | ||
c4bb9405 DC |
8 | stateful: true, |
9 | stateId: 'grid-dc-storage', | |
10 | ||
f28ec3e4 TL |
11 | createStorageEditWindow: function(type, sid) { |
12 | var schema = PVE.Utils.storageSchema[type]; | |
13 | if (!schema || !schema.ipanel) { | |
14 | throw "no editor registered for storage type: " + type; | |
15 | } | |
16 | ||
17 | Ext.create('PVE.storage.BaseEdit', { | |
18 | paneltype: 'PVE.storage.' + schema.ipanel, | |
19 | type: type, | |
20 | storageId: sid, | |
06c8315d | 21 | canDoBackups: schema.backups, |
f28ec3e4 TL |
22 | autoShow: true, |
23 | listeners: { | |
f6710aac TL |
24 | destroy: this.reloadStore, |
25 | }, | |
f28ec3e4 TL |
26 | }); |
27 | }, | |
28 | ||
8058410f | 29 | initComponent: function() { |
2f8915cf DM |
30 | var me = this; |
31 | ||
32 | var store = new Ext.data.Store({ | |
33 | model: 'pve-storage', | |
34 | proxy: { | |
56a353b9 | 35 | type: 'proxmox', |
f6710aac | 36 | url: "/api2/json/storage", |
2f8915cf | 37 | }, |
a9f71282 DC |
38 | sorters: { |
39 | property: 'storage', | |
f6710aac TL |
40 | order: 'DESC', |
41 | }, | |
2f8915cf DM |
42 | }); |
43 | ||
44 | var reload = function() { | |
45 | store.load(); | |
46 | }; | |
47 | ||
48 | var sm = Ext.create('Ext.selection.RowModel', {}); | |
49 | ||
50 | var run_editor = function() { | |
51 | var rec = sm.getSelection()[0]; | |
52 | if (!rec) { | |
53 | return; | |
54 | } | |
f28ec3e4 TL |
55 | var type = rec.data.type, |
56 | sid = rec.data.storage; | |
57 | ||
f28ec3e4 | 58 | me.createStorageEditWindow(type, sid); |
2f8915cf | 59 | }; |
a9f71282 | 60 | |
5720fafa | 61 | var edit_btn = new Proxmox.button.Button({ |
2f8915cf DM |
62 | text: gettext('Edit'), |
63 | disabled: true, | |
64 | selModel: sm, | |
f6710aac | 65 | handler: run_editor, |
2f8915cf DM |
66 | }); |
67 | ||
3b1ca3ff | 68 | var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', { |
2f8915cf | 69 | selModel: sm, |
3b1ca3ff | 70 | baseurl: '/storage/', |
f6710aac | 71 | callback: reload, |
2f8915cf DM |
72 | }); |
73 | ||
f28ec3e4 TL |
74 | // else we cannot dynamically generate the add menu handlers |
75 | var addHandleGenerator = function(type) { | |
76 | return function() { me.createStorageEditWindow(type); }; | |
77 | }; | |
78 | var addMenuItems = [], type; | |
f28ec3e4 TL |
79 | for (type in PVE.Utils.storageSchema) { |
80 | var storage = PVE.Utils.storageSchema[type]; | |
81 | if (storage.hideAdd) { | |
82 | continue; | |
83 | } | |
84 | addMenuItems.push({ | |
8058410f | 85 | text: PVE.Utils.format_storage_type(type), |
f28ec3e4 | 86 | iconCls: 'fa fa-fw fa-' + storage.faIcon, |
f6710aac | 87 | handler: addHandleGenerator(type), |
f28ec3e4 TL |
88 | }); |
89 | } | |
90 | ||
2f8915cf DM |
91 | Ext.apply(me, { |
92 | store: store, | |
f28ec3e4 | 93 | reloadStore: reload, |
2f8915cf | 94 | selModel: sm, |
2f8915cf | 95 | viewConfig: { |
f6710aac | 96 | trackOver: false, |
2f8915cf | 97 | }, |
a9f71282 | 98 | tbar: [ |
2f8915cf DM |
99 | { |
100 | text: gettext('Add'), | |
101 | menu: new Ext.menu.Menu({ | |
f6710aac TL |
102 | items: addMenuItems, |
103 | }), | |
2f8915cf DM |
104 | }, |
105 | remove_btn, | |
f6710aac | 106 | edit_btn, |
2f8915cf DM |
107 | ], |
108 | columns: [ | |
109 | { | |
110 | header: 'ID', | |
99acd7d9 | 111 | flex: 2, |
2f8915cf | 112 | sortable: true, |
f6710aac | 113 | dataIndex: 'storage', |
2f8915cf DM |
114 | }, |
115 | { | |
116 | header: gettext('Type'), | |
99acd7d9 | 117 | flex: 1, |
2f8915cf DM |
118 | sortable: true, |
119 | dataIndex: 'type', | |
f6710aac | 120 | renderer: PVE.Utils.format_storage_type, |
2f8915cf DM |
121 | }, |
122 | { | |
123 | header: gettext('Content'), | |
99acd7d9 | 124 | flex: 3, |
2f8915cf DM |
125 | sortable: true, |
126 | dataIndex: 'content', | |
f6710aac | 127 | renderer: PVE.Utils.format_content_types, |
2f8915cf DM |
128 | }, |
129 | { | |
130 | header: gettext('Path') + '/' + gettext('Target'), | |
99acd7d9 | 131 | flex: 2, |
2f8915cf DM |
132 | sortable: true, |
133 | dataIndex: 'path', | |
134 | renderer: function(value, metaData, record) { | |
135 | if (record.data.target) { | |
136 | return record.data.target; | |
137 | } | |
138 | return value; | |
f6710aac | 139 | }, |
2f8915cf DM |
140 | }, |
141 | { | |
142 | header: gettext('Shared'), | |
99acd7d9 | 143 | flex: 1, |
2f8915cf DM |
144 | sortable: true, |
145 | dataIndex: 'shared', | |
f6710aac | 146 | renderer: Proxmox.Utils.format_boolean, |
2f8915cf DM |
147 | }, |
148 | { | |
185a77e5 | 149 | header: gettext('Enabled'), |
99acd7d9 | 150 | flex: 1, |
2f8915cf DM |
151 | sortable: true, |
152 | dataIndex: 'disable', | |
f6710aac | 153 | renderer: Proxmox.Utils.format_neg_boolean, |
a8abd7a1 TL |
154 | }, |
155 | { | |
156 | header: gettext('Bandwidth Limit'), | |
157 | flex: 2, | |
158 | sortable: true, | |
f6710aac TL |
159 | dataIndex: 'bwlimit', |
160 | }, | |
2f8915cf DM |
161 | ], |
162 | listeners: { | |
c0b3df6e | 163 | activate: reload, |
f6710aac TL |
164 | itemdblclick: run_editor, |
165 | }, | |
2f8915cf DM |
166 | }); |
167 | ||
168 | me.callParent(); | |
f6710aac | 169 | }, |
2f8915cf | 170 | }, function() { |
2f8915cf DM |
171 | Ext.define('pve-storage', { |
172 | extend: 'Ext.data.Model', | |
a9f71282 | 173 | fields: [ |
2f8915cf | 174 | 'path', 'type', 'content', 'server', 'portal', 'target', 'export', 'storage', |
8058410f TL |
175 | { name: 'shared', type: 'boolean' }, |
176 | { name: 'disable', type: 'boolean' }, | |
2f8915cf | 177 | ], |
f6710aac | 178 | idProperty: 'storage', |
2f8915cf | 179 | }); |
2f8915cf | 180 | }); |