Use the new `getFieldDefFromPropertySchema()` helper function to
simplify some of the logic in `ACMEPluginEdit.js`.

This results in no noticeable difference when setting up ACME challenge
plugins, except for the fact that fields not marked as optional are
now in fact not optional in the UI.

Signed-off-by: Max R. Carrara <[email protected]>
---
 src/window/ACMEPluginEdit.js | 42 +++++++++++-------------------------
 1 file changed, 13 insertions(+), 29 deletions(-)

diff --git a/src/window/ACMEPluginEdit.js b/src/window/ACMEPluginEdit.js
index 900923b..d8591ae 100644
--- a/src/window/ACMEPluginEdit.js
+++ b/src/window/ACMEPluginEdit.js
@@ -69,45 +69,29 @@ Ext.define('Proxmox.window.ACMEPluginEdit', {
                 for (const [name, definition] of 
Object.entries(schema.fields).sort((a, b) =>
                     a[0].localeCompare(b[0]),
                 )) {
-                    let xtype;
-                    switch (definition.type) {
-                        case 'string':
-                            xtype = 'proxmoxtextfield';
-                            break;
-                        case 'integer':
-                            xtype = 'proxmoxintegerfield';
-                            break;
-                        case 'number':
-                            xtype = 'numberfield';
-                            break;
-                        default:
-                            console.warn(`unknown type '${definition.type}'`);
-                            xtype = 'proxmoxtextfield';
-                            break;
-                    }
+                    let fieldName = `custom_${name}`;
+                    let context = { isCreate: me.isCreate };
+
+                    let fieldDef = Proxmox.Utils.getFieldDefFromPropertySchema(
+                        fieldName,
+                        definition,
+                        {},
+                        context,
+                    );
 
                     let label = name;
                     if (typeof definition.name === 'string') {
                         label = definition.name;
                     }
 
-                    let field = Ext.create({
-                        xtype,
-                        name: `custom_${name}`,
+                    let extraProps = {
                         fieldLabel: Ext.htmlEncode(label),
                         width: '100%',
                         labelWidth: 150,
                         labelSeparator: '=',
-                        emptyText: definition.default || '',
-                        autoEl: definition.description
-                            ? {
-                                  tag: 'div',
-                                  'data-qtip': Ext.htmlEncode(
-                                      Ext.htmlEncode(definition.description),
-                                  ),
-                              }
-                            : undefined,
-                    });
+                    };
+
+                    let field = Ext.create({ ...fieldDef, ...extraProps });
 
                     me.createdFields[name] = field;
                     container.add(field);
-- 
2.47.3



_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to