Ext.define('PMG.UserEdit', {
extend: 'Proxmox.window.Edit',
- alias: ['widget.pmgUserEdit'],
+ alias: 'widget.pmgUserEdit',
+ mixins: ['Proxmox.Mixin.CBind'],
+ onlineHelp: 'pmgconfig_localuser',
+
+ userid: undefined,
isAdd: true,
- initComponent : function() {
- var me = this;
+ subject: gettext('User'),
- me.create = !me.userid;
+ fieldDefaults: { labelWidth: 120 },
- var url;
- var method;
- var realm;
+ cbindData: function(initialConfig) {
+ var me = this;
- if (me.create) {
- url = '/api2/extjs/access/users';
- method = 'POST';
- } else {
- url = '/api2/extjs/access/users/' + me.userid;
- method = 'PUT';
- }
+ var userid = initialConfig.userid;
+ var baseurl = '/api2/extjs/access/users';
- var verifypw;
- var pwfield;
+ me.isCreate = !userid;
+ me.url = userid ? baseurl + '/' + userid : baseurl;
+ me.method = userid ? 'PUT' : 'POST';
+ me.autoLoad = !!userid;
- var validate_pw = function() {
- if (verifypw.getValue() !== pwfield.getValue()) {
- return gettext("Passwords does not match");
- }
- return true;
+ return {
+ useridXType: userid ? 'displayfield' : 'textfield',
+ isSuperUser: userid === 'root@pam',
};
+ },
- verifypw = Ext.createWidget('textfield', {
- inputType: 'password',
- fieldLabel: gettext('Confirm password'),
- name: 'verifypassword',
- submitValue: false,
- validator: validate_pw
- });
-
- pwfield = Ext.createWidget('textfield', {
- inputType: 'password',
- fieldLabel: gettext('Password'),
- minLength: 5,
- name: 'password',
- validator: validate_pw
- });
-
- var column1 = [
- {
- xtype: me.create ? 'textfield' : 'displayfield',
- name: 'userid',
- fieldLabel: gettext('User name'),
- value: me.userid,
- allowBlank: false,
- submitValue: me.create ? true : false
- }
- ];
-
- if (me.create) {
- column1.push(pwfield, verifypw);
- }
-
- column1.push(
+ items: {
+ xtype: 'inputpanel',
+ column1: [
+ {
+ xtype: 'textfield',
+ name: 'username',
+ fieldLabel: gettext('User name'),
+ renderer: Ext.htmlEncode,
+ allowBlank: false,
+ minLength: 4,
+ cbind: {
+ submitValue: '{isCreate}',
+ xtype: '{useridXType}',
+ },
+ },
+ {
+ xtype: 'textfield',
+ inputType: 'password',
+ fieldLabel: gettext('Password'),
+ minLength: 5,
+ allowBlank: false,
+ name: 'password',
+ listeners: {
+ change: function(field) {
+ field.next().validate();
+ },
+ blur: function(field) {
+ field.next().validate();
+ },
+ },
+ cbind: {
+ hidden: '{!isCreate}',
+ disabled: '{!isCreate}',
+ },
+ },
+ {
+ xtype: 'textfield',
+ inputType: 'password',
+ fieldLabel: gettext('Confirm password'),
+ name: 'verifypassword',
+ vtype: 'password',
+ initialPassField: 'password',
+ allowBlank: false,
+ submitValue: false,
+ cbind: {
+ hidden: '{!isCreate}',
+ disabled: '{!isCreate}',
+ },
+ },
{
xtype: 'pmgRoleSelector',
name: 'role',
- disabled: me.userid === 'root@pam',
allowBlank: false,
- fieldLabel: gettext('Role')
+ fieldLabel: gettext('Role'),
+ cbind: {
+ disabled: '{isSuperUser}',
+ },
},
- {
+ {
xtype: 'datefield',
name: 'expire',
emptyText: Proxmox.Utils.neverText,
format: 'Y-m-d',
- disabled: me.userid === 'root@pam',
submitFormat: 'U',
- fieldLabel: gettext('Expire')
+ fieldLabel: gettext('Expire'),
+ cbind: {
+ disabled: '{isSuperUser}',
+ },
},
{
xtype: 'proxmoxcheckbox',
fieldLabel: gettext('Enabled'),
name: 'enable',
- disabled: me.userid === 'root@pam',
uncheckedValue: 0,
defaultValue: 1,
- checked: true
- }
- );
+ checked: true,
+ cbind: {
+ disabled: '{isSuperUser}',
+ },
+ },
+ ],
- var column2 = [
+ column2: [
{
xtype: 'proxmoxtextfield',
- deleteEmpty: me.create ? false : true,
name: 'firstname',
- fieldLabel: gettext('First Name')
+ fieldLabel: gettext('First Name'),
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
},
{
xtype: 'proxmoxtextfield',
- deleteEmpty: me.create ? false : true,
name: 'lastname',
- fieldLabel: gettext('Last Name')
+ fieldLabel: gettext('Last Name'),
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
},
{
xtype: 'proxmoxtextfield',
name: 'email',
- deleteEmpty: me.create ? false : true,
fieldLabel: gettext('E-Mail'),
- vtype: 'proxmoxMail'
- }
- ];
+ vtype: 'proxmoxMail',
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
+ },
+ ],
- var columnB = [
+ columnB: [
{
xtype: 'proxmoxtextfield',
name: 'comment',
- deleteEmpty: me.create ? false : true,
- disabled: me.userid === 'root@pam',
- fieldLabel: gettext('Comment')
+ fieldLabel: gettext('Comment'),
+ cbind: {
+ disabled: '{isSuperUser}',
+ deleteEmpty: '{!isCreate}',
+ },
},
{
xtype: 'proxmoxtextfield',
- deleteEmpty: me.create ? false : true,
name: 'keys',
- fieldLabel: gettext('Key IDs')
- }
- ];
-
- var ipanel = Ext.create('Proxmox.panel.InputPanel', {
- column1: column1,
- column2: column2,
- columnB: columnB,
- onGetValues: function(values) {
- // hack: ExtJS datefield does not submit 0, so we need to set that
- if (!values.expire) {
- values.expire = 0;
- }
-
- if (me.create) {
- values.userid = values.userid + '@pmg';
- }
-
- if (!values.password) {
- delete values.password;
- }
-
- return values;
- }
- });
-
- Ext.applyIf(me, {
- subject: gettext('User'),
- url: url,
- method: method,
- fieldDefaults: {
- labelWidth: 120
+ fieldLabel: gettext('Key IDs'),
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
},
- items: [ ipanel ]
- });
-
- me.callParent();
-
- if (!me.create) {
- me.load({
- success: function(response, options) {
- var data = response.result.data;
- if (Ext.isDefined(data.expire)) {
- if (data.expire) {
- data.expire = new Date(data.expire * 1000);
- } else {
- // display 'never' instead of '1970-01-01'
- data.expire = null;
- }
- }
- me.setValues(data);
- }
- });
- }
- }
+ ],
+ },
+
+ getValues: function(dirtyOnly) {
+ var me = this;
+
+ var values = me.callParent(arguments);
+
+ // hack: ExtJS datefield does not submit 0, so we need to set that
+ if (!values.expire) {
+ values.expire = 0;
+ }
+
+ if (me.isCreate) {
+ values.userid = values.username + '@pmg';
+ }
+
+ delete values.username;
+
+ 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]);
+ },
});