]>
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 for (const [name
, definition
] of Object
.entries(schema
.fields
).sort((a
, b
) => a
[0].localeCompare(b
[0]))) {
58 switch (definition
.type
) {
60 xtype
= 'proxmoxtextfield';
63 xtype
= 'proxmoxintegerfield';
66 xtype
= 'numberfield';
69 console
.warn(`unknown type '${definition.type}'`);
70 xtype
= 'proxmoxtextfield';
74 let field
= Ext
.create({
76 name
: `custom_${name}`,
80 emptyText
: definition
.default || '',
81 autoEl
: definition
.description
? {
83 'data-qtip': definition
.description
,
87 me
.createdFields
[name
] = field
;
91 // parse data from field and set it to the custom ones
93 [data
, extradata
] = PVE
.Parser
.parseACMEPluginData(datafield
.getValue());
94 for (const [key
, value
] of Object
.entries(data
)) {
95 if (me
.createdFields
[key
]) {
96 me
.createdFields
[key
].setValue(value
);
97 me
.createdFields
[key
].originalValue
= me
.originalValues
[key
];
99 extradata
.push(`${key}=${value}`);
102 datafield
.setValue(extradata
.join('\n'));
103 if (!me
.createdInitially
) {
104 datafield
.resetOriginalValue();
105 me
.createdInitially
= true; // save that we initally set that
108 onGetValues: function(values
) {
110 let win
= me
.up('pveACMEPluginEditor');
112 values
.id
= values
.plugin
;
113 values
.type
= 'dns'; // the only one for now
115 delete values
.plugin
;
117 PVE
.Utils
.delete_if_default(values
, 'validation-delay', '30', win
.isCreate
);
120 for (const [name
, field
] of Object
.entries(me
.createdFields
)) {
121 let value
= field
.getValue();
122 if (value
!== null && value
!== undefined && value
!== '') {
123 data
+= `${name}=${value}\n`;
125 delete values
[`custom_${name}`];
127 values
.data
= Ext
.util
.Base64
.encode(data
+ values
.data
);
132 xtype
: 'pmxDisplayEditField',
134 editable
: (get) => get('isCreate'),
135 submitValue
: (get) => get('isCreate'),
139 xtype
: 'proxmoxtextfield',
144 fieldLabel
: gettext('Plugin'),
147 xtype
: 'proxmoxintegerfield',
148 name
: 'validation-delay',
150 fieldLabel
: gettext('Validation Delay'),
153 deleteEmpty
: '{!isCreate}',
159 xtype
: 'pveACMEApiSelector',
163 change: function(selector
) {
164 let schema
= selector
.getSchema();
165 selector
.up('inputpanel').createSchemaFields(schema
);
170 fieldLabel
: gettext('API Data'),
179 initComponent: function() {
186 success: function(response
, opts
) {
187 me
.setValues(response
.result
.data
);