]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/window/ACMEAccount.js
api-viewer: eslint fixes, code cleanups
[proxmox-widget-toolkit.git] / src / window / ACMEAccount.js
1 Ext.define('Proxmox.window.ACMEAccountCreate', {
2 extend: 'Proxmox.window.Edit',
3 mixins: ['Proxmox.Mixin.CBind'],
4 xtype: 'pmxACMEAccountCreate',
5
6 acmeUrl: undefined,
7
8 width: 450,
9 title: gettext('Register Account'),
10 isCreate: true,
11 method: 'POST',
12 submitText: gettext('Register'),
13 showTaskViewer: true,
14 defaultExists: false,
15
16 items: [
17 {
18 xtype: 'proxmoxtextfield',
19 fieldLabel: gettext('Account Name'),
20 name: 'name',
21 cbind: {
22 emptyText: (get) => get('defaultExists') ? '' : 'default',
23 allowBlank: (get) => !get('defaultExists'),
24 },
25 },
26 {
27 xtype: 'textfield',
28 name: 'contact',
29 vtype: 'email',
30 allowBlank: false,
31 fieldLabel: gettext('E-Mail'),
32 },
33 {
34 xtype: 'proxmoxComboGrid',
35 name: 'directory',
36 reference: 'directory',
37 allowBlank: false,
38 valueField: 'url',
39 displayField: 'name',
40 fieldLabel: gettext('ACME Directory'),
41 store: {
42 autoLoad: true,
43 fields: ['name', 'url'],
44 idProperty: ['name'],
45 proxy: { type: 'proxmox' },
46 sorters: {
47 property: 'name',
48 order: 'ASC',
49 },
50 },
51 listConfig: {
52 columns: [
53 {
54 header: gettext('Name'),
55 dataIndex: 'name',
56 flex: 1,
57 },
58 {
59 header: gettext('URL'),
60 dataIndex: 'url',
61 flex: 1,
62 },
63 ],
64 },
65 listeners: {
66 change: function(combogrid, value) {
67 let me = this;
68
69 if (!value) {
70 return;
71 }
72
73 let acmeUrl = me.up('window').acmeUrl;
74
75 let disp = me.up('window').down('#tos_url_display');
76 let field = me.up('window').down('#tos_url');
77 let checkbox = me.up('window').down('#tos_checkbox');
78
79 disp.setValue(gettext('Loading'));
80 field.setValue(undefined);
81 checkbox.setValue(undefined);
82 checkbox.setHidden(true);
83
84 Proxmox.Utils.API2Request({
85 url: `${acmeUrl}/tos`,
86 method: 'GET',
87 params: {
88 directory: value,
89 },
90 success: function(response, opt) {
91 field.setValue(response.result.data);
92 disp.setValue(response.result.data);
93 checkbox.setHidden(false);
94 },
95 failure: function(response, opt) {
96 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
97 },
98 });
99 },
100 },
101 },
102 {
103 xtype: 'displayfield',
104 itemId: 'tos_url_display',
105 renderer: Proxmox.Utils.render_optional_url,
106 name: 'tos_url_display',
107 },
108 {
109 xtype: 'hidden',
110 itemId: 'tos_url',
111 name: 'tos_url',
112 },
113 {
114 xtype: 'proxmoxcheckbox',
115 itemId: 'tos_checkbox',
116 boxLabel: gettext('Accept TOS'),
117 submitValue: false,
118 validateValue: function(value) {
119 if (value && this.checked) {
120 return true;
121 }
122 return false;
123 },
124 },
125 ],
126
127 initComponent: function() {
128 let me = this;
129
130 if (!me.acmeUrl) {
131 throw "no acmeUrl given";
132 }
133
134 me.url = `${me.acmeUrl}/account`;
135
136 me.callParent();
137
138 me.lookup('directory')
139 .store
140 .proxy
141 .setUrl(`/api2/json/${me.acmeUrl}/directories`);
142 },
143 });
144
145 Ext.define('Proxmox.window.ACMEAccountView', {
146 extend: 'Proxmox.window.Edit',
147 xtype: 'pmxACMEAccountView',
148
149 width: 600,
150 fieldDefaults: {
151 labelWidth: 140,
152 },
153
154 title: gettext('Account'),
155
156 items: [
157 {
158 xtype: 'displayfield',
159 fieldLabel: gettext('E-Mail'),
160 name: 'email',
161 },
162 {
163 xtype: 'displayfield',
164 fieldLabel: gettext('Created'),
165 name: 'createdAt',
166 },
167 {
168 xtype: 'displayfield',
169 fieldLabel: gettext('Status'),
170 name: 'status',
171 },
172 {
173 xtype: 'displayfield',
174 fieldLabel: gettext('Directory'),
175 renderer: Proxmox.Utils.render_optional_url,
176 name: 'directory',
177 },
178 {
179 xtype: 'displayfield',
180 fieldLabel: gettext('Terms of Services'),
181 renderer: Proxmox.Utils.render_optional_url,
182 name: 'tos',
183 },
184 ],
185
186 initComponent: function() {
187 var me = this;
188
189 me.callParent();
190
191 // hide OK/Reset button, because we just want to show data
192 me.down('toolbar[dock=bottom]').setVisible(false);
193
194 me.load({
195 success: function(response) {
196 var data = response.result.data;
197 data.email = data.account.contact[0];
198 data.createdAt = data.account.createdAt;
199 data.status = data.account.status;
200 me.setValues(data);
201 },
202 });
203 },
204 });