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