]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/dc/TokenEdit.js
ui: ldap: add 'Check connection' checkbox as advanced option
[pve-manager.git] / www / manager6 / dc / TokenEdit.js
1 Ext.define('PVE.dc.TokenEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: ['widget.pveDcTokenEdit'],
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 subject: gettext('Token'),
7 onlineHelp: 'pveum_tokens',
8
9 isAdd: true,
10 isCreate: false,
11 fixedUser: false,
12
13 method: 'POST',
14 url: '/api2/extjs/access/users/',
15
16 defaultFocus: 'field[disabled=false][hidden=false][name=tokenid]',
17
18 items: {
19 xtype: 'inputpanel',
20 onGetValues: function(values) {
21 let me = this;
22 let win = me.up('pveDcTokenEdit');
23 win.url = '/api2/extjs/access/users/';
24 let uid = encodeURIComponent(values.userid);
25 let tid = encodeURIComponent(values.tokenid);
26 delete values.userid;
27 delete values.tokenid;
28
29 win.url += `${uid}/token/${tid}`;
30 return values;
31 },
32 column1: [
33 {
34 xtype: 'pmxDisplayEditField',
35 cbind: {
36 editable: (get) => get('isCreate') && !get('fixedUser'),
37 },
38 submitValue: true,
39 editConfig: {
40 xtype: 'pmxUserSelector',
41 allowBlank: false,
42 },
43 name: 'userid',
44 value: Proxmox.UserName,
45 renderer: Ext.String.htmlEncode,
46 fieldLabel: gettext('User'),
47 },
48 {
49 xtype: 'pmxDisplayEditField',
50 cbind: {
51 editable: '{isCreate}',
52 },
53 name: 'tokenid',
54 fieldLabel: gettext('Token ID'),
55 submitValue: true,
56 minLength: 2,
57 allowBlank: false,
58 },
59 ],
60 column2: [
61 {
62 xtype: 'proxmoxcheckbox',
63 name: 'privsep',
64 checked: true,
65 uncheckedValue: 0,
66 fieldLabel: gettext('Privilege Separation'),
67 },
68 {
69 xtype: 'pmxExpireDate',
70 name: 'expire',
71 },
72 ],
73 columnB: [
74 {
75 xtype: 'textfield',
76 name: 'comment',
77 fieldLabel: gettext('Comment'),
78 },
79 ],
80 },
81
82 initComponent: function() {
83 let me = this;
84
85 me.callParent();
86
87 if (!me.isCreate) {
88 me.load({
89 success: function(response, options) {
90 me.setValues(response.result.data);
91 },
92 });
93 }
94 },
95 apiCallDone: function(success, response, options) {
96 let res = response.result.data;
97 if (!success || !res.value) {
98 return;
99 }
100
101 Ext.create('PVE.dc.TokenShow', {
102 autoShow: true,
103 tokenid: res['full-tokenid'],
104 secret: res.value,
105 });
106 },
107 });
108
109 Ext.define('PVE.dc.TokenShow', {
110 extend: 'Ext.window.Window',
111 alias: ['widget.pveTokenShow'],
112 mixins: ['Proxmox.Mixin.CBind'],
113
114 width: 600,
115 modal: true,
116 resizable: false,
117 title: gettext('Token Secret'),
118
119 items: [
120 {
121 xtype: 'container',
122 layout: 'form',
123 bodyPadding: 10,
124 border: false,
125 fieldDefaults: {
126 labelWidth: 100,
127 anchor: '100%',
128 },
129 padding: '0 10 10 10',
130 items: [
131 {
132 xtype: 'textfield',
133 fieldLabel: gettext('Token ID'),
134 cbind: {
135 value: '{tokenid}',
136 },
137 editable: false,
138 },
139 {
140 xtype: 'textfield',
141 fieldLabel: gettext('Secret'),
142 inputId: 'token-secret-value',
143 cbind: {
144 value: '{secret}',
145 },
146 editable: false,
147 },
148 ],
149 },
150 {
151 xtype: 'component',
152 border: false,
153 padding: '10 10 10 10',
154 userCls: 'pmx-hint',
155 html: gettext('Please record the API token secret - it will only be displayed now'),
156 },
157 ],
158 buttons: [
159 {
160 handler: function(b) {
161 document.getElementById('token-secret-value').select();
162 document.execCommand("copy");
163 },
164 text: gettext('Copy Secret Value'),
165 iconCls: 'fa fa-clipboard',
166 },
167 ],
168 });