2021-04-21 23:53:36 +02:00
Ext . define ( 'PVE.sdn.DnsView' , {
extend : 'Ext.grid.GridPanel' ,
alias : [ 'widget.pveSDNDnsView' ] ,
stateful : true ,
stateId : 'grid-sdn-dns' ,
createSDNEditWindow : function ( type , sid ) {
let schema = PVE . Utils . sdndnsSchema [ type ] ;
if ( ! schema || ! schema . ipanel ) {
throw "no editor registered for dns type: " + type ;
}
Ext . create ( 'PVE.sdn.dns.BaseEdit' , {
paneltype : 'PVE.sdn.dns.' + schema . ipanel ,
type : type ,
dns : sid ,
autoShow : true ,
listeners : {
2021-04-26 15:44:57 +02:00
destroy : this . reloadStore ,
} ,
2021-04-21 23:53:36 +02:00
} ) ;
} ,
2021-04-26 15:44:57 +02:00
initComponent : function ( ) {
2021-04-21 23:53:36 +02:00
let me = this ;
let store = new Ext . data . Store ( {
model : 'pve-sdn-dns' ,
proxy : {
type : 'proxmox' ,
2021-04-26 15:44:57 +02:00
url : "/api2/json/cluster/sdn/dns" ,
2021-04-21 23:53:36 +02:00
} ,
sorters : {
property : 'dns' ,
2021-12-07 14:08:44 +01:00
direction : 'ASC' ,
2021-04-21 23:53:36 +02:00
} ,
} ) ;
let sm = Ext . create ( 'Ext.selection.RowModel' , { } ) ;
let run _editor = function ( ) {
let rec = sm . getSelection ( ) [ 0 ] ;
if ( ! rec ) {
return ;
}
let type = rec . data . type ,
dns = rec . data . dns ;
me . createSDNEditWindow ( type , dns ) ;
} ;
let edit _btn = new Proxmox . button . Button ( {
text : gettext ( 'Edit' ) ,
disabled : true ,
selModel : sm ,
2021-04-26 15:44:57 +02:00
handler : run _editor ,
2021-04-21 23:53:36 +02:00
} ) ;
let remove _btn = Ext . create ( 'Proxmox.button.StdRemoveButton' , {
selModel : sm ,
baseurl : '/cluster/sdn/dns/' ,
2021-04-26 19:48:02 +02:00
callback : ( ) => store . load ( ) ,
2021-04-21 23:53:36 +02:00
} ) ;
// else we cannot dynamically generate the add menu handlers
let addHandleGenerator = function ( type ) {
return function ( ) { me . createSDNEditWindow ( type ) ; } ;
} ;
2021-04-26 19:48:02 +02:00
let addMenuItems = [ ] ;
for ( const [ type , dns ] of Object . entries ( PVE . Utils . sdndnsSchema ) ) {
2021-04-21 23:53:36 +02:00
if ( dns . hideAdd ) {
continue ;
}
addMenuItems . push ( {
2021-04-26 15:44:57 +02:00
text : PVE . Utils . format _sdndns _type ( type ) ,
2021-04-21 23:53:36 +02:00
iconCls : 'fa fa-fw fa-' + dns . faIcon ,
2021-04-26 15:44:57 +02:00
handler : addHandleGenerator ( type ) ,
2021-04-21 23:53:36 +02:00
} ) ;
}
Ext . apply ( me , {
store : store ,
2021-04-26 19:48:02 +02:00
reloadStore : ( ) => store . load ( ) ,
2021-04-21 23:53:36 +02:00
selModel : sm ,
viewConfig : {
2021-04-26 15:44:57 +02:00
trackOver : false ,
2021-04-21 23:53:36 +02:00
} ,
tbar : [
{
text : gettext ( 'Add' ) ,
menu : new Ext . menu . Menu ( {
2021-04-26 15:44:57 +02:00
items : addMenuItems ,
} ) ,
2021-04-21 23:53:36 +02:00
} ,
remove _btn ,
edit _btn ,
] ,
columns : [
{
header : 'ID' ,
flex : 2 ,
2021-04-26 15:44:57 +02:00
dataIndex : 'dns' ,
2021-04-21 23:53:36 +02:00
} ,
{
header : gettext ( 'Type' ) ,
flex : 1 ,
dataIndex : 'type' ,
2021-04-26 15:44:57 +02:00
renderer : PVE . Utils . format _sdndns _type ,
2021-04-21 23:53:36 +02:00
} ,
{
header : 'url' ,
flex : 1 ,
dataIndex : 'url' ,
} ,
] ,
listeners : {
2021-04-26 19:48:02 +02:00
activate : ( ) => store . load ( ) ,
2021-04-26 15:44:57 +02:00
itemdblclick : run _editor ,
} ,
2021-04-21 23:53:36 +02:00
} ) ;
store . load ( ) ;
me . callParent ( ) ;
2021-04-26 15:44:57 +02:00
} ,
2021-04-21 23:53:36 +02:00
} ) ;