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