2015-06-16 17:42:36 +02:00
Ext . define ( 'PVE.dc.StorageView' , {
extend : 'Ext.grid.GridPanel' ,
alias : [ 'widget.pveStorageView' ] ,
initComponent : function ( ) {
var me = this ;
var store = new Ext . data . Store ( {
model : 'pve-storage' ,
proxy : {
type : 'pve' ,
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 ;
}
var type = rec . data . type ;
2016-03-08 11:03:57 +01:00
2015-06-16 17:42:36 +02:00
var editor ;
if ( type === 'dir' ) {
editor = 'PVE.storage.DirEdit' ;
} else if ( type === 'nfs' ) {
editor = 'PVE.storage.NFSEdit' ;
} else if ( type === 'glusterfs' ) {
editor = 'PVE.storage.GlusterFsEdit' ;
} else if ( type === 'lvm' ) {
editor = 'PVE.storage.LVMEdit' ;
2016-03-08 11:03:56 +01:00
} else if ( type === 'lvmthin' ) {
editor = 'PVE.storage.LvmThinEdit' ;
2015-06-16 17:42:36 +02:00
} else if ( type === 'iscsi' ) {
editor = 'PVE.storage.IScsiEdit' ;
} else if ( type === 'rbd' ) {
editor = 'PVE.storage.RBDEdit' ;
} else if ( type === 'sheepdog' ) {
editor = 'PVE.storage.SheepdogEdit' ;
} else if ( type === 'zfs' ) {
editor = 'PVE.storage.ZFSEdit' ;
} else if ( type === 'zfspool' ) {
editor = 'PVE.storage.ZFSPoolEdit' ;
} else {
return ;
}
var win = Ext . create ( editor , {
storageId : rec . data . storage
} ) ;
win . show ( ) ;
win . on ( 'destroy' , reload ) ;
} ;
2016-03-08 11:03:57 +01:00
2015-06-16 17:42:36 +02:00
var edit _btn = new PVE . button . Button ( {
text : gettext ( 'Edit' ) ,
disabled : true ,
selModel : sm ,
handler : run _editor
} ) ;
var remove _btn = new PVE . button . Button ( {
text : gettext ( 'Remove' ) ,
disabled : true ,
selModel : sm ,
confirmMsg : function ( rec ) {
return Ext . String . format ( gettext ( 'Are you sure you want to remove entry {0}' ) ,
"'" + rec . data . storage + "'" ) ;
} ,
handler : function ( btn , event , rec ) {
PVE . Utils . API2Request ( {
url : '/storage/' + rec . data . storage ,
method : 'DELETE' ,
waitMsgTarget : me ,
callback : function ( ) {
reload ( ) ;
} ,
failure : function ( response , opts ) {
Ext . Msg . alert ( gettext ( 'Error' ) , response . htmlStatus ) ;
}
} ) ;
}
} ) ;
Ext . apply ( me , {
store : store ,
selModel : sm ,
stateful : false ,
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 ( {
items : [
{
text : PVE . Utils . format _storage _type ( 'dir' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-folder' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.DirEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
{
text : PVE . Utils . format _storage _type ( 'lvm' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-folder' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.LVMEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
2016-03-08 11:03:56 +01:00
{
text : PVE . Utils . format _storage _type ( 'lvmthin' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-folder' ,
2016-03-08 11:03:56 +01:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.LvmThinEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
2015-06-16 17:42:36 +02:00
{
text : PVE . Utils . format _storage _type ( 'nfs' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-building' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.NFSEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
{
text : PVE . Utils . format _storage _type ( 'iscsi' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-building' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.IScsiEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
{
text : PVE . Utils . format _storage _type ( 'glusterfs' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-building' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.GlusterFsEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
{
text : PVE . Utils . format _storage _type ( 'rbd' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-building' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.RBDEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
{
text : PVE . Utils . format _storage _type ( 'zfs' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-building' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.ZFSEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
} ,
{
text : PVE . Utils . format _storage _type ( 'zfspool' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-folder' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.ZFSPoolEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
2016-04-29 12:06:28 +02:00
}
2015-06-16 17:42:36 +02:00
/ * t h e f o l l o w i n g t y p e a r e c o n i d e r e d u n s t a b l e
* so we do not enable that on the GUI for now
{
text : PVE . Utils . format _storage _type ( 'sheepdog' ) ,
2016-04-11 10:19:05 +02:00
iconCls : 'fa fa-fw fa-building' ,
2015-06-16 17:42:36 +02:00
handler : function ( ) {
var win = Ext . create ( 'PVE.storage.SheepdogEdit' , { } ) ;
win . on ( 'destroy' , reload ) ;
win . show ( ) ;
}
}
* /
]
} )
} ,
remove _btn ,
edit _btn
] ,
columns : [
{
header : 'ID' ,
width : 100 ,
sortable : true ,
dataIndex : 'storage'
} ,
{
header : gettext ( 'Type' ) ,
width : 60 ,
sortable : true ,
dataIndex : 'type' ,
renderer : PVE . Utils . format _storage _type
} ,
{
header : gettext ( 'Content' ) ,
width : 150 ,
sortable : true ,
dataIndex : 'content' ,
renderer : PVE . Utils . format _content _types
} ,
{
header : gettext ( 'Path' ) + '/' + gettext ( 'Target' ) ,
flex : 1 ,
sortable : true ,
dataIndex : 'path' ,
renderer : function ( value , metaData , record ) {
if ( record . data . target ) {
return record . data . target ;
}
return value ;
}
} ,
{
header : gettext ( 'Shared' ) ,
width : 80 ,
sortable : true ,
dataIndex : 'shared' ,
renderer : PVE . Utils . format _boolean
} ,
{
2016-04-05 11:10:52 +02:00
header : gettext ( 'Enabled' ) ,
2015-06-16 17:42:36 +02:00
width : 80 ,
sortable : true ,
dataIndex : 'disable' ,
renderer : PVE . Utils . format _neg _boolean
}
] ,
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'
} ) ;
} ) ;