]> git.proxmox.com Git - pmg-gui.git/blame - js/UserEdit.js
ui: trim whitespaces when adding a subscription key
[pmg-gui.git] / js / UserEdit.js
CommitLineData
b7e43bc4
DM
1Ext.define('PMG.UserEdit', {
2 extend: 'Proxmox.window.Edit',
2f74c5b4
DM
3 alias: 'widget.pmgUserEdit',
4 mixins: ['Proxmox.Mixin.CBind'],
573a6e8b 5 onlineHelp: 'pmgconfig_localuser',
3142a237 6
2f74c5b4 7 userid: undefined,
ec1dd829 8
b7e43bc4 9 isAdd: true,
ec1dd829 10
b7e43bc4 11 subject: gettext('User'),
ec1dd829 12
b7e43bc4 13 fieldDefaults: { labelWidth: 120 },
4d904e0a 14
2f74c5b4
DM
15 cbindData: function(initialConfig) {
16 var me = this;
17
18 var userid = initialConfig.userid;
19 var baseurl = '/api2/extjs/access/users';
20
18b5b6ad 21 me.isCreate = !userid;
c87d46fb 22 me.url = userid ? baseurl + '/' + userid : baseurl;
2f74c5b4 23 me.method = userid ? 'PUT' : 'POST';
c87d46fb 24 me.autoLoad = !!userid;
2f74c5b4
DM
25
26 return {
b4ca6e3a 27 useridXType: userid ? 'displayfield' : 'textfield',
c87d46fb 28 isSuperUser: userid === 'root@pam',
131ba4f6 29 };
2f74c5b4
DM
30 },
31
b7e43bc4
DM
32 items: {
33 xtype: 'inputpanel',
b7e43bc4
DM
34 column1: [
35 {
36 xtype: 'textfield',
c5e49a3d 37 name: 'username',
b7e43bc4 38 fieldLabel: gettext('User name'),
5b621b46 39 renderer: Ext.htmlEncode,
b7e43bc4 40 allowBlank: false,
2f74c5b4 41 cbind: {
18b5b6ad 42 submitValue: '{isCreate}',
c87d46fb
TL
43 xtype: '{useridXType}',
44 },
b7e43bc4
DM
45 },
46 {
47 xtype: 'textfield',
48 inputType: 'password',
49 fieldLabel: gettext('Password'),
50 minLength: 5,
466b5739 51 allowBlank: false,
b7e43bc4
DM
52 name: 'password',
53 listeners: {
c87d46fb 54 change: function(field) {
b7e43bc4
DM
55 field.next().validate();
56 },
c87d46fb 57 blur: function(field) {
b7e43bc4 58 field.next().validate();
c87d46fb 59 },
b7e43bc4 60 },
2f74c5b4 61 cbind: {
18b5b6ad 62 hidden: '{!isCreate}',
c87d46fb
TL
63 disabled: '{!isCreate}',
64 },
b7e43bc4
DM
65 },
66 {
ccbf186f 67 xtype: 'textfield',
b7e43bc4
DM
68 inputType: 'password',
69 fieldLabel: gettext('Confirm password'),
70 name: 'verifypassword',
71 vtype: 'password',
72 initialPassField: 'password',
466b5739 73 allowBlank: false,
b7e43bc4 74 submitValue: false,
2f74c5b4 75 cbind: {
18b5b6ad 76 hidden: '{!isCreate}',
c87d46fb
TL
77 disabled: '{!isCreate}',
78 },
b7e43bc4 79 },
ec1dd829 80 {
c0ffdd00 81 xtype: 'pmgRoleSelector',
ec1dd829
DM
82 name: 'role',
83 allowBlank: false,
b7e43bc4 84 fieldLabel: gettext('Role'),
2f74c5b4 85 cbind: {
c87d46fb
TL
86 disabled: '{isSuperUser}',
87 },
ec1dd829 88 },
b7e43bc4 89 {
ec1dd829
DM
90 xtype: 'datefield',
91 name: 'expire',
92 emptyText: Proxmox.Utils.neverText,
93 format: 'Y-m-d',
ec1dd829 94 submitFormat: 'U',
b7e43bc4 95 fieldLabel: gettext('Expire'),
2f74c5b4 96 cbind: {
c87d46fb
TL
97 disabled: '{isSuperUser}',
98 },
ec1dd829
DM
99 },
100 {
101 xtype: 'proxmoxcheckbox',
102 fieldLabel: gettext('Enabled'),
103 name: 'enable',
ec1dd829
DM
104 uncheckedValue: 0,
105 defaultValue: 1,
b7e43bc4 106 checked: true,
2f74c5b4 107 cbind: {
c87d46fb
TL
108 disabled: '{isSuperUser}',
109 },
110 },
b7e43bc4 111 ],
ec1dd829 112
b7e43bc4 113 column2: [
ec1dd829
DM
114 {
115 xtype: 'proxmoxtextfield',
116 name: 'firstname',
b7e43bc4 117 fieldLabel: gettext('First Name'),
2f74c5b4 118 cbind: {
c87d46fb
TL
119 deleteEmpty: '{!isCreate}',
120 },
ec1dd829
DM
121 },
122 {
123 xtype: 'proxmoxtextfield',
124 name: 'lastname',
b7e43bc4 125 fieldLabel: gettext('Last Name'),
2f74c5b4 126 cbind: {
c87d46fb
TL
127 deleteEmpty: '{!isCreate}',
128 },
ec1dd829
DM
129 },
130 {
131 xtype: 'proxmoxtextfield',
132 name: 'email',
133 fieldLabel: gettext('E-Mail'),
b7e43bc4 134 vtype: 'proxmoxMail',
2f74c5b4 135 cbind: {
c87d46fb
TL
136 deleteEmpty: '{!isCreate}',
137 },
138 },
b7e43bc4 139 ],
ec1dd829 140
b7e43bc4 141 columnB: [
ec1dd829
DM
142 {
143 xtype: 'proxmoxtextfield',
144 name: 'comment',
b7e43bc4 145 fieldLabel: gettext('Comment'),
2f74c5b4 146 cbind: {
b7e43bc4 147 disabled: '{isSuperUser}',
c87d46fb
TL
148 deleteEmpty: '{!isCreate}',
149 },
ec1dd829
DM
150 },
151 {
152 xtype: 'proxmoxtextfield',
153 name: 'keys',
b7e43bc4 154 fieldLabel: gettext('Key IDs'),
2f74c5b4 155 cbind: {
c87d46fb
TL
156 deleteEmpty: '{!isCreate}',
157 },
158 },
159 ],
b7e43bc4 160 },
ec1dd829 161
c5e49a3d
DM
162 getValues: function(dirtyOnly) {
163 var me = this;
164
165 var values = me.callParent(arguments);
166
167 // hack: ExtJS datefield does not submit 0, so we need to set that
168 if (!values.expire) {
169 values.expire = 0;
170 }
171
18b5b6ad 172 if (me.isCreate) {
c5e49a3d
DM
173 values.userid = values.username + '@pmg';
174 }
175
176 delete values.username;
177
178 if (!values.password) {
179 delete values.password;
180 }
181
182 return values;
183 },
184
2d1e22dd
DM
185 setValues: function(values) {
186 var me = this;
187
188 if (Ext.isDefined(values.expire)) {
189 if (values.expire) {
190 values.expire = new Date(values.expire * 1000);
191 } else {
192 // display 'never' instead of '1970-01-01'
193 values.expire = null;
194 }
195 }
196
197 me.callParent([values]);
c87d46fb 198 },
ec1dd829 199});