]> git.proxmox.com Git - proxmox-backup.git/blame - www/window/UserEdit.js
ui: add calendar event selector
[proxmox-backup.git] / www / window / UserEdit.js
CommitLineData
88acc861
DC
1Ext.define('PBS.window.UserEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: 'widget.pbsUserEdit',
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.isCreate = !userid;
21 me.url = userid ? baseurl + '/' + userid : baseurl;
22 me.method = userid ? 'PUT' : 'POST';
23 me.autoLoad = !!userid;
24
25 return {
26 useridXType: userid ? 'displayfield' : 'textfield',
27 };
28 },
29
30 items: {
31 xtype: 'inputpanel',
32 column1: [
33 {
34 xtype: 'pmxDisplayEditField',
35 name: 'userid',
36 fieldLabel: gettext('User name'),
37 renderer: Ext.htmlEncode,
38 allowBlank: false,
39 minLength: 4,
40 cbind: {
41 editable: '{isCreate}',
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: '{!isCreate}',
61 disabled: '{!isCreate}',
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: '{!isCreate}',
75 disabled: '{!isCreate}',
76 },
77 },
78 {
79 xtype: 'datefield',
80 name: 'expire',
81 emptyText: Proxmox.Utils.neverText,
82 format: 'Y-m-d',
83 submitFormat: 'U',
84 fieldLabel: gettext('Expire'),
85 },
86 {
87 xtype: 'proxmoxcheckbox',
88 fieldLabel: gettext('Enabled'),
89 name: 'enable',
90 uncheckedValue: 0,
91 defaultValue: 1,
92 checked: true,
93 },
94 ],
95
96 column2: [
97 {
98 xtype: 'proxmoxtextfield',
99 name: 'firstname',
100 fieldLabel: gettext('First Name'),
101 },
102 {
103 xtype: 'proxmoxtextfield',
104 name: 'lastname',
105 fieldLabel: gettext('Last Name'),
106 },
107 {
108 xtype: 'proxmoxtextfield',
109 name: 'email',
110 fieldLabel: gettext('E-Mail'),
111 vtype: 'proxmoxMail',
112 },
113 ],
114
115 columnB: [
116 {
117 xtype: 'proxmoxtextfield',
118 name: 'comment',
119 fieldLabel: gettext('Comment'),
120 },
121 ],
122 },
123
124 getValues: function(dirtyOnly) {
125 var me = this;
126
127 var values = me.callParent(arguments);
128
129 // hack: ExtJS datefield does not submit 0, so we need to set that
130 if (!values.expire) {
131 values.expire = 0;
132 }
133
134 if (me.isCreate) {
135 values.userid = values.userid + '@pbs';
136 }
137
138 delete values.username;
139
140 if (!values.password) {
141 delete values.password;
142 }
143
144 return values;
145 },
146
147 setValues: function(values) {
148 var me = this;
149
150 if (Ext.isDefined(values.expire)) {
151 if (values.expire) {
152 values.expire = new Date(values.expire * 1000);
153 } else {
154 // display 'never' instead of '1970-01-01'
155 values.expire = null;
156 }
157 }
158
159 me.callParent([values]);
160 },
161});