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