]>
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'], | |
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, |
40ced664 | 41 | minLength: 4, |
2f74c5b4 | 42 | cbind: { |
18b5b6ad | 43 | submitValue: '{isCreate}', |
c87d46fb TL |
44 | xtype: '{useridXType}', |
45 | }, | |
b7e43bc4 DM |
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: { | |
c87d46fb | 55 | change: function(field) { |
b7e43bc4 DM |
56 | field.next().validate(); |
57 | }, | |
c87d46fb | 58 | blur: function(field) { |
b7e43bc4 | 59 | field.next().validate(); |
c87d46fb | 60 | }, |
b7e43bc4 | 61 | }, |
2f74c5b4 | 62 | cbind: { |
18b5b6ad | 63 | hidden: '{!isCreate}', |
c87d46fb TL |
64 | disabled: '{!isCreate}', |
65 | }, | |
b7e43bc4 DM |
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 | 76 | cbind: { |
18b5b6ad | 77 | hidden: '{!isCreate}', |
c87d46fb TL |
78 | disabled: '{!isCreate}', |
79 | }, | |
b7e43bc4 | 80 | }, |
ec1dd829 | 81 | { |
c0ffdd00 | 82 | xtype: 'pmgRoleSelector', |
ec1dd829 DM |
83 | name: 'role', |
84 | allowBlank: false, | |
b7e43bc4 | 85 | fieldLabel: gettext('Role'), |
2f74c5b4 | 86 | cbind: { |
c87d46fb TL |
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: { |
c87d46fb TL |
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: { |
c87d46fb TL |
109 | disabled: '{isSuperUser}', |
110 | }, | |
111 | }, | |
b7e43bc4 | 112 | ], |
ec1dd829 | 113 | |
b7e43bc4 | 114 | column2: [ |
ec1dd829 DM |
115 | { |
116 | xtype: 'proxmoxtextfield', | |
117 | name: 'firstname', | |
b7e43bc4 | 118 | fieldLabel: gettext('First Name'), |
2f74c5b4 | 119 | cbind: { |
c87d46fb TL |
120 | deleteEmpty: '{!isCreate}', |
121 | }, | |
ec1dd829 DM |
122 | }, |
123 | { | |
124 | xtype: 'proxmoxtextfield', | |
125 | name: 'lastname', | |
b7e43bc4 | 126 | fieldLabel: gettext('Last Name'), |
2f74c5b4 | 127 | cbind: { |
c87d46fb TL |
128 | deleteEmpty: '{!isCreate}', |
129 | }, | |
ec1dd829 DM |
130 | }, |
131 | { | |
132 | xtype: 'proxmoxtextfield', | |
133 | name: 'email', | |
134 | fieldLabel: gettext('E-Mail'), | |
b7e43bc4 | 135 | vtype: 'proxmoxMail', |
2f74c5b4 | 136 | cbind: { |
c87d46fb TL |
137 | deleteEmpty: '{!isCreate}', |
138 | }, | |
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}', |
c87d46fb TL |
149 | deleteEmpty: '{!isCreate}', |
150 | }, | |
ec1dd829 DM |
151 | }, |
152 | { | |
153 | xtype: 'proxmoxtextfield', | |
154 | name: 'keys', | |
b7e43bc4 | 155 | fieldLabel: gettext('Key IDs'), |
2f74c5b4 | 156 | cbind: { |
c87d46fb TL |
157 | deleteEmpty: '{!isCreate}', |
158 | }, | |
159 | }, | |
160 | ], | |
b7e43bc4 | 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 | ||
18b5b6ad | 173 | if (me.isCreate) { |
c5e49a3d DM |
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]); | |
c87d46fb | 199 | }, |
ec1dd829 | 200 | }); |