]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/window/ACMEPluginEdit.js
1 Ext
.define('Proxmox.window.ACMEPluginEdit', {
2 extend
: 'Proxmox.window.Edit',
3 xtype
: 'pmxACMEPluginEdit',
4 mixins
: ['Proxmox.Mixin.CBind'],
6 //onlineHelp: 'sysadmin_certs_acme_plugins',
15 subject
: 'ACME DNS Plugin',
17 cbindData: function(config
) {
20 challengeSchemaUrl
: `/api2/json/${me.acmeUrl}/challenge-schema`,
27 // we dynamically create fields from the given schema
28 // things we have to do here:
29 // * save which fields we created to remove them again
30 // * split the data from the generic 'data' field into the boxes
31 // * on deletion collect those values again
32 // * save the original values of the data field
34 createdInitially
: false,
36 createSchemaFields: function(schema
) {
38 // we know where to add because we define it right below
39 let container
= me
.down('container');
40 let datafield
= me
.down('field[name=data]');
41 let hintfield
= me
.down('field[name=hint]');
42 if (!me
.createdInitially
) {
43 [me
.originalValues
] = Proxmox
.Utils
.parseACMEPluginData(datafield
.getValue());
46 // collect values from custom fields and add it to 'data'',
47 // then remove the custom fields
49 for (const [name
, field
] of Object
.entries(me
.createdFields
)) {
50 let value
= field
.getValue();
51 if (value
!== undefined && value
!== null && value
!== '') {
52 data
.push(`${name}=${value}`);
54 container
.remove(field
);
56 let datavalue
= datafield
.getValue();
57 if (datavalue
!== undefined && datavalue
!== null && datavalue
!== '') {
60 datafield
.setValue(data
.join('\n'));
62 me
.createdFields
= {};
64 if (typeof schema
.fields
!== 'object') {
67 // create custom fields according to schema
68 let gotSchemaField
= false;
69 for (const [name
, definition
] of Object
70 .entries(schema
.fields
)
71 .sort((a
, b
) => a
[0].localeCompare(b
[0]))
74 switch (definition
.type
) {
76 xtype
= 'proxmoxtextfield';
79 xtype
= 'proxmoxintegerfield';
82 xtype
= 'numberfield';
85 console
.warn(`unknown type '${definition.type}'`);
86 xtype
= 'proxmoxtextfield';
91 if (typeof definition
.name
=== "string") {
92 label
= definition
.name
;
95 let field
= Ext
.create({
97 name
: `custom_${name}`,
102 emptyText
: definition
.default || '',
103 autoEl
: definition
.description
? {
105 'data-qtip': definition
.description
,
109 me
.createdFields
[name
] = field
;
110 container
.add(field
);
111 gotSchemaField
= true;
113 datafield
.setHidden(gotSchemaField
); // prefer schema-fields
115 if (schema
.description
) {
116 hintfield
.setValue(schema
.description
);
117 hintfield
.setHidden(false);
119 hintfield
.setValue('');
120 hintfield
.setHidden(true);
123 // parse data from field and set it to the custom ones
125 [data
, extradata
] = Proxmox
.Utils
.parseACMEPluginData(datafield
.getValue());
126 for (const [key
, value
] of Object
.entries(data
)) {
127 if (me
.createdFields
[key
]) {
128 me
.createdFields
[key
].setValue(value
);
129 me
.createdFields
[key
].originalValue
= me
.originalValues
[key
];
130 me
.createdFields
[key
].checkDirty();
132 extradata
.push(`${key}=${value}`);
135 datafield
.setValue(extradata
.join('\n'));
136 if (!me
.createdInitially
) {
137 datafield
.resetOriginalValue();
138 me
.createdInitially
= true; // save that we initially set that
142 onGetValues: function(values
) {
144 let win
= me
.up('pmxACMEPluginEdit');
146 values
.id
= values
.plugin
;
147 values
.type
= 'dns'; // the only one for now
149 delete values
.plugin
;
151 Proxmox
.Utils
.delete_if_default(values
, 'validation-delay', '30', win
.isCreate
);
154 for (const [name
, field
] of Object
.entries(me
.createdFields
)) {
155 let value
= field
.getValue();
156 if (value
!== null && value
!== undefined && value
!== '') {
157 data
+= `${name}=${value}\n`;
159 delete values
[`custom_${name}`];
161 values
.data
= Ext
.util
.Base64
.encode(data
+ values
.data
);
167 xtype
: 'pmxDisplayEditField',
169 editable
: (get) => get('isCreate'),
170 submitValue
: (get) => get('isCreate'),
174 xtype
: 'proxmoxtextfield',
179 fieldLabel
: gettext('Plugin ID'),
182 xtype
: 'proxmoxintegerfield',
183 name
: 'validation-delay',
185 fieldLabel
: gettext('Validation Delay'),
188 deleteEmpty
: '{!isCreate}',
194 xtype
: 'pmxACMEApiSelector',
198 url
: '{challengeSchemaUrl}',
201 change: function(selector
) {
202 let schema
= selector
.getSchema();
203 selector
.up('inputpanel').createSchemaFields(schema
);
209 fieldLabel
: gettext('API Data'),
214 xtype
: 'displayfield',
215 fieldLabel
: gettext('Hint'),
224 initComponent: function() {
228 throw "no acmeUrl given";
235 success: function(response
, opts
) {
236 me
.setValues(response
.result
.data
);