2023-02-09 14:31:14 +01:00
Ext . define ( 'PBS.window.UserEditViewModel' , {
extend : 'Ext.app.ViewModel' ,
alias : 'viewmodel.pbsUserEdit' ,
data : {
realm : 'pbs' ,
} ,
formulas : {
maySetPassword : function ( get ) {
2023-03-28 18:46:38 +02:00
let realm = get ( 'realm' ) ;
let view = this . getView ( ) ;
let realmStore = view . down ( 'pmxRealmComboBox' ) . getStore ( ) ;
if ( realmStore . isLoaded ( ) ) {
let rec = realmStore . findRecord ( 'realm' , realm , 0 , false , true , true ) ;
return Proxmox . Schema . authDomains [ rec . data . type ] ? . pwchange && view . isCreate ;
} else {
return view . isCreate ;
}
2023-02-09 14:31:14 +01:00
} ,
} ,
} ) ;
2020-05-18 14:18:38 +02:00
Ext . define ( 'PBS.window.UserEdit' , {
extend : 'Proxmox.window.Edit' ,
alias : 'widget.pbsUserEdit' ,
mixins : [ 'Proxmox.Mixin.CBind' ] ,
2020-09-21 13:25:48 +02:00
onlineHelp : 'user_mgmt' ,
2020-05-18 14:18:38 +02:00
userid : undefined ,
isAdd : true ,
subject : gettext ( 'User' ) ,
fieldDefaults : { labelWidth : 120 } ,
2023-02-09 14:31:14 +01:00
viewModel : {
type : 'pbsUserEdit' ,
} ,
2020-05-18 14:18:38 +02:00
cbindData : function ( initialConfig ) {
var me = this ;
var userid = initialConfig . userid ;
var baseurl = '/api2/extjs/access/users' ;
me . isCreate = ! userid ;
2021-01-19 14:33:23 +01:00
me . url = userid ? baseurl + '/' + encodeURIComponent ( userid ) : baseurl ;
2020-05-18 14:18:38 +02:00
me . method = userid ? 'PUT' : 'POST' ;
me . autoLoad = ! ! userid ;
return {
useridXType : userid ? 'displayfield' : 'textfield' ,
} ;
} ,
items : {
xtype : 'inputpanel' ,
column1 : [
{
xtype : 'pmxDisplayEditField' ,
name : 'userid' ,
fieldLabel : gettext ( 'User name' ) ,
renderer : Ext . htmlEncode ,
allowBlank : false ,
cbind : {
editable : '{isCreate}' ,
} ,
} ,
2023-02-09 14:31:14 +01:00
{
xtype : 'pmxRealmComboBox' ,
name : 'realm' ,
fieldLabel : gettext ( 'Realm' ) ,
allowBlank : false ,
matchFieldWidth : false ,
listConfig : { width : 300 } ,
2023-03-28 18:46:38 +02:00
bind : {
value : '{realm}' ,
} ,
2023-02-09 14:31:14 +01:00
cbind : {
hidden : '{!isCreate}' ,
disabled : '{!isCreate}' ,
} ,
submitValue : true ,
2023-03-28 18:21:02 +02:00
storeFilter : rec => rec . data ? . type !== 'pam' ,
2023-02-09 14:31:14 +01:00
} ,
2020-05-18 14:18:38 +02:00
{
xtype : 'textfield' ,
inputType : 'password' ,
fieldLabel : gettext ( 'Password' ) ,
2024-10-04 15:40:54 +02:00
minLength : 8 ,
2020-05-18 14:18:38 +02:00
allowBlank : false ,
name : 'password' ,
listeners : {
2023-02-09 14:31:14 +01:00
change : function ( field ) {
2020-05-18 14:18:38 +02:00
field . next ( ) . validate ( ) ;
2023-02-09 14:31:14 +01:00
} ,
blur : function ( field ) {
2020-05-18 14:18:38 +02:00
field . next ( ) . validate ( ) ;
2023-02-09 14:31:14 +01:00
} ,
2020-05-18 14:18:38 +02:00
} ,
2023-02-09 14:31:14 +01:00
bind : {
disabled : '{!maySetPassword}' ,
hidden : '{!maySetPassword}' ,
2020-05-18 14:18:38 +02:00
} ,
} ,
{
xtype : 'textfield' ,
inputType : 'password' ,
fieldLabel : gettext ( 'Confirm password' ) ,
name : 'verifypassword' ,
vtype : 'password' ,
initialPassField : 'password' ,
allowBlank : false ,
submitValue : false ,
2023-02-09 14:31:14 +01:00
bind : {
disabled : '{!maySetPassword}' ,
hidden : '{!maySetPassword}' ,
2020-05-18 14:18:38 +02:00
} ,
} ,
{
2023-02-09 14:31:14 +01:00
xtype : 'datefield' ,
name : 'expire' ,
2020-05-18 14:18:38 +02:00
emptyText : Proxmox . Utils . neverText ,
format : 'Y-m-d' ,
submitFormat : 'U' ,
2023-02-09 14:31:14 +01:00
fieldLabel : gettext ( 'Expire' ) ,
} ,
2020-05-18 14:18:38 +02:00
{
xtype : 'proxmoxcheckbox' ,
fieldLabel : gettext ( 'Enabled' ) ,
name : 'enable' ,
uncheckedValue : 0 ,
defaultValue : 1 ,
checked : true ,
} ,
] ,
column2 : [
{
xtype : 'proxmoxtextfield' ,
name : 'firstname' ,
fieldLabel : gettext ( 'First Name' ) ,
2020-11-11 13:34:13 +01:00
cbind : {
deleteEmpty : '{!isCreate}' ,
} ,
2020-05-18 14:18:38 +02:00
} ,
{
xtype : 'proxmoxtextfield' ,
name : 'lastname' ,
fieldLabel : gettext ( 'Last Name' ) ,
2020-11-11 13:34:13 +01:00
cbind : {
deleteEmpty : '{!isCreate}' ,
} ,
2020-05-18 14:18:38 +02:00
} ,
{
xtype : 'proxmoxtextfield' ,
name : 'email' ,
fieldLabel : gettext ( 'E-Mail' ) ,
vtype : 'proxmoxMail' ,
2020-11-11 13:34:13 +01:00
cbind : {
deleteEmpty : '{!isCreate}' ,
} ,
2020-05-18 14:18:38 +02:00
} ,
] ,
columnB : [
{
xtype : 'proxmoxtextfield' ,
name : 'comment' ,
fieldLabel : gettext ( 'Comment' ) ,
2020-11-11 13:34:13 +01:00
cbind : {
deleteEmpty : '{!isCreate}' ,
} ,
2020-05-18 14:18:38 +02:00
} ,
] ,
} ,
getValues : function ( dirtyOnly ) {
2024-03-07 10:37:35 +01:00
let me = this ;
2020-05-18 14:18:38 +02:00
2024-03-07 10:37:35 +01:00
let values = me . callParent ( arguments ) ;
2020-05-18 14:18:38 +02:00
if ( ! values . expire ) {
2024-03-07 10:37:35 +01:00
values . expire = 0 ; // "no expiry" is encoded as 0, so set that explicitly if left empty
2020-05-18 14:18:38 +02:00
}
if ( me . isCreate ) {
2023-02-09 14:31:14 +01:00
values . userid = values . userid + '@' + values . realm ;
2024-03-07 10:37:35 +01:00
delete values . realm ;
2020-05-18 14:18:38 +02:00
}
if ( ! values . password ) {
delete values . password ;
}
return values ;
} ,
setValues : function ( values ) {
var me = this ;
if ( Ext . isDefined ( values . expire ) ) {
if ( values . expire ) {
values . expire = new Date ( values . expire * 1000 ) ;
} else {
// display 'never' instead of '1970-01-01'
values . expire = null ;
}
}
me . callParent ( [ values ] ) ;
} ,
} ) ;