]> git.proxmox.com Git - pmg-gui.git/blob - js/UserEdit.js
bump version to 1.0-26
[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 renderer: Ext.htmlEncode,
42 allowBlank: false,
43 cbind: {
44 submitValue: '{isCreate}',
45 xtype: '{useridXType}'
46 }
47 },
48 {
49 xtype: 'textfield',
50 inputType: 'password',
51 fieldLabel: gettext('Password'),
52 minLength: 5,
53 allowBlank: false,
54 name: 'password',
55 listeners: {
56 change: function(field){
57 field.next().validate();
58 },
59 blur: function(field){
60 field.next().validate();
61 }
62 },
63 cbind: {
64 hidden: '{!isCreate}',
65 disabled: '{!isCreate}'
66 }
67 },
68 {
69 xtype: 'textfield',
70 inputType: 'password',
71 fieldLabel: gettext('Confirm password'),
72 name: 'verifypassword',
73 vtype: 'password',
74 initialPassField: 'password',
75 allowBlank: false,
76 submitValue: false,
77 cbind: {
78 hidden: '{!isCreate}',
79 disabled: '{!isCreate}'
80 }
81 },
82 {
83 xtype: 'pmgRoleSelector',
84 name: 'role',
85 allowBlank: false,
86 fieldLabel: gettext('Role'),
87 cbind: {
88 disabled: '{isSuperUser}'
89 }
90 },
91 {
92 xtype: 'datefield',
93 name: 'expire',
94 emptyText: Proxmox.Utils.neverText,
95 format: 'Y-m-d',
96 submitFormat: 'U',
97 fieldLabel: gettext('Expire'),
98 cbind: {
99 disabled: '{isSuperUser}'
100 }
101 },
102 {
103 xtype: 'proxmoxcheckbox',
104 fieldLabel: gettext('Enabled'),
105 name: 'enable',
106 uncheckedValue: 0,
107 defaultValue: 1,
108 checked: true,
109 cbind: {
110 disabled: '{isSuperUser}'
111 }
112 }
113 ],
114
115 column2: [
116 {
117 xtype: 'proxmoxtextfield',
118 name: 'firstname',
119 fieldLabel: gettext('First Name'),
120 cbind: {
121 deleteEmpty: '{!isCreate}'
122 }
123 },
124 {
125 xtype: 'proxmoxtextfield',
126 name: 'lastname',
127 fieldLabel: gettext('Last Name'),
128 cbind: {
129 deleteEmpty: '{!isCreate}'
130 }
131 },
132 {
133 xtype: 'proxmoxtextfield',
134 name: 'email',
135 fieldLabel: gettext('E-Mail'),
136 vtype: 'proxmoxMail',
137 cbind: {
138 deleteEmpty: '{!isCreate}'
139 }
140 }
141 ],
142
143 columnB: [
144 {
145 xtype: 'proxmoxtextfield',
146 name: 'comment',
147 fieldLabel: gettext('Comment'),
148 cbind: {
149 disabled: '{isSuperUser}',
150 deleteEmpty: '{!isCreate}'
151 }
152 },
153 {
154 xtype: 'proxmoxtextfield',
155 name: 'keys',
156 fieldLabel: gettext('Key IDs'),
157 cbind: {
158 deleteEmpty: '{!isCreate}'
159 }
160 }
161 ]
162 },
163
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
174 if (me.isCreate) {
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
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]);
200 }
201 });