]> git.proxmox.com Git - pmg-gui.git/blame - js/UserEdit.js
implement local user panel
[pmg-gui.git] / js / UserEdit.js
CommitLineData
ec1dd829
DM
1Ext.define('PMG.UserEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: ['widget.pmgUserEdit'],
4
5 isAdd: true,
6
7 initComponent : function() {
8 var me = this;
9
10 me.create = !me.userid;
11
12 var url;
13 var method;
14 var realm;
15
16 if (me.create) {
17 url = '/api2/extjs/access/users';
18 method = 'POST';
19 } else {
20 url = '/api2/extjs/access/users/' + me.userid;
21 method = 'PUT';
22 }
23
24 var verifypw;
25 var pwfield;
26
27 var validate_pw = function() {
28 if (verifypw.getValue() !== pwfield.getValue()) {
29 return gettext("Passwords does not match");
30 }
31 return true;
32 };
33
34 verifypw = Ext.createWidget('textfield', {
35 inputType: 'password',
36 fieldLabel: gettext('Confirm password'),
37 name: 'verifypassword',
38 submitValue: false,
39 validator: validate_pw
40 });
41
42 pwfield = Ext.createWidget('textfield', {
43 inputType: 'password',
44 fieldLabel: gettext('Password'),
45 minLength: 5,
46 name: 'password',
47 validator: validate_pw
48 });
49
50 var column1 = [
51 {
52 xtype: me.create ? 'textfield' : 'displayfield',
53 name: 'userid',
54 fieldLabel: gettext('User name'),
55 value: me.userid,
56 allowBlank: false,
57 submitValue: me.create ? true : false
58 }
59 ];
60
61 if (me.create) {
62 column1.push(pwfield, verifypw);
63 }
64
65 column1.push(
66 {
67 xtype: 'textfield',
68 name: 'role',
69 allowBlank: false,
70 fieldLabel: gettext('Role')
71 },
72 {
73 xtype: 'datefield',
74 name: 'expire',
75 emptyText: Proxmox.Utils.neverText,
76 format: 'Y-m-d',
77 disabled: me.userid === 'root@pam',
78 submitFormat: 'U',
79 fieldLabel: gettext('Expire')
80 },
81 {
82 xtype: 'proxmoxcheckbox',
83 fieldLabel: gettext('Enabled'),
84 name: 'enable',
85 disabled: me.userid === 'root@pam',
86 uncheckedValue: 0,
87 defaultValue: 1,
88 checked: true
89 }
90 );
91
92 var column2 = [
93 {
94 xtype: 'proxmoxtextfield',
95 name: 'firstname',
96 fieldLabel: gettext('First Name')
97 },
98 {
99 xtype: 'proxmoxtextfield',
100 name: 'lastname',
101 fieldLabel: gettext('Last Name')
102 },
103 {
104 xtype: 'proxmoxtextfield',
105 name: 'email',
106 fieldLabel: gettext('E-Mail'),
107 vtype: 'proxmoxMail'
108 }
109 ];
110
111 var columnB = [
112 {
113 xtype: 'proxmoxtextfield',
114 name: 'comment',
115 disabled: me.userid === 'root@pam',
116 fieldLabel: gettext('Comment')
117 },
118 {
119 xtype: 'proxmoxtextfield',
120 name: 'keys',
121 fieldLabel: gettext('Key IDs')
122 }
123 ];
124
125 var ipanel = Ext.create('Proxmox.panel.InputPanel', {
126 column1: column1,
127 column2: column2,
128 columnB: columnB,
129 onGetValues: function(values) {
130 // hack: ExtJS datefield does not submit 0, so we need to set that
131 if (!values.expire) {
132 values.expire = 0;
133 }
134
135 if (me.create) {
136 values.userid = values.userid + '@pmg';
137 }
138
139 if (!values.password) {
140 delete values.password;
141 }
142
143 console.dir(values);
144
145 return values;
146 }
147 });
148
149 Ext.applyIf(me, {
150 subject: gettext('User'),
151 url: url,
152 method: method,
153 fieldDefaults: {
154 labelWidth: 120
155 },
156 items: [ ipanel ]
157 });
158
159 me.callParent();
160
161 if (!me.create) {
162 me.load({
163 success: function(response, options) {
164 var data = response.result.data;
165 if (Ext.isDefined(data.expire)) {
166 if (data.expire) {
167 data.expire = new Date(data.expire * 1000);
168 } else {
169 // display 'never' instead of '1970-01-01'
170 data.expire = null;
171 }
172 }
173 me.setValues(data);
174 }
175 });
176 }
177 }
178});