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