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