]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/dc/UserEdit.js
40c4044fd9364c9bcb8787507068378ed9936f67
[pve-manager.git] / www / manager6 / dc / UserEdit.js
1 Ext.define('PVE.dc.UserEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: ['widget.pveDcUserEdit'],
4
5 isAdd: true,
6
7 initComponent : function() {
8 var me = this;
9
10 me.isCreate = !me.userid;
11
12 var url;
13 var method;
14 var realm;
15
16 if (me.isCreate) {
17 url = '/api2/extjs/access/users';
18 method = 'POST';
19 } else {
20 url = '/api2/extjs/access/users/' + encodeURIComponent(me.userid);
21 method = 'PUT';
22 }
23
24 var verifypw;
25 var pwfield;
26
27 var validate_pw = function() {
28 if (verifypw.getValue() !== pwfield.getValue()) {
29 return gettext("Passwords do not match");
30 }
31 return true;
32 };
33
34 verifypw = Ext.createWidget('textfield', {
35 inputType: 'password',
36 fieldLabel: gettext('Confirm password'),
37 name: 'verifypassword',
38 submitValue: false,
39 disabled: true,
40 hidden: true,
41 validator: validate_pw
42 });
43
44 pwfield = Ext.createWidget('textfield', {
45 inputType: 'password',
46 fieldLabel: gettext('Password'),
47 minLength: 5,
48 name: 'password',
49 disabled: true,
50 hidden: true,
51 validator: validate_pw
52 });
53
54 var update_passwd_field = function(realm) {
55 if (realm === 'pve') {
56 pwfield.setVisible(true);
57 pwfield.setDisabled(false);
58 verifypw.setVisible(true);
59 verifypw.setDisabled(false);
60 } else {
61 pwfield.setVisible(false);
62 pwfield.setDisabled(true);
63 verifypw.setVisible(false);
64 verifypw.setDisabled(true);
65 }
66
67 };
68
69 var column1 = [
70 {
71 xtype: me.isCreate ? 'textfield' : 'displayfield',
72 name: 'userid',
73 fieldLabel: gettext('User name'),
74 value: me.userid,
75 allowBlank: false,
76 submitValue: me.isCreate ? true : false
77 },
78 pwfield, verifypw,
79 {
80 xtype: 'pveGroupSelector',
81 name: 'groups',
82 multiSelect: true,
83 allowBlank: true,
84 fieldLabel: gettext('Group')
85 },
86 {
87 xtype: 'datefield',
88 name: 'expire',
89 emptyText: 'never',
90 format: 'Y-m-d',
91 submitFormat: 'U',
92 fieldLabel: gettext('Expire')
93 },
94 {
95 xtype: 'proxmoxcheckbox',
96 fieldLabel: gettext('Enabled'),
97 name: 'enable',
98 uncheckedValue: 0,
99 defaultValue: 1,
100 checked: true
101 }
102 ];
103
104 var column2 = [
105 {
106 xtype: 'textfield',
107 name: 'firstname',
108 fieldLabel: gettext('First Name')
109 },
110 {
111 xtype: 'textfield',
112 name: 'lastname',
113 fieldLabel: gettext('Last Name')
114 },
115 {
116 xtype: 'textfield',
117 name: 'email',
118 fieldLabel: gettext('E-Mail'),
119 vtype: 'proxmoxMail'
120 }
121 ];
122
123 if (me.isCreate) {
124 column1.splice(1,0,{
125 xtype: 'pveRealmComboBox',
126 name: 'realm',
127 fieldLabel: gettext('Realm'),
128 allowBlank: false,
129 matchFieldWidth: false,
130 listConfig: { width: 300 },
131 listeners: {
132 change: function(combo, newValue){
133 realm = newValue;
134 update_passwd_field(realm);
135 }
136 },
137 submitValue: false
138 });
139 }
140
141 var ipanel = Ext.create('Proxmox.panel.InputPanel', {
142 column1: column1,
143 column2: column2,
144 columnB: [
145 {
146 xtype: 'textfield',
147 name: 'comment',
148 fieldLabel: gettext('Comment')
149 }
150 ],
151 advancedItems: [
152 {
153 xtype: 'textfield',
154 name: 'keys',
155 fieldLabel: gettext('Key IDs')
156 }
157 ],
158 onGetValues: function(values) {
159 // hack: ExtJS datefield does not submit 0, so we need to set that
160 if (!values.expire) {
161 values.expire = 0;
162 }
163
164 if (realm) {
165 values.userid = values.userid + '@' + realm;
166 }
167
168 if (!values.password) {
169 delete values.password;
170 }
171
172 return values;
173 }
174 });
175
176 Ext.applyIf(me, {
177 subject: gettext('User'),
178 url: url,
179 method: method,
180 fieldDefaults: {
181 labelWidth: 110 // for spanish translation
182 },
183 items: [ ipanel ]
184 });
185
186 me.callParent();
187
188 if (!me.isCreate) {
189 me.load({
190 success: function(response, options) {
191 var data = response.result.data;
192 if (Ext.isDefined(data.expire)) {
193 if (data.expire) {
194 data.expire = new Date(data.expire * 1000);
195 } else {
196 // display 'never' instead of '1970-01-01'
197 data.expire = null;
198 }
199 }
200 me.setValues(data);
201 if (data.keys) {
202 if ( data.keys === 'x!oath' || data.keys === 'x!u2f' ) {
203 me.down('[name="keys"]').setDisabled(1);
204 }
205 }
206 }
207 });
208 }
209 }
210 });