]> git.proxmox.com Git - pmg-gui.git/blob - js/UserEdit.js
pbs remote: add namespace support
[pmg-gui.git] / js / UserEdit.js
1 Ext.define('PMG.UserEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: 'widget.pmgUserEdit',
4 mixins: ['Proxmox.Mixin.CBind'],
5 onlineHelp: 'pmgconfig_localuser',
6
7 userid: undefined,
8
9 isAdd: true,
10
11 subject: gettext('User'),
12
13 fieldDefaults: { labelWidth: 120 },
14
15 cbindData: function(initialConfig) {
16 var me = this;
17
18 var userid = initialConfig.userid;
19 var baseurl = '/api2/extjs/access/users';
20
21 me.isCreate = !userid;
22 me.url = userid ? baseurl + '/' + userid : baseurl;
23 me.method = userid ? 'PUT' : 'POST';
24 me.autoLoad = !!userid;
25
26 return {
27 useridXType: userid ? 'displayfield' : 'textfield',
28 isSuperUser: userid === 'root@pam',
29 };
30 },
31
32 items: {
33 xtype: 'inputpanel',
34 column1: [
35 {
36 xtype: 'textfield',
37 name: 'username',
38 fieldLabel: gettext('User name'),
39 renderer: Ext.htmlEncode,
40 allowBlank: false,
41 minLength: 4,
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 });