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