]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/window/TfaEdit.js
file browser: unify file type schema and avoid switch-case bloat
[proxmox-widget-toolkit.git] / src / window / TfaEdit.js
1 Ext.define('Proxmox.window.TfaEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: 'widget.pmxTfaEdit',
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 onlineHelp: 'user_mgmt',
7
8 modal: true,
9 resizable: false,
10 title: gettext("Modify a TFA entry's description"),
11 width: 512,
12
13 layout: {
14 type: 'vbox',
15 align: 'stretch',
16 },
17
18 cbindData: function(initialConfig) {
19 let me = this;
20
21 let tfa_id = initialConfig['tfa-id'];
22 me.tfa_id = tfa_id;
23 me.defaultFocus = 'textfield[name=description]';
24 me.url = `/api2/extjs/access/tfa/${tfa_id}`;
25 me.method = 'PUT';
26 me.autoLoad = true;
27 return {};
28 },
29
30 initComponent: function() {
31 let me = this;
32 me.callParent();
33
34 if (Proxmox.UserName === 'root@pam') {
35 me.lookup('password').setVisible(false);
36 me.lookup('password').setDisabled(true);
37 }
38
39 let userid = me.tfa_id.split('/')[0];
40 me.lookup('userid').setValue(userid);
41 },
42
43 items: [
44 {
45 xtype: 'displayfield',
46 reference: 'userid',
47 editable: false,
48 fieldLabel: gettext('User'),
49 editConfig: {
50 xtype: 'pmxUserSelector',
51 allowBlank: false,
52 },
53 cbind: {
54 value: () => Proxmox.UserName,
55 },
56 },
57 {
58 xtype: 'proxmoxtextfield',
59 name: 'description',
60 allowBlank: false,
61 fieldLabel: gettext('Description'),
62 },
63 {
64 xtype: 'proxmoxcheckbox',
65 fieldLabel: gettext('Enabled'),
66 name: 'enable',
67 uncheckedValue: 0,
68 defaultValue: 1,
69 checked: true,
70 },
71 {
72 xtype: 'textfield',
73 inputType: 'password',
74 fieldLabel: gettext('Password'),
75 minLength: 5,
76 reference: 'password',
77 name: 'password',
78 allowBlank: false,
79 validateBlank: true,
80 emptyText: gettext('verify current password'),
81 },
82 ],
83
84 getValues: function() {
85 var me = this;
86
87 var values = me.callParent(arguments);
88
89 delete values.userid;
90
91 return values;
92 },
93 });
94
95 Ext.define('Proxmox.tfa.confirmRemove', {
96 extend: 'Proxmox.window.Edit',
97 mixins: ['Proxmox.Mixin.CBind'],
98
99 title: gettext("Confirm TFA Removal"),
100
101 modal: true,
102 resizable: false,
103 width: 600,
104 isCreate: true, // logic
105 isRemove: true,
106
107 url: '/access/tfa',
108
109 initComponent: function() {
110 let me = this;
111
112 if (typeof me.type !== "string") {
113 throw "missing type";
114 }
115
116 if (!me.callback) {
117 throw "missing callback";
118 }
119
120 me.callParent();
121
122 if (Proxmox.UserName === 'root@pam') {
123 me.lookup('password').setVisible(false);
124 me.lookup('password').setDisabled(true);
125 }
126 },
127
128 submit: function() {
129 let me = this;
130 if (Proxmox.UserName === 'root@pam') {
131 me.callback(null);
132 } else {
133 me.callback(me.lookup('password').getValue());
134 }
135 me.close();
136 },
137
138 items: [
139 {
140 xtype: 'box',
141 padding: '0 0 10 0',
142 html: Ext.String.format(
143 gettext('Are you sure you want to remove this {0} entry?'),
144 'TFA',
145 ),
146 },
147 {
148 xtype: 'container',
149 layout: {
150 type: 'hbox',
151 align: 'begin',
152 },
153 defaults: {
154 border: false,
155 layout: 'anchor',
156 flex: 1,
157 padding: 5,
158 },
159 items: [
160 {
161 xtype: 'container',
162 layout: {
163 type: 'vbox',
164 },
165 padding: '0 10 0 0',
166 items: [
167 {
168 xtype: 'displayfield',
169 fieldLabel: gettext('User'),
170 cbind: {
171 value: '{userid}',
172 },
173 },
174 {
175 xtype: 'displayfield',
176 fieldLabel: gettext('Type'),
177 cbind: {
178 value: '{type}',
179 },
180 },
181 ],
182 },
183 {
184 xtype: 'container',
185 layout: {
186 type: 'vbox',
187 },
188 padding: '0 0 0 10',
189 items: [
190 {
191 xtype: 'displayfield',
192 fieldLabel: gettext('Created'),
193 renderer: v => Proxmox.Utils.render_timestamp(v),
194 cbind: {
195 value: '{created}',
196 },
197 },
198 {
199 xtype: 'textfield',
200 fieldLabel: gettext('Description'),
201 cbind: {
202 value: '{description}',
203 },
204 emptyText: Proxmox.Utils.NoneText,
205 submitValue: false,
206 editable: false,
207 },
208 ],
209 },
210 ],
211 },
212 {
213 xtype: 'textfield',
214 inputType: 'password',
215 fieldLabel: gettext('Password'),
216 minLength: 5,
217 reference: 'password',
218 name: 'password',
219 allowBlank: false,
220 validateBlank: true,
221 padding: '10 0 0 0',
222 cbind: {
223 emptyText: () =>
224 Ext.String.format(gettext("Confirm your ({0}) password"), Proxmox.UserName),
225 },
226 },
227 ],
228 });