]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/dc/ACMEPluginEdit.js
1 Ext
.define('PVE.dc.ACMEPluginEditor', {
2 extend
: 'Proxmox.window.Edit',
3 xtype
: 'pveACMEPluginEditor',
4 mixins
: ['Proxmox.Mixin.CBind'],
6 onlineHelp
: 'sysadmin_certs_acme_plugins',
12 url
: '/cluster/acme/plugins/',
14 subject
: 'ACME DNS Plugin',
19 // we dynamically create fields from the given schema
20 // things we have to do here:
21 // * save which fields we created to remove them again
22 // * split the data from the generic 'data' field into the boxes
23 // * on deletion collect those values again
24 // * save the original values of the data field
26 createdInitially
: false,
28 createSchemaFields: function(schema
) {
30 // we know where to add because we define it right below
31 let container
= me
.down('container');
32 let datafield
= me
.down('field[name=data]');
33 let hintfield
= me
.down('field[name=hint]');
34 if (!me
.createdInitially
) {
35 [me
.originalValues
] = PVE
.Parser
.parseACMEPluginData(datafield
.getValue());
38 // collect values from custom fields and add it to 'data'',
39 // then remove the custom fields
41 for (const [name
, field
] of Object
.entries(me
.createdFields
)) {
42 let value
= field
.getValue();
43 if (value
!== undefined && value
!== null && value
!== '') {
44 data
.push(`${name}=${value}`);
46 container
.remove(field
);
48 let datavalue
= datafield
.getValue();
49 if (datavalue
!== undefined && datavalue
!== null && datavalue
!== '') {
52 datafield
.setValue(data
.join('\n'));
54 me
.createdFields
= {};
56 if (typeof schema
.fields
!== 'object') {
59 // create custom fields according to schema
60 let gotSchemaField
= false;
61 let cmp
= (a
, b
) => a
[0].localeCompare(b
[0]);
62 for (const [name
, definition
] of Object
.entries(schema
.fields
).sort(cmp
)) {
64 switch (definition
.type
) {
66 xtype
= 'proxmoxtextfield';
69 xtype
= 'proxmoxintegerfield';
72 xtype
= 'numberfield';
75 console
.warn(`unknown type '${definition.type}'`);
76 xtype
= 'proxmoxtextfield';
81 if (typeof definition
.name
=== "string") {
82 label
= definition
.name
;
85 let field
= Ext
.create({
87 name
: `custom_${name}`,
92 emptyText
: definition
.default || '',
93 autoEl
: definition
.description
? {
95 'data-qtip': definition
.description
,
99 me
.createdFields
[name
] = field
;
100 container
.add(field
);
101 gotSchemaField
= true;
103 datafield
.setHidden(gotSchemaField
); // prefer schema-fields
105 if (schema
.description
) {
106 hintfield
.setValue(schema
.description
);
107 hintfield
.setHidden(false);
109 hintfield
.setValue('');
110 hintfield
.setHidden(true);
113 // parse data from field and set it to the custom ones
115 [data
, extradata
] = PVE
.Parser
.parseACMEPluginData(datafield
.getValue());
116 for (const [key
, value
] of Object
.entries(data
)) {
117 if (me
.createdFields
[key
]) {
118 me
.createdFields
[key
].setValue(value
);
119 me
.createdFields
[key
].originalValue
= me
.originalValues
[key
];
121 extradata
.push(`${key}=${value}`);
124 datafield
.setValue(extradata
.join('\n'));
125 if (!me
.createdInitially
) {
126 datafield
.resetOriginalValue();
127 me
.createdInitially
= true; // save that we initally set that
130 onGetValues: function(values
) {
132 let win
= me
.up('pveACMEPluginEditor');
134 values
.id
= values
.plugin
;
135 values
.type
= 'dns'; // the only one for now
137 delete values
.plugin
;
139 PVE
.Utils
.delete_if_default(values
, 'validation-delay', '30', win
.isCreate
);
142 for (const [name
, field
] of Object
.entries(me
.createdFields
)) {
143 let value
= field
.getValue();
144 if (value
!== null && value
!== undefined && value
!== '') {
145 data
+= `${name}=${value}\n`;
147 delete values
[`custom_${name}`];
149 values
.data
= Ext
.util
.Base64
.encode(data
+ values
.data
);
154 xtype
: 'pmxDisplayEditField',
156 editable
: (get) => get('isCreate'),
157 submitValue
: (get) => get('isCreate'),
161 xtype
: 'proxmoxtextfield',
166 fieldLabel
: gettext('Plugin ID'),
169 xtype
: 'proxmoxintegerfield',
170 name
: 'validation-delay',
172 fieldLabel
: gettext('Validation Delay'),
175 deleteEmpty
: '{!isCreate}',
181 xtype
: 'pveACMEApiSelector',
185 change: function(selector
) {
186 let schema
= selector
.getSchema();
187 selector
.up('inputpanel').createSchemaFields(schema
);
193 fieldLabel
: gettext('API Data'),
198 xtype
: 'displayfield',
199 fieldLabel
: gettext('Hint'),
208 initComponent: function() {
215 success: function(response
, opts
) {
216 me
.setValues(response
.result
.data
);