2020-04-09 16:10:45 +02:00
Ext . define ( 'PVE.panel.AuthBase' , {
extend : 'Proxmox.panel.InputPanel' ,
xtype : 'pveAuthBasePanel' ,
type : '' ,
onGetValues : function ( values ) {
let me = this ;
if ( ! values . port ) {
if ( ! me . isCreate ) {
Proxmox . Utils . assemble _field _data ( values , { 'delete' : 'port' } ) ;
}
delete values . port ;
}
if ( me . isCreate ) {
2020-04-26 13:26:50 +02:00
values . type = me . type ;
2020-04-09 16:10:45 +02:00
}
return values ;
} ,
initComponent : function ( ) {
let me = this ;
2021-07-01 14:25:01 +02:00
let options = PVE . Utils . authSchema [ me . type ] ;
2020-04-09 16:10:45 +02:00
if ( ! me . column1 ) { me . column1 = [ ] ; }
if ( ! me . column2 ) { me . column2 = [ ] ; }
if ( ! me . columnB ) { me . columnB = [ ] ; }
// first field is name
me . column1 . unshift ( {
xtype : me . isCreate ? 'textfield' : 'displayfield' ,
name : 'realm' ,
fieldLabel : gettext ( 'Realm' ) ,
value : me . realm ,
allowBlank : false ,
} ) ;
// last field is default'
me . column1 . push ( {
xtype : 'proxmoxcheckbox' ,
fieldLabel : gettext ( 'Default' ) ,
name : 'default' ,
uncheckedValue : 0 ,
} ) ;
2021-07-01 14:25:01 +02:00
if ( options . tfa ) {
// last field of column2is tfa
me . column2 . push ( {
xtype : 'pveTFASelector' ,
deleteEmpty : ! me . isCreate ,
} ) ;
}
2020-04-09 16:10:45 +02:00
me . columnB . push ( {
xtype : 'textfield' ,
name : 'comment' ,
fieldLabel : gettext ( 'Comment' ) ,
} ) ;
me . callParent ( ) ;
} ,
} ) ;
Ext . define ( 'PVE.dc.AuthEditBase' , {
extend : 'Proxmox.window.Edit' ,
2020-05-06 20:35:41 +02:00
onlineHelp : 'pveum_authentication_realms' ,
2020-04-09 16:10:45 +02:00
isAdd : true ,
fieldDefaults : {
labelWidth : 120 ,
} ,
initComponent : function ( ) {
var me = this ;
me . isCreate = ! me . realm ;
if ( me . isCreate ) {
me . url = '/api2/extjs/access/domains' ;
me . method = 'POST' ;
} else {
me . url = '/api2/extjs/access/domains/' + me . realm ;
me . method = 'PUT' ;
}
let authConfig = PVE . Utils . authSchema [ me . authType ] ;
if ( ! authConfig ) {
throw 'unknown auth type' ;
} else if ( ! authConfig . add && me . isCreate ) {
throw 'trying to add non addable realm' ;
}
me . subject = authConfig . name ;
2020-04-09 16:10:48 +02:00
let items ;
let bodyPadding ;
if ( authConfig . syncipanel ) {
bodyPadding = 0 ;
items = {
xtype : 'tabpanel' ,
region : 'center' ,
layout : 'fit' ,
bodyPadding : 10 ,
items : [
{
title : gettext ( 'General' ) ,
realm : me . realm ,
xtype : authConfig . ipanel ,
isCreate : me . isCreate ,
type : me . authType ,
} ,
{
title : gettext ( 'Sync Options' ) ,
realm : me . realm ,
xtype : authConfig . syncipanel ,
isCreate : me . isCreate ,
type : me . authType ,
} ,
] ,
} ;
} else {
items = [ {
2020-04-09 16:10:45 +02:00
realm : me . realm ,
xtype : authConfig . ipanel ,
isCreate : me . isCreate ,
type : me . authType ,
2020-04-09 16:10:48 +02:00
} ] ;
}
Ext . apply ( me , {
items ,
bodyPadding ,
2020-04-09 16:10:45 +02:00
} ) ;
me . callParent ( ) ;
if ( ! me . isCreate ) {
me . load ( {
2020-04-26 13:26:26 +02:00
success : function ( response , options ) {
var data = response . result . data || { } ;
// just to be sure (should not happen)
if ( data . type !== me . authType ) {
me . close ( ) ;
throw "got wrong auth type" ;
}
me . setValues ( data ) ;
} ,
2020-04-09 16:10:45 +02:00
} ) ;
}
} ,
} ) ;