]> git.proxmox.com Git - pmg-gui.git/blob - js/UserEdit.js
e3ab5a296970680e4dee4a3e6c5838e674b732eb
[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
9 userid: undefined,
10
11 isAdd: true,
12
13 subject: gettext('User'),
14
15 fieldDefaults: { labelWidth: 120 },
16
17 cbindData: function(initialConfig) {
18 var me = this;
19
20 var userid = initialConfig.userid;
21 var baseurl = '/api2/extjs/access/users';
22
23 me.isCreate = !userid;
24 me.url = userid ? baseurl + '/' + userid : baseurl;
25 me.method = userid ? 'PUT' : 'POST';
26 me.autoLoad = userid ? true : false;
27
28 return {
29 useridXType: userid ? 'displayfield' : 'textfield',
30 isSuperUser: userid === 'root@pam'
31 };
32 },
33
34 items: {
35 xtype: 'inputpanel',
36 column1: [
37 {
38 xtype: 'textfield',
39 name: 'username',
40 fieldLabel: gettext('User name'),
41 allowBlank: false,
42 cbind: {
43 submitValue: '{isCreate}',
44 xtype: '{useridXType}'
45 }
46 },
47 {
48 xtype: 'textfield',
49 inputType: 'password',
50 fieldLabel: gettext('Password'),
51 minLength: 5,
52 allowBlank: false,
53 name: 'password',
54 listeners: {
55 change: function(field){
56 field.next().validate();
57 },
58 blur: function(field){
59 field.next().validate();
60 }
61 },
62 cbind: {
63 hidden: '{!isCreate}',
64 disabled: '{!isCreate}'
65 }
66 },
67 {
68 xtype: 'textfield',
69 inputType: 'password',
70 fieldLabel: gettext('Confirm password'),
71 name: 'verifypassword',
72 vtype: 'password',
73 initialPassField: 'password',
74 allowBlank: false,
75 submitValue: false,
76 cbind: {
77 hidden: '{!isCreate}',
78 disabled: '{!isCreate}'
79 }
80 },
81 {
82 xtype: 'pmgRoleSelector',
83 name: 'role',
84 allowBlank: false,
85 fieldLabel: gettext('Role'),
86 cbind: {
87 disabled: '{isSuperUser}'
88 }
89 },
90 {
91 xtype: 'datefield',
92 name: 'expire',
93 emptyText: Proxmox.Utils.neverText,
94 format: 'Y-m-d',
95 submitFormat: 'U',
96 fieldLabel: gettext('Expire'),
97 cbind: {
98 disabled: '{isSuperUser}'
99 }
100 },
101 {
102 xtype: 'proxmoxcheckbox',
103 fieldLabel: gettext('Enabled'),
104 name: 'enable',
105 uncheckedValue: 0,
106 defaultValue: 1,
107 checked: true,
108 cbind: {
109 disabled: '{isSuperUser}'
110 }
111 }
112 ],
113
114 column2: [
115 {
116 xtype: 'proxmoxtextfield',
117 name: 'firstname',
118 fieldLabel: gettext('First Name'),
119 cbind: {
120 deleteEmpty: '{!isCreate}'
121 }
122 },
123 {
124 xtype: 'proxmoxtextfield',
125 name: 'lastname',
126 fieldLabel: gettext('Last Name'),
127 cbind: {
128 deleteEmpty: '{!isCreate}'
129 }
130 },
131 {
132 xtype: 'proxmoxtextfield',
133 name: 'email',
134 fieldLabel: gettext('E-Mail'),
135 vtype: 'proxmoxMail',
136 cbind: {
137 deleteEmpty: '{!isCreate}'
138 }
139 }
140 ],
141
142 columnB: [
143 {
144 xtype: 'proxmoxtextfield',
145 name: 'comment',
146 fieldLabel: gettext('Comment'),
147 cbind: {
148 disabled: '{isSuperUser}',
149 deleteEmpty: '{!isCreate}'
150 }
151 },
152 {
153 xtype: 'proxmoxtextfield',
154 name: 'keys',
155 fieldLabel: gettext('Key IDs'),
156 cbind: {
157 deleteEmpty: '{!isCreate}'
158 }
159 }
160 ]
161 },
162
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.isCreate) {
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
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]);
199 }
200 });