2015-06-16 17:42:36 +02:00
Ext . define ( 'PVE.dc.StorageView' , {
extend : 'Ext.grid.GridPanel' ,
alias : [ 'widget.pveStorageView' ] ,
2016-11-02 16:57:10 +01:00
onlineHelp : 'chapter_storage' ,
2016-11-08 10:50:43 +01:00
stateful : true ,
stateId : 'grid-dc-storage' ,
2018-03-27 14:19:46 +02:00
createStorageEditWindow : function ( type , sid ) {
var schema = PVE . Utils . storageSchema [ type ] ;
if ( ! schema || ! schema . ipanel ) {
throw "no editor registered for storage type: " + type ;
}
Ext . create ( 'PVE.storage.BaseEdit' , {
paneltype : 'PVE.storage.' + schema . ipanel ,
type : type ,
storageId : sid ,
autoShow : true ,
listeners : {
destroy : this . reloadStore
}
} ) ;
} ,
2015-06-16 17:42:36 +02:00
initComponent : function ( ) {
var me = this ;
var store = new Ext . data . Store ( {
model : 'pve-storage' ,
proxy : {
2017-12-11 14:46:51 +01:00
type : 'proxmox' ,
2015-06-16 17:42:36 +02:00
url : "/api2/json/storage"
} ,
2016-03-08 11:03:57 +01:00
sorters : {
property : 'storage' ,
order : 'DESC'
2015-06-16 17:42:36 +02:00
}
} ) ;
var reload = function ( ) {
store . load ( ) ;
} ;
var sm = Ext . create ( 'Ext.selection.RowModel' , { } ) ;
var run _editor = function ( ) {
var rec = sm . getSelection ( ) [ 0 ] ;
if ( ! rec ) {
return ;
}
2018-03-27 14:19:46 +02:00
var type = rec . data . type ,
sid = rec . data . storage ;
me . createStorageEditWindow ( type , sid ) ;
2015-06-16 17:42:36 +02:00
} ;
2016-03-08 11:03:57 +01:00
2018-01-15 15:18:08 +01:00
var edit _btn = new Proxmox . button . Button ( {
2015-06-16 17:42:36 +02:00
text : gettext ( 'Edit' ) ,
disabled : true ,
selModel : sm ,
handler : run _editor
} ) ;
2018-01-15 15:18:07 +01:00
var remove _btn = Ext . create ( 'Proxmox.button.StdRemoveButton' , {
2015-06-16 17:42:36 +02:00
selModel : sm ,
2018-01-15 15:18:07 +01:00
baseurl : '/storage/' ,
2018-03-27 14:19:46 +02:00
callback : reload
2015-06-16 17:42:36 +02:00
} ) ;
2018-03-27 14:19:46 +02:00
// else we cannot dynamically generate the add menu handlers
var addHandleGenerator = function ( type ) {
return function ( ) { me . createStorageEditWindow ( type ) ; } ;
} ;
var addMenuItems = [ ] , type ;
/*jslint forin: true */
for ( type in PVE . Utils . storageSchema ) {
var storage = PVE . Utils . storageSchema [ type ] ;
if ( storage . hideAdd ) {
continue ;
}
addMenuItems . push ( {
text : PVE . Utils . format _storage _type ( type ) ,
iconCls : 'fa fa-fw fa-' + storage . faIcon ,
handler : addHandleGenerator ( type )
} ) ;
}
2015-06-16 17:42:36 +02:00
Ext . apply ( me , {
store : store ,
2018-03-27 14:19:46 +02:00
reloadStore : reload ,
2015-06-16 17:42:36 +02:00
selModel : sm ,
viewConfig : {
trackOver : false
} ,
2016-03-08 11:03:57 +01:00
tbar : [
2015-06-16 17:42:36 +02:00
{
text : gettext ( 'Add' ) ,
menu : new Ext . menu . Menu ( {
2018-03-27 14:19:46 +02:00
items : addMenuItems
2015-06-16 17:42:36 +02:00
} )
} ,
remove _btn ,
edit _btn
] ,
columns : [
{
header : 'ID' ,
2018-03-22 16:27:04 +01:00
flex : 2 ,
2015-06-16 17:42:36 +02:00
sortable : true ,
dataIndex : 'storage'
} ,
{
header : gettext ( 'Type' ) ,
2018-03-22 16:27:04 +01:00
flex : 1 ,
2015-06-16 17:42:36 +02:00
sortable : true ,
dataIndex : 'type' ,
renderer : PVE . Utils . format _storage _type
} ,
{
header : gettext ( 'Content' ) ,
2018-03-22 16:27:04 +01:00
flex : 3 ,
2015-06-16 17:42:36 +02:00
sortable : true ,
dataIndex : 'content' ,
renderer : PVE . Utils . format _content _types
} ,
{
header : gettext ( 'Path' ) + '/' + gettext ( 'Target' ) ,
2018-03-22 16:27:04 +01:00
flex : 2 ,
2015-06-16 17:42:36 +02:00
sortable : true ,
dataIndex : 'path' ,
renderer : function ( value , metaData , record ) {
if ( record . data . target ) {
return record . data . target ;
}
return value ;
}
} ,
{
header : gettext ( 'Shared' ) ,
2018-03-22 16:27:04 +01:00
flex : 1 ,
2015-06-16 17:42:36 +02:00
sortable : true ,
dataIndex : 'shared' ,
2018-01-15 15:18:09 +01:00
renderer : Proxmox . Utils . format _boolean
2015-06-16 17:42:36 +02:00
} ,
{
2016-04-05 11:10:52 +02:00
header : gettext ( 'Enabled' ) ,
2018-03-22 16:27:04 +01:00
flex : 1 ,
2015-06-16 17:42:36 +02:00
sortable : true ,
dataIndex : 'disable' ,
2018-01-15 15:18:09 +01:00
renderer : Proxmox . Utils . format _neg _boolean
2018-03-22 16:27:05 +01:00
} ,
{
header : gettext ( 'Bandwidth Limit' ) ,
flex : 2 ,
sortable : true ,
dataIndex : 'bwlimit'
2015-06-16 17:42:36 +02:00
}
] ,
listeners : {
2015-11-23 15:13:12 +01:00
activate : reload ,
2015-06-16 17:42:36 +02:00
itemdblclick : run _editor
}
} ) ;
me . callParent ( ) ;
}
} , function ( ) {
Ext . define ( 'pve-storage' , {
extend : 'Ext.data.Model' ,
2016-03-08 11:03:57 +01:00
fields : [
2015-06-16 17:42:36 +02:00
'path' , 'type' , 'content' , 'server' , 'portal' , 'target' , 'export' , 'storage' ,
{ name : 'shared' , type : 'boolean' } ,
2016-03-08 11:03:57 +01:00
{ name : 'disable' , type : 'boolean' }
2015-06-16 17:42:36 +02:00
] ,
idProperty : 'storage'
} ) ;
} ) ;