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