]>
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'],
10 url
: '/cluster/acme/plugins/',
12 subject
: gettext('Plugin'),
16 // we dynamically create fields from the given schema
17 // things we have to do here:
18 // * save which fields we created to remove them again
19 // * split the data from the generic 'data' field into the boxes
20 // * on deletion collect those values again
21 // * save the original values of the data field
23 createdInitially
: false,
25 createSchemaFields: function(schema
) {
27 // we know where to add because we define it right below
28 let container
= me
.down('container');
29 let datafield
= me
.down('field[name=data]');
30 if (!me
.createdInitially
) {
31 [me
.originalValues
] = PVE
.Parser
.parseACMEPluginData(datafield
.getValue());
34 // collect values from custom fields and add it to 'data'',
35 // then remove the custom fields
37 for (const [name
, field
] of Object
.entries(me
.createdFields
)) {
38 let value
= field
.getValue();
39 if (value
!== undefined && value
!== null && value
!== '') {
40 data
.push(`${name}=${value}`);
42 container
.remove(field
);
44 let datavalue
= datafield
.getValue();
45 if (datavalue
!== undefined && datavalue
!== null && datavalue
!== '') {
48 datafield
.setValue(data
.join('\n'));
50 me
.createdFields
= {};
52 if (typeof schema
.fields
!== 'object') {
55 // create custom fields according to schema
56 let gotSchemaField
= false;
57 for (const [name
, definition
] of Object
.entries(schema
.fields
).sort((a
, b
) => a
[0].localeCompare(b
[0]))) {
59 switch (definition
.type
) {
61 xtype
= 'proxmoxtextfield';
64 xtype
= 'proxmoxintegerfield';
67 xtype
= 'numberfield';
70 console
.warn(`unknown type '${definition.type}'`);
71 xtype
= 'proxmoxtextfield';
75 let field
= Ext
.create({
77 name
: `custom_${name}`,
81 emptyText
: definition
.default || '',
82 autoEl
: definition
.description
? {
84 'data-qtip': definition
.description
,
88 me
.createdFields
[name
] = field
;
90 gotSchemaField
= true;
92 datafield
.setHidden(gotSchemaField
); // prefer schema-fields
94 // parse data from field and set it to the custom ones
96 [data
, extradata
] = PVE
.Parser
.parseACMEPluginData(datafield
.getValue());
97 for (const [key
, value
] of Object
.entries(data
)) {
98 if (me
.createdFields
[key
]) {
99 me
.createdFields
[key
].setValue(value
);
100 me
.createdFields
[key
].originalValue
= me
.originalValues
[key
];
102 extradata
.push(`${key}=${value}`);
105 datafield
.setValue(extradata
.join('\n'));
106 if (!me
.createdInitially
) {
107 datafield
.resetOriginalValue();
108 me
.createdInitially
= true; // save that we initally set that
111 onGetValues: function(values
) {
113 let win
= me
.up('pveACMEPluginEditor');
115 values
.id
= values
.plugin
;
116 values
.type
= 'dns'; // the only one for now
118 delete values
.plugin
;
120 PVE
.Utils
.delete_if_default(values
, 'validation-delay', '30', win
.isCreate
);
123 for (const [name
, field
] of Object
.entries(me
.createdFields
)) {
124 let value
= field
.getValue();
125 if (value
!== null && value
!== undefined && value
!== '') {
126 data
+= `${name}=${value}\n`;
128 delete values
[`custom_${name}`];
130 values
.data
= Ext
.util
.Base64
.encode(data
+ values
.data
);
135 xtype
: 'pmxDisplayEditField',
137 editable
: (get) => get('isCreate'),
138 submitValue
: (get) => get('isCreate'),
142 xtype
: 'proxmoxtextfield',
147 fieldLabel
: gettext('Plugin'),
150 xtype
: 'proxmoxintegerfield',
151 name
: 'validation-delay',
153 fieldLabel
: gettext('Validation Delay'),
156 deleteEmpty
: '{!isCreate}',
162 xtype
: 'pveACMEApiSelector',
166 change: function(selector
) {
167 let schema
= selector
.getSchema();
168 selector
.up('inputpanel').createSchemaFields(schema
);
173 fieldLabel
: gettext('API Data'),
182 initComponent: function() {
189 success: function(response
, opts
) {
190 me
.setValues(response
.result
.data
);