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