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