]> git.proxmox.com Git - pve-manager.git/blob - www/manager/dc/UserEdit.js
use standard titles for create/edit dialogs
[pve-manager.git] / www / manager / dc / UserEdit.js
1 Ext.define('PVE.dc.UserEdit', {
2 extend: 'PVE.window.Edit',
3 alias: ['widget.pveDcUserEdit'],
4
5 initComponent : function() {
6 var me = this;
7
8 me.create = !me.userid;
9
10 var url;
11 var method;
12 var realm;
13
14 if (me.create) {
15 url = '/api2/extjs/access/users';
16 method = 'POST';
17 } else {
18 url = '/api2/extjs/access/users/' + me.userid;
19 method = 'PUT';
20 }
21
22 var column1 = [
23 {
24 xtype: me.create ? 'textfield' : 'displayfield',
25 name: 'userid',
26 fieldLabel: gettext('User name'),
27 value: me.userid,
28 allowBlank: false,
29 submitValue: me.create ? true : false
30 },
31 {
32 xtype: 'pveGroupSelector',
33 name: 'groups',
34 multiSelect: true,
35 allowBlank: true,
36 fieldLabel: gettext('Group')
37 },
38 {
39 xtype: 'datefield',
40 name: 'expire',
41 emptyText: 'never',
42 format: 'Y-m-d',
43 submitFormat: 'U',
44 fieldLabel: gettext('Expire')
45 },
46 {
47 xtype: 'pvecheckbox',
48 fieldLabel: gettext('Enabled'),
49 name: 'enable',
50 uncheckedValue: 0,
51 defaultValue: 1
52 }
53 ];
54
55 var column2 = [
56 {
57 xtype: 'textfield',
58 name: 'firstname',
59 fieldLabel: gettext('First Name')
60 },
61 {
62 xtype: 'textfield',
63 name: 'lastname',
64 fieldLabel: gettext('Last Name')
65 },
66 {
67 xtype: 'textfield',
68 name: 'email',
69 fieldLabel: 'E-Mail',
70 vtype: 'email'
71 },
72 {
73 xtype: 'textfield',
74 name: 'comment',
75 fieldLabel: gettext('Comment')
76 }
77 ];
78
79 if (me.create) {
80 column1.splice(1,0,{
81 xtype: 'pveRealmComboBox',
82 name: 'realm',
83 fieldLabel: gettext('Realm'),
84 allowBlank: false,
85 listeners: {
86 change: function(combo, newValue){
87 realm = newValue;
88 }
89 },
90 submitValue: false
91 });
92 }
93
94
95 var ipanel = Ext.create('PVE.panel.InputPanel', {
96 column1: column1,
97 column2: column2,
98 onGetValues: function(values) {
99 // hack: ExtJS datefield does not submit 0, so we need to set that
100 if (!values.expire) {
101 values.expire = 0;
102 }
103
104 if (realm) {
105 values.userid = values.userid + '@' + realm;
106 }
107
108 return values;
109 }
110 });
111
112 Ext.applyIf(me, {
113 subject: gettext('User'),
114 url: url,
115 method: method,
116 items: [ ipanel ]
117 });
118
119 me.callParent();
120
121 if (!me.create) {
122 me.load({
123 success: function(response, options) {
124 var data = response.result.data;
125 if (Ext.isDefined(data.expire)) {
126 if (data.expire) {
127 data.expire = new Date(data.expire * 1000);
128 } else {
129 // display 'never' instead of '1970-01-01'
130 data.expire = null;
131 }
132 }
133
134 me.setValues(data);
135 }
136 });
137 }
138 }
139 });